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])
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])
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 )
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] )
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, )
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 )
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)
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
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')
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 )
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', )
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)
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)
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 )
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, )
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], )
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, )
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)
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, )
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, )
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 )
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] )
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 )
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)
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)
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 )
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] )
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], )
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, )
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)
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)
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)
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 _check_ndim(in_type, lower=1, upper=2): type_check.expect(in_type.ndim >= lower, in_type.ndim <= upper)
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)
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) )
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, )
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)
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)
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)
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, )
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')
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)
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)
def check_type_forward(self, in_types): type_check.argname(in_types, ('x', )) type_check.expect(in_types.size() == 1)
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, )
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)
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, )
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 1,)
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)
def _check_type_dataset(self, in_types): img_type = in_types[0] type_check.expect( img_type.dtype.kind == 'f', )
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
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', )
def check_type_forward(self, in_types): type_check._argname(in_types, ('x', )) type_check.expect(in_types[0].dtype.kind == 'f')
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)