Python chainer.utils.type_check._argname() Examples
The following are 30
code examples of chainer.utils.type_check._argname().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
chainer.utils.type_check
, or try the search function
.
Example #1
Source File: matmul.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('a', 'b')) 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_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) a_size = _get_size(a_type, a_idx) b_size = _get_size(b_type, b_idx) type_check.expect( a_size == b_size )
Example #2
Source File: dstack.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() > 0) type_check._argname((in_types[0],), ('x0',)) ndim = type_check.eval(in_types[0].ndim) for i in six.moves.range(1, type_check.eval(in_types.size())): type_check._argname((in_types[i],), ('x{}'.format(i),)) type_check.expect( in_types[0].dtype == in_types[i].dtype, in_types[0].ndim == in_types[i].ndim, ) if ndim <= 2: type_check.expect(in_types[0].shape == in_types[i].shape) continue for d in six.moves.range(0, ndim): if d == 2: continue type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
Example #3
Source File: broadcast.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) ndim = type_check.make_variable(len(self._shape), 'len(shape)') type_check.expect(in_types[0].ndim <= ndim) shape = type_check.eval(in_types[0].shape) # 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)
Example #4
Source File: hstack.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() > 0) type_check._argname((in_types[0],), ('x0',)) ndim = type_check.eval(in_types[0].ndim) for i in six.moves.range(1, type_check.eval(in_types.size())): type_check._argname((in_types[i],), ('x{}'.format(i),)) type_check.expect( in_types[0].dtype == in_types[i].dtype, in_types[0].ndim == in_types[i].ndim, ) if ndim <= 1: continue for d in six.moves.range(0, ndim): if d == 1: continue type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
Example #5
Source File: reshape.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) x_type, = in_types if self._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.make_variable( known_size, 'known_size(=%d)' % known_size) type_check.expect( type_check.prod(x_type.shape) % size_var == 0)
Example #6
Source File: average.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(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, ) # TODO(kataoka): override `forward_chainerx` if `chainerx.mean` does not # overflow for large float16 inputs
Example #7
Source File: chainer_functions.py From chainer-compiler with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() > 0) type_check._argname((in_types[0],), ('x0',)) ndim = type_check.eval(in_types[0].ndim) for i in range(1, type_check.eval(in_types.size())): type_check._argname((in_types[i],), ('x{}'.format(i),)) type_check.expect( in_types[0].dtype == in_types[i].dtype, in_types[0].ndim == in_types[i].ndim, ) if ndim <= 1: continue for d in range(0, ndim): if d == 1: continue type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
Example #8
Source File: top_k_accuracy1.py From imgclsmob with MIT License | 6 votes |
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' ) t_ndim = type_check.eval(t_type.ndim) 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, type_check.eval(x_type.ndim)): type_check.expect(x_type.shape[i] == 1)
Example #9
Source File: lstm.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('c', 'x')) 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 six.moves.range(2, type_check.eval(c_type.ndim)): type_check.expect(x_type.shape[i] == c_type.shape[i])
Example #10
Source File: sparse_matmul.py From chainer with MIT License | 5 votes |
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], )
Example #11
Source File: basic_math.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',))
Example #12
Source File: square.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #13
Source File: logsumexp.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(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, )
Example #14
Source File: linear_interpolate.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('p', 'x', 'y')) p_type, x_type, y_type = in_types type_check.expect( p_type.dtype.kind == 'f', x_type.dtype == p_type.dtype, y_type.dtype == p_type.dtype, p_type.shape == x_type.shape, p_type.shape == y_type.shape, )
Example #15
Source File: matmul.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('a', 'b')) 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])
Example #16
Source File: basic_math.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #17
Source File: erfinv.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #18
Source File: basic_math.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #19
Source File: exponential_m1.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #20
Source File: minmax.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(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, )
Example #21
Source File: cholesky.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('a', )) a_type, = in_types type_check.expect( a_type.dtype.kind == 'f', a_type.ndim == 2, )
Example #22
Source File: inv.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('a',)) a_type, = in_types type_check.expect(a_type.dtype.kind == 'f') # Only a minibatch of 2D array shapes allowed type_check.expect(a_type.ndim == 3) # Matrix inversion only allowed for square matrices # so assert the last two dimensions are equal type_check.expect(a_type.shape[-1] == a_type.shape[-2])
Example #23
Source File: inv.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('a',)) a_type, = in_types type_check.expect(a_type.dtype.kind == 'f') # Only 2D array shapes allowed type_check.expect(a_type.ndim == 2) # Matrix inversion only allowed for square matrices type_check.expect(a_type.shape[0] == a_type.shape[1])
Example #24
Source File: cumsum.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f') if self.axis is not None: if self.axis >= 0: type_check.expect(self.axis < in_types[0].ndim) else: type_check.expect(-self.axis - 1 < in_types[0].ndim)
Example #25
Source File: polygamma.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('n', 'x')) n_type, x_type = in_types type_check.expect( n_type.dtype.kind == 'i', x_type.dtype.kind == 'f', )
Example #26
Source File: exponential.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #27
Source File: exponential.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #28
Source File: exponential.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) type_check.expect(in_types[0].dtype.kind == 'f')
Example #29
Source File: basic_math.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',))
Example #30
Source File: trigonometric.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x1', 'x2')) type_check.expect(in_types[0].dtype.kind == 'f') type_check.expect(in_types[1].dtype.kind == 'f')