我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用chainer.utils.type_check.expect()。
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 >= 2, w_type.ndim == 2, type_check.prod(x_type.shape[1:]) == w_type.shape[1], ) if n_in.eval() == 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[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 == numpy.float32, w_type.dtype == numpy.float32, x_type.ndim >= 2, w_type.ndim == 2, type_check.prod(x_type.shape[1:]) == w_type.shape[1], ) if n_in.eval() == 3: b_type = in_types[2] type_check.expect( b_type.dtype == numpy.float32, b_type.ndim == 1, b_type.shape[0] == w_type.shape[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, x_type.shape == self.indexes.shape, ) if self.outh is not None: expected_h = conv.get_conv_outsize( self.outh, self.kh, self.sy, self.ph, cover_all=self.cover_all) type_check.expect(x_type.shape[2] == expected_h) if self.outw is not None: expected_w = conv.get_conv_outsize( self.outw, self.kw, self.sx, self.pw, cover_all=self.cover_all) type_check.expect(x_type.shape[3] == expected_w)
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[1], ) 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[0], )
def check_type_forward(self, in_types): n_in = in_types.size() type_check.expect(2 <= n_in, n_in <= 4) x_type = in_types[0] v_type = in_types[1] g_type = in_types[1] type_check.expect( x_type.dtype.kind == "f", v_type.dtype.kind == "f", g_type.dtype.kind == "f", x_type.ndim == self.ndim + 2, v_type.ndim == self.ndim + 2, g_type.ndim == self.ndim + 2, x_type.shape[1] == v_type.shape[1], ) 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[0], )
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 2) x_type, t_type = in_types type_check.expect( x_type.dtype.kind == 'f', t_type.dtype == numpy.int32 ) t_ndim = t_type.ndim.eval() type_check.expect( x_type.ndim >= t_type.ndim, x_type.shape[0] == t_type.shape[0], x_type.shape[2: t_ndim + 1] == t_type.shape[1:] ) for i in six.moves.range(t_ndim + 1, x_type.ndim.eval()): type_check.expect(x_type.shape[i] == 1)
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 1) ndim = type_check.Variable(len(self._shape), 'len(shape)') type_check.expect(in_types[0].ndim <= ndim) shape = in_types[0].shape.eval() # check the shape in inverse order for i in six.moves.range(-1, -len(shape) - 1, -1): if shape[i] == self._shape[i] or shape[i] == 1: continue expect = 'in_type[0].shape[%d] == %d' % (i, self._shape[i]) if self._shape[i] != 1: expect += ' or in_type[0].shape[%d] == 1' % i actual = 'in_type[0].shape: %s' % str(shape) raise type_check.InvalidType(expect, actual)
def check_type_forward(self, in_types): type_check.expect( in_types.size() == 1, ) x_type, = in_types cnt = _count_unknown_dims(self.shape) if cnt == 0: type_check.expect( type_check.prod(x_type.shape) == type_check.prod(self.shape)) else: known_size = 1 for s in self.shape: if s > 0: known_size *= s size_var = type_check.Variable(known_size, 'known_size(=%d)' % known_size) type_check.expect( type_check.prod(x_type.shape) % size_var == 0)
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 2) c_type, x_type = in_types type_check.expect( c_type.dtype.kind == 'f', x_type.dtype == c_type.dtype, c_type.ndim >= 2, x_type.ndim >= 2, c_type.ndim == x_type.ndim, x_type.shape[0] == c_type.shape[0], x_type.shape[1] == 4 * c_type.shape[1], ) for i in range(2, c_type.ndim.eval()): type_check.expect(x_type.shape[i] == c_type.shape[i])
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): n_in = in_types.size() type_check.expect(2 <= n_in, n_in <= 3) x_type = in_types[0] w_type = in_types[1] type_check.expect( x_type.dtype == numpy.float32, w_type.dtype == numpy.float32, x_type.ndim == 4, w_type.ndim == 4, x_type.shape[1] == w_type.shape[1], ) if n_in.eval() == 3: b_type = in_types[2] type_check.expect( b_type.dtype == numpy.float32, b_type.ndim == 1, b_type.shape[0] == w_type.shape[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: for axis in self.axis: 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.expect( in_types.size() == 1, in_types[0].dtype.kind == 'f' ) if self.axis is not None: for axis in self.axis: 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.expect(in_types.size() == 2) a_type, b_type = in_types type_check.expect( a_type.dtype == numpy.float32, b_type.dtype == numpy.float32 ) _check_ndim(a_type) _check_ndim(b_type) a_type = _convert_type(a_type) b_type = _convert_type(b_type) a_idx = _get_check_index(self.transa, False) b_idx = _get_check_index(self.transb, True) type_check.expect( a_type.shape[a_idx] == b_type.shape[b_idx] )
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 == numpy.float32, b_type.dtype == numpy.float32 ) _check_ndim(a_type, lower=2, upper=3) _check_ndim(b_type, lower=2, upper=3) a_type = _convert_type(a_type, vector_ndim=2) b_type = _convert_type(b_type, vector_ndim=2) a_idx = _get_check_index(self.transa, False, row_idx=1, col_idx=2) b_idx = _get_check_index(self.transb, True, row_idx=1, col_idx=2) type_check.expect( a_type.shape[a_idx] == b_type.shape[b_idx] )
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] M = gamma_type.ndim.eval() type_check.expect( x_type.dtype.kind == 'f', x_type.ndim >= gamma_type.ndim + 1, x_type.shape[1:1 + M] == gamma_type.shape, # 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): n_in = in_types.size() type_check.expect(2 <= n_in, n_in <= 3) x_type = in_types[0] w_type = in_types[1] 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[1], ) if n_in.eval() == 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[0], )
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[1], ) if n_in.eval() == 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[0], )
def check_type_forward(self, in_types): n_in = in_types.size() type_check.expect(3 <= n_in, n_in <= 4) x_type, w_type, g_type = in_types[:3] type_check.expect( x_type.dtype.kind == "f", w_type.dtype.kind == "f", g_type.dtype.kind == "f", x_type.ndim >= 2, w_type.ndim == 2, g_type.ndim == 2, type_check.prod(x_type.shape[1:]) == w_type.shape[1], ) if n_in.eval() == 4: b_type = in_types[3] type_check.expect( b_type.dtype == x_type.dtype, b_type.ndim == 1, b_type.shape[0] == w_type.shape[0], )
def check_type_forward(self, in_types): n_in = type_check.eval(in_types.size()) 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] M = type_check.eval(gamma_type.ndim) type_check.expect( x_type.dtype.kind == 'f', x_type.ndim >= gamma_type.ndim + 1, x_type.shape[1:1 + M] == gamma_type.shape, # 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): n_in = in_types.size() type_check.expect(2 <= n_in, n_in <= 3) x_type = in_types[0] w_type = in_types[1] type_check.expect( x_type.dtype.kind == 'f', w_type.dtype.kind == 'f', x_type.ndim == 3, w_type.ndim == 3, x_type.shape[1] == w_type.shape[1], ) if n_in.eval() == 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[0], )
def check_type_forward(self, in_types): n_in = in_types.size() type_check.expect(2 <= n_in, n_in <= 3) x_type = in_types[0] w_type = in_types[1] type_check.expect( x_type.dtype.kind == 'f', w_type.dtype.kind == 'f', x_type.ndim == 4, w_type.ndim == 5, x_type.shape[1] == w_type.shape[0] * w_type.shape[2], ) if type_check.eval(n_in) == 3: b_type = in_types[2] type_check.expect( b_type.dtype == x_type.dtype, b_type.ndim == 2, b_type.shape[0] == w_type.shape[0], b_type.shape[1] == w_type.shape[1], )
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 3) x_type, t_type, w_type = in_types type_check.expect( x_type.dtype.kind == 'f', t_type.dtype == numpy.int32, w_type.dtype == 'f', t_type.ndim == x_type.ndim - 1, w_type.ndim == x_type.ndim - 1, x_type.shape[0] == t_type.shape[0], x_type.shape[0] == w_type.shape[0], x_type.shape[2:] == t_type.shape[1:], x_type.shape[2:] == w_type.shape[1:], )
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 == np.float32, w_type.dtype == np.float32, x_type.ndim >= 2, w_type.ndim == 2, type_check.prod(x_type.shape[1:]) == w_type.shape[1], ) if n_in.eval() == 3: b_type = in_types[2] type_check.expect( b_type.dtype == np.float32, b_type.ndim == 1, b_type.shape[0] == w_type.shape[0], )
def check_type_forward(self, in_types): type_check.expect( in_types.size() == 1, in_types[0].dtype.kind == 'f', )
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() == 1, in_types[0].dtype == numpy.float32 )
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.expect(in_types.size() == 1,)
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 2,)
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 2) x_type, roi_type = in_types type_check.expect( x_type.dtype == numpy.float32, x_type.ndim == 4, roi_type.dtype == numpy.float32, roi_type.ndim == 2, roi_type.shape[1] == 5, )
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): n_in = type_check.eval(in_types.size()) if n_in != 3: raise type_check.InvalidType( '%s == %s' % (in_types.size(), n_in)) x_type, gamma_type, beta_type = in_types[:3] M = type_check.eval(gamma_type.ndim) type_check.expect( x_type.dtype.kind == 'f', x_type.ndim >= gamma_type.ndim + 1, x_type.shape[1:1 + M] == gamma_type.shape, gamma_type.dtype == x_type.dtype, beta_type.dtype == x_type.dtype, gamma_type.shape == beta_type.shape, )