# Path: deeppy/base.py
# class PhaseMixin(object):
#     _phase = None
# 
#     @property
#     def phase(self):
#         return self._phase
# 
#     @phase.setter
#     def phase(self, phase):
#         self._phase = phase
# 
# Path: deeppy/expr/base.py
# class UnaryElementWise(Unary):
#     def setup(self):
#         self.shape = self.x.shape
#         self.array = ca.zeros(self.shape)
#         self.grad_array = ca.zeros(self.shape)


import cudarray as ca
from ...base import PhaseMixin
from ..base import UnaryElementWise


class Dropout(UnaryElementWise, PhaseMixin):
    def __init__(self, dropout=0.5):
        self.dropout = dropout
        self._tmp_mask = None
        self.phase = 'train'

    def __call__(self, x):
        if self.dropout == 0.0:
            return x
        return super(Dropout, self).__call__(x)

    def setup(self):
        super(Dropout, self).setup()
        self.mask_shape = self.shape

# Path: deeppy/base.py
# class PhaseMixin(object):
#     _phase = None
# 
#     @property
#     def phase(self):
#         return self._phase
# 
#     @phase.setter
#     def phase(self, phase):
#         self._phase = phase
# 
# Path: deeppy/expr/base.py
# class UnaryElementWise(Unary):
#     def setup(self):
#         self.shape = self.x.shape
#         self.array = ca.zeros(self.shape)
#         self.grad_array = ca.zeros(self.shape)


# Path: deeppy/expr/nnet/dropout.py
import cudarray as ca
from ...base import PhaseMixin
from ..base import UnaryElementWise



class Dropout(UnaryElementWise, PhaseMixin):
    def __init__(self, dropout=0.5):
        self.dropout = dropout
        self._tmp_mask = None
        self.phase = 'train'

    def __call__(self, x):
        if self.dropout == 0.0:
            return x
        return super(Dropout, self).__call__(x)

    def setup(self):
        super(Dropout, self).setup()
        self.mask_shape = self.shape

        self._tmp_mask = ca.zeros(self.mask_shape, dtype=ca.int_)