Ejemplo n.º 1
0
 def setUp(self):
     f = T.Variable(sum, 'sum')
     self.c1 = T.Call(f, ([1, 2, 3], ))
     self.c2 = f([1, 2, 3])
     self.c3 = T.Call(f, (['', 1], ))
Ejemplo n.º 2
0
 def setUp(self):
     x = T.Variable(1, 'x')
     f = lambda x: (x, )
     self.op1 = T.UnaryOperator(8, x, '-', f)
     self.op2 = T.UnaryOperator(9, x, '-', f)
Ejemplo n.º 3
0
 def setUp(self):
     x = Object()
     self.value = T.GetAttr(T.Variable(x, 'x'), 'value')
     self.value2 = T.GetAttr(T.Variable(x, 'x'), T.Constant('value'))
     self.value3 = T.GetAttr(T.Variable(x, 'x'), 3)
Ejemplo n.º 4
0
 def setUp(self):
     x = T.Variable([1, 2, 3], 'x')
     y = T.Variable({'a': 1, 'b': 2}, 'y')
     self.x = x
     self.v1 = T.GetItem(x, 1)
     self.v2 = T.GetItem(y, 'a')
Ejemplo n.º 5
0
 def setUp(self):
     self.x = T.Variable(1, 'x')
     self.y = T.Variable(2, 'y')
Ejemplo n.º 6
0
 def setUp(self):
     self.x = T.Variable(10, 'x')
Ejemplo n.º 7
0
def make_multiple_tc_variable(ty_args, names):
    assert len(ty_args) == len(names)
    return [type_check.Variable(t, n) for t, n in zip(ty_args, names)]
Ejemplo n.º 8
0
def apply_subst_shapeElem(subst, e):
    if e.value in subst.keys():
        return ShapeElem(subst[e.value],
                         expr=type_check.Variable(None, e.value))
    return e
Ejemplo n.º 9
0
import numpy

from chainer import function
from chainer.utils import type_check

_type_check_prod = type_check.Variable(numpy.prod, 'prod')


class Reshape(function.Function):
    """Reshapes an input array without copy."""
    def __init__(self, shape):
        self.shape = shape

    def check_type_forward(self, in_types):
        type_check.expect(
            in_types.size() == 1,
            _type_check_prod(in_types[0].shape) == _type_check_prod(
                self.shape))

    def forward(self, x):
        return x[0].reshape(self.shape),

    def backward(self, x, gy):
        return gy[0].reshape(x[0].shape),


def reshape(x, shape):
    """Reshapes an input variable without copy.

    Args:
        x (~chainer.Variable): Input variable.