Ejemplo n.º 1
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 4)
        c1_type, c2_type, x1_type, x2_type = in_types

        type_check.expect(
            c1_type.dtype.kind == 'f',
            c2_type.dtype == c1_type.dtype,
            x1_type.dtype == c1_type.dtype,
            x2_type.dtype == c1_type.dtype,

            c1_type.ndim >= 2,
            c2_type.ndim >= 2,
            x1_type.ndim >= 2,
            x2_type.ndim >= 2,
            c1_type.ndim == x1_type.ndim,
            c1_type.ndim == c2_type.ndim,
            c1_type.ndim == x2_type.ndim,

            c1_type.shape[0] == x1_type.shape[0],
            c1_type.shape[0] == c2_type.shape[0],
            c1_type.shape[0] == x2_type.shape[0],
            x1_type.shape[1] == 4 * c1_type.shape[1],
            x2_type.shape[1] == 4 * c2_type.shape[1],
        )
        for i in range(2, c1_type.ndim.eval()):
            type_check.expect(x1_type.shape[i] == c1_type.shape[i])
            type_check.expect(x2_type.shape[i] == c2_type.shape[i])
            type_check.expect(x1_type.shape[i] == x2_type.shape[i])
Ejemplo n.º 2
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 2)
        a_type, b_type = in_types

        type_check.expect(
            a_type.dtype.kind == 'f',
            b_type.dtype.kind == 'f',
            a_type.ndim >= 1,
            b_type.ndim >= 1,
        )

        a_ndim = type_check.eval(a_type.ndim)
        b_ndim = type_check.eval(b_type.ndim)
        if b_ndim == 1:
            a_idx = -2 if self.transa and a_ndim > 1 else -1
            type_check.expect(a_type.shape[a_idx] == b_type.shape[0])
        elif a_ndim == 1:
            b_idx = -1 if self.transb and b_ndim > 1 else -2
            type_check.expect(a_type.shape[0] == b_type.shape[b_idx])
        else:
            a_idx = _get_check_index(self.transa, False,
                                     row_idx=-2, col_idx=-1)
            b_idx = _get_check_index(self.transb, True,
                                     row_idx=-2, col_idx=-1)
            type_check.expect(a_type.shape[a_idx] == b_type.shape[b_idx])
            type_check.expect_broadcast_shapes(
                a_type.shape[:-2], b_type.shape[:-2])
Ejemplo n.º 3
0
 def check_type_backward(self, in_types, out_types):
     type_check.expect(
         out_types.size() == 1,
         in_types[0].dtype == out_types[0].dtype,
         in_types[0].ndim == out_types[0].ndim,
         in_types[0].shape == out_types[0].shape
     )
Ejemplo n.º 4
0
    def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(2 <= n_in, n_in <= 3)
        x_type, w_type = in_types[:2]

        type_check.expect(
            x_type.dtype.kind == 'f',
            w_type.dtype.kind == 'f',
            x_type.ndim == 4,
            w_type.ndim == 4,
            x_type.shape[1] == w_type.shape[0]
        )

        if self.outh is not None:
            type_check.expect(
                x_type.shape[2] ==
                conv.get_conv_outsize(self.outh, w_type.shape[2],
                                      self.sy, self.ph),
            )
        if self.outw is not None:
            type_check.expect(
                x_type.shape[3] ==
                conv.get_conv_outsize(self.outw, w_type.shape[3],
                                      self.sx, self.pw),
            )

        if type_check.eval(n_in) == 3:
            b_type = in_types[2]
            type_check.expect(
                b_type.dtype == x_type.dtype,
                b_type.ndim == 1,
                b_type.shape[0] == w_type.shape[1]
            )
Ejemplo n.º 5
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1)
        x_type, = in_types

        type_check.expect(
            x_type.dtype == numpy.float32,
        )
Ejemplo n.º 6
0
 def check_type_forward(self, in_types):
     type_check.expect(
         in_types.size() == 2,
         in_types[0].dtype.kind == 'f',
         in_types[0].dtype == in_types[1].dtype,
         in_types[0].shape == in_types[1].shape
     )
Ejemplo n.º 7
0
    def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(2 <= n_in, n_in <= 3)
        x_type, w_type = in_types[:2]
        type_check._argname((x_type, w_type), ('x', 'W'))

        type_check.expect(
            x_type.dtype.kind == 'f',
            w_type.dtype.kind == 'f',
            x_type.ndim >= 2,
            w_type.ndim == 2,
            type_check.prod(x_type.shape[1:]) == w_type.shape[1],
        )
        if type_check.eval(n_in) == 3:
            b_type = in_types[2]
            type_check._argname((b_type,), ('b',))
            type_check.expect(
                b_type.dtype == x_type.dtype,
                b_type.ndim == 1,
                b_type.shape[0] == w_type.shape[0],
            )

        if self.mask is not None:
            if self.use_batchwise_mask:
                type_check.expect(
                    self.mask.shape[0] == x_type.shape[0],
                    self.mask.shape[1:] == w_type.shape,
                )
            else:
                type_check.expect(self.mask.shape == w_type.shape)
Ejemplo n.º 8
0
 def check_type_backward(self, in_types, out_types):
     type_check.expect(
         in_types.size() == 2,
         out_types.size() == 1,
     )
     y_type, = out_types
     type_check.expect(y_type.ndim == 0)  # means scalar
Ejemplo n.º 9
0
 def check_type_forward(self, in_types):
     # Depending on the arguments, pad_width and keywords, the input value
     # may be inappropriate. In that case, numpy.pad or cupy.pad will raise
     # errors, so that only check the size and the dtype in this function.
     type_check.expect(in_types.size() == 1)
     x_type = in_types[0]
     type_check.expect(x_type.dtype.kind == 'f')
Ejemplo n.º 10
0
    def check_type_forward(self, in_types):
        type_check._argname(in_types, ('gy',))

        type_check.expect(
            in_types[0].dtype.kind == 'f',
            in_types[0].dtype == self.x.dtype
        )
Ejemplo n.º 11
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x', 'divisor'))
     type_check.expect(
         in_types[0].dtype == in_types[1].dtype,
         in_types[0].dtype.kind == 'f',
         in_types[1].dtype.kind == 'f',
     )
Ejemplo n.º 12
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     type_check.expect(
         in_types[0].dtype == in_types[1].dtype,
     )
     type_check.expect_broadcast_shapes(
         in_types[0].shape, in_types[1].shape)
Ejemplo n.º 13
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1)
        x_type = in_types[0]

        type_check.expect(
            x_type.dtype.kind == 'f',
            x_type.ndim >= 2)
Ejemplo n.º 14
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x0', 'x1'))
     type_check.expect(
         in_types[0].dtype.kind == 'f',
         in_types[0].dtype == in_types[1].dtype,
         in_types[0].shape == in_types[1].shape
     )
Ejemplo n.º 15
0
    def check_type_forward(self, in_types):
        type_check._argname(in_types, ('x',))
        type_check.expect(
            in_types[0].dtype.kind == 'f',
        )

        if self.source is not None:
            for axis in self.source:
                if axis >= 0:
                    type_check.expect(
                        axis < in_types[0].ndim,
                    )
                else:
                    type_check.expect(
                        -axis - 1 < in_types[0].ndim,
                    )
        if self.destination is not None:
            for axis in self.destination:
                if axis >= 0:
                    type_check.expect(
                        axis < in_types[0].ndim,
                    )
                else:
                    type_check.expect(
                        -axis - 1 < in_types[0].ndim,
                    )
Ejemplo n.º 16
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('sp', 'dn'))
     sp_type, dn_type = in_types
     # sp_type.shape: ((nb,) ldnz)
     # dn_type.shape: ((nb,) _k, _n) when transb is False
     sp_k_axis = -1
     if self.transa:
         sp_k_axis = -2
     dn_k_axis = -2
     if self.transb:
         dn_k_axis = -1
     type_check.expect(
         sp_type.dtype.kind == 'f',
         dn_type.dtype.kind == 'f',
         dn_type.ndim >= 2,
         dn_type.ndim <= 3,
         sp_type.ndim == dn_type.ndim - 1,
         sp_type.shape[-1] == self.sp_row.shape[-1],
         self.sp_shape[sp_k_axis] == dn_type.shape[dn_k_axis],
     )
     dn_ndim = type_check.eval(dn_type.ndim)
     if dn_ndim == 3:
         type_check.expect(
             sp_type.shape[0] == self.sp_row.shape[0],
             dn_type.shape[0] == self.sp_row.shape[0],
         )
Ejemplo n.º 17
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('lhs', 'rhs', 'gy'))
     type_check.expect(
         in_types[0].dtype.kind == 'f',
         in_types[0].dtype == in_types[1].dtype,
         in_types[0].dtype == in_types[2].dtype,
     )
Ejemplo n.º 18
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('lhs', 'rhs'))
     type_check.expect(
         in_types[0].dtype == in_types[1].dtype,
     )
     type_check.expect_broadcast_shapes(
         in_types[0].shape, in_types[1].shape)
Ejemplo n.º 19
0
    def check_type_forward(self, in_types):
        n_in = in_types.size().eval()
        if n_in != 3 and n_in != 5:
            raise type_check.InvalidType(
                '%s or %s' % (in_types.size() == 3, in_types.size() == 5),
                '%s == %s' % (in_types.size(), n_in))

        x_type, gamma_type, beta_type = in_types[:3]
        type_check.expect(
            x_type.dtype.kind == 'f',
            x_type.ndim >= gamma_type.ndim + 1,
            # TODO(beam2d): Check shape
            gamma_type.dtype == x_type.dtype,
            beta_type.dtype == x_type.dtype,
            gamma_type.shape == beta_type.shape,
        )

        if len(in_types) == 5:
            mean_type, var_type = in_types[3:]
            type_check.expect(
                mean_type.dtype == x_type.dtype,
                mean_type.shape == gamma_type.shape,
                var_type.dtype == x_type.dtype,
                var_type.shape == gamma_type.shape,
            )
Ejemplo n.º 20
0
 def check_type_forward(self, in_types):
     type_check.expect(
         in_types.size() == 1,
         in_types[0].dtype.kind == 'f',
         in_types[0].ndim == 2 + self.ndim,
         in_types[0].size > 0,
     )
Ejemplo n.º 21
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     type_check.expect(
         in_types[0].dtype == numpy.float32,
         in_types[1].dtype == numpy.float32,
         in_types[0].shape == in_types[1].shape
     )
Ejemplo n.º 22
0
 def check_type_forward(self, in_types):
     type_check.expect(
         in_types.size() == 1,
         in_types[0].dtype.kind == 'f',
         in_types[0].ndim > self.axis,
         in_types[0].ndim >= -self.axis
     )
	def check_type_forward(self, in_types):
		n_in = in_types.size()
		type_check.expect(3 <= n_in, n_in <= 4)
		x_type = in_types[0]
		v_type = in_types[1]
		g_type = in_types[2]

		type_check.expect(
			x_type.dtype.kind == "f",
			v_type.dtype.kind == "f",
			g_type.dtype.kind == "f",
			x_type.ndim == 4,
			v_type.ndim == 4,
			g_type.ndim == 4,
			x_type.shape[1] == v_type.shape[0]
		)

		if self.outh is not None:
			type_check.expect(
				x_type.shape[2] ==
				conv.get_conv_outsize(self.outh, v_type.shape[2],self.sy, self.ph),
			)
		if self.outw is not None:
			type_check.expect(
				x_type.shape[3] ==
				conv.get_conv_outsize(self.outw, v_type.shape[3], self.sx, self.pw),
			)

		if type_check.eval(n_in) == 4:
			b_type = in_types[3]
			type_check.expect(
				b_type.dtype == x_type.dtype,
				b_type.ndim == 1,
				b_type.shape[0] == v_type.shape[1]
			)
Ejemplo n.º 24
0
 def check_type_forward(self, in_types):
     type_check.expect(
         in_types.size() == 1,
         in_types[0].dtype == numpy.float32,
         in_types[0].ndim > self.axis,
         in_types[0].ndim >= -self.axis
     )
Ejemplo n.º 25
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x',))
     x_type, = in_types
     if self.axis >= 0:
         type_check.expect(x_type.ndim >= self.axis)
     else:
         type_check.expect(x_type.ndim >= -self.axis - 1)
Ejemplo n.º 26
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x',))
     x_type = in_types[0]
     if self.axis >= 0:
         type_check.expect(self.axis < x_type.ndim)
     else:
         type_check.expect(-self.axis <= x_type.ndim)
Ejemplo n.º 27
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x',))
     type_check.expect(
         in_types[0].dtype.kind == 'f',
         in_types[0].ndim > self.axis,
         in_types[0].ndim >= -self.axis
     )
Ejemplo n.º 28
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     type_check.expect(
         in_types[0].dtype == in_types[1].dtype,
         # check if the mini_batch sizes are same
         in_types[0].shape[0] == in_types[1].shape[0]
     )
Ejemplo n.º 29
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 5)
     x_type, gamma_type, beta_type, mean_type, var_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f',
         # TODO(beam2d): Check shape
         gamma_type.dtype == x_type.dtype,
         beta_type.dtype == x_type.dtype,
         gamma_type.shape == beta_type.shape,
         mean_type.dtype == x_type.dtype,
         mean_type.shape == gamma_type.shape,
         var_type.dtype == x_type.dtype,
         var_type.shape == gamma_type.shape,
     )
     _x_ndim = type_check.eval(x_type.ndim)
     _gamma_ndim = type_check.eval(gamma_type.ndim)
     _axis = _compute_axis(_x_ndim, _gamma_ndim, self.axis)
     type_check.expect(
         x_type.ndim >= len(_axis),
     )
     _key_axis = _compute_key_axis(_x_ndim, _gamma_ndim, _axis)
     type_check.expect(
         gamma_type.ndim == len(_key_axis),
     )
     for i in range(len(_key_axis)):
         type_check.expect(
             x_type.shape[_key_axis[i]] == gamma_type.shape[i],
         )
Ejemplo n.º 30
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1)
        x_type, = in_types

        type_check.expect(
            x_type.dtype == numpy.int32,
            x_type.ndim == 1,
        )
Ejemplo n.º 31
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('lhs', 'rhs'))
     type_check.expect(in_types[0].dtype == in_types[1].dtype)
     type_check.expect_broadcast_shapes(in_types[0].shape,
                                        in_types[1].shape)
Ejemplo n.º 32
0
    def check_type_forward(self, in_types):
        type_check._argname(in_types, ('x', 't'))
        x_type, t_type = in_types

        type_check.expect(x_type.dtype.kind == 'f', t_type.dtype.kind == 'i',
                          x_type.shape == t_type.shape)
Ejemplo n.º 33
0
    def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(n_in == 1)

        x_type = in_types[0]
        type_check.expect(x_type.dtype.kind == 'f', x_type.ndim == 4)
Ejemplo n.º 34
0
 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)
     )
Ejemplo n.º 35
0
def _check_ndim(in_type, lower=1, upper=2):
    type_check.expect(in_type.ndim >= lower, in_type.ndim <= upper)
Ejemplo n.º 36
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() > 0)

        shapes = [t.shape for t in in_types]
        type_check.expect_broadcast_shapes(*shapes)
Ejemplo n.º 37
0
 def check_type_backward(self, in_types, out_types):
     type_check.expect(
         out_types.size() == 1,
         _type_check_prod(in_types[0].shape) ==
         _type_check_prod(out_types[0].shape)
     )
Ejemplo n.º 38
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1)
        x_type, = in_types

        type_check.expect(x_type.dtype == numpy.float32, )
Ejemplo n.º 39
0
    def check_type_forward(self, in_types):
        type_check._argname(in_types, ('gy', ))

        gy_type = in_types[0]
        type_check.expect(gy_type.dtype.char == 'f', gy_type.ndim == 4)
Ejemplo n.º 40
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     type_check.expect(in_types[0].dtype.kind == 'f',
                       in_types[0].dtype == in_types[1].dtype,
                       in_types[0].shape == in_types[1].shape)
Ejemplo n.º 41
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x0', 'x1'))
     type_check.expect(in_types[0].dtype.kind == 'f',
                       in_types[0].dtype == in_types[1].dtype,
                       in_types[0].shape == in_types[1].shape)
Ejemplo n.º 42
0
 def check_type_forward(self, xs_type):
     for p, n in zip(xs_type, xs_type[1:]):
         type_check.expect(
             p.shape[0] >= n.shape[0],
             p.shape[1:] == n.shape[1:],
         )
 def check_type_forward(self, in_types):
     x_type, = in_types
     type_check.expect(
         x_type.dtype == numpy.float32,
         x_type.ndim >= 2,
     )
Ejemplo n.º 44
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 1)
     x_type, = in_types
     type_check.expect(x_type.dtype.kind == 'f')
Ejemplo n.º 45
0
 def check_type_forward(self, in_types):
     for i, in_type in enumerate(in_types):
         type_check.argname((in_type, ), ('x{}'.format(i), ))
         type_check.expect(in_types[0].dtype == in_type.dtype)
Ejemplo n.º 46
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     type_check.expect(in_types[0].dtype == numpy.float32,
                       in_types[1].dtype == numpy.float32,
                       in_types[0].shape == in_types[1].shape)
Ejemplo n.º 47
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('x', ))
     type_check.expect(in_types.size() == 1)
Ejemplo n.º 48
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 1,
                       in_types[0].dtype == numpy.float32,
                       in_types[0].ndim == 4)
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() > self._n_cell + self._n_params * 2)

        if self.use_cell:
            (h_type, c_type), in_types = _split(in_types, 2)
            h_size = self.n_layers * self.rnn_direction
            type_check.expect(
                h_type.dtype == numpy.float32,
                c_type.dtype == numpy.float32,
                h_type.ndim == 3,
                h_type.shape[0] == h_size,
                c_type.ndim == 3,
                c_type.shape[0] == h_size,

                # mini-batch size
                h_type.shape[1] == c_type.shape[1],

                # hidden size
                h_type.shape[2] == c_type.shape[2],
            )

        else:
            (h_type, ), in_types = _split(in_types, 1)
            h_size = self.n_layers * self.rnn_direction
            type_check.expect(
                h_type.dtype == numpy.float32,
                h_type.ndim == 3,
                h_type.shape[0] == h_size,
            )

        w_types, in_types = _split(in_types, self._n_params)
        b_types, in_types = _split(in_types, self._n_params)

        x_types = in_types
        for x_type in x_types:
            type_check.expect(
                x_type.dtype == numpy.float32,
                x_type.ndim == 2,
            )
        for x1_type, x2_type in six.moves.zip(x_types, x_types[1:]):
            type_check.expect(
                # Check if xs are sorted by descending lengths
                x1_type.shape[0] >= x2_type.shape[0],
                x1_type.shape[1] == x2_type.shape[1])

        in_size = x_types[0].shape[1]
        out_size = h_type.shape[2]

        for layer in six.moves.range(self.n_layers):
            for i in six.moves.range(self.n_W):
                for di in six.moves.range(self.rnn_direction):
                    ind = (layer * self.rnn_direction + di) * self.n_W + i
                    w_type = w_types[ind]
                    b_type = b_types[ind]
                    if self.rnn_direction == 1:
                        # Uni-direction
                        if layer == 0 and i < (self.n_W // 2):
                            w_in = in_size
                        else:
                            w_in = out_size
                    else:
                        # Bi-direction
                        if layer == 0 and i < (self.n_W // 2):
                            w_in = in_size
                        elif layer > 0 and i < (self.n_W // 2):
                            w_in = out_size * self.rnn_direction
                        else:
                            w_in = out_size

                    type_check.expect(
                        w_type.dtype == numpy.float32,
                        w_type.ndim == 2,
                        w_type.shape[0] == out_size,
                        w_type.shape[1] == w_in,
                        b_type.dtype == numpy.float32,
                        b_type.ndim == 1,
                        b_type.shape[0] == out_size,
                    )
Ejemplo n.º 50
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     n_nones = len([item for item in self.slices if item is None])
     valid_slice = len(self.slices) - n_nones
     type_check.expect(in_types[0].ndim >= valid_slice)
Ejemplo n.º 51
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1,
                          in_types[0].dtype == numpy.float32)

        if self.axis is not None:
            type_check.expect(self.axis < in_types[0].ndim, )
Ejemplo n.º 52
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 1,)
Ejemplo n.º 53
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x', ))
     type_check.expect(in_types[0].dtype.kind == 'f',
                       in_types[0].ndim > self.axis,
                       in_types[0].ndim >= -self.axis)
Ejemplo n.º 54
0
 def _check_type_dataset(self, in_types):
     img_type = in_types[0]
     type_check.expect(
         img_type.dtype.kind == 'f',
     )
Ejemplo n.º 55
0
 def check_type_forward(self, in_types):
     w_type, = in_types
     type_check.expect(w_type.ndim == 5)
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 3)
     bs_type, M_type, logS2_type = in_types
Ejemplo n.º 57
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 1)
     type_check.expect(in_types[0].dtype.kind == 'f')
 def check_type_forward(self, in_types):
     type_check.expect(in_types[0].dtype.kind == 'f', )
Ejemplo n.º 59
0
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x', ))
     type_check.expect(in_types[0].dtype.kind == 'f')
Ejemplo n.º 60
0
 def check_type_backward(self, in_types, out_types):
     type_check.expect(out_types.size() == 1,
                       out_types[0].dtype == numpy.float32,
                       out_types[0].ndim == 0)