# Path: deeppy/expr/base.py
# class Unary(Op):
#     x = None
# 
#     def __call__(self, x):
#         x = _require_op(x)
#         self.x = x
#         if isinstance(x, Constant):
#             # Propagate constant.
#             self.setup()
#             self.fprop()
#             return Constant(self.array)
#         self.bpropable = x.bpropable
#         self.inputs = [x]
#         return self
# 
# Path: deeppy/base.py
# class ParamMixin(object):
# class PhaseMixin(object):
# class CollectionMixin(ParamMixin, PhaseMixin):
# class Model(ParamMixin):
# class PickleMixin(object):
#     def params(self):
#     def params(self, params):
#     def phase(self):
#     def phase(self, phase):
#     def params(self):
#     def params(self, params):
#     def phase(self):
#     def phase(self, phase):
#     def setup(self, *array_shapes):
#     def update(self, *arrays):
#     def _pickle_discard(self, attr_name):
#     def __getstate__(self):


import cudarray as ca
from ..base import Unary
from ...base import int_


class OneHot(Unary):
    def __init__(self, n_classes):
        self.n_classes = n_classes

    def setup(self):
        self.shape = self.x.shape + (self.n_classes,)
        self.array = ca.zeros(self.shape)

    def fprop(self):
        ca.nnet.one_hot_encode(self.x.array, self.n_classes, self.array)



# Path: deeppy/expr/base.py
# class Unary(Op):
#     x = None
# 
#     def __call__(self, x):
#         x = _require_op(x)
#         self.x = x
#         if isinstance(x, Constant):
#             # Propagate constant.
#             self.setup()
#             self.fprop()
#             return Constant(self.array)
#         self.bpropable = x.bpropable
#         self.inputs = [x]
#         return self
# 
# Path: deeppy/base.py
# class ParamMixin(object):
# class PhaseMixin(object):
# class CollectionMixin(ParamMixin, PhaseMixin):
# class Model(ParamMixin):
# class PickleMixin(object):
#     def params(self):
#     def params(self, params):
#     def phase(self):
#     def phase(self, phase):
#     def params(self):
#     def params(self, params):
#     def phase(self):
#     def phase(self, phase):
#     def setup(self, *array_shapes):
#     def update(self, *arrays):
#     def _pickle_discard(self, attr_name):
#     def __getstate__(self):


# Path: deeppy/expr/nnet/one_hot.py
import cudarray as ca
from ..base import Unary
from ...base import int_



class OneHot(Unary):
    def __init__(self, n_classes):
        self.n_classes = n_classes

    def setup(self):
        self.shape = self.x.shape + (self.n_classes,)
        self.array = ca.zeros(self.shape)

    def fprop(self):
        ca.nnet.one_hot_encode(self.x.array, self.n_classes, self.array)



class OneHotDecode(Unary):