Python chainer.utils.type_check.expect() Examples
The following are 30
code examples of chainer.utils.type_check.expect().
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: 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 #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: 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.expect( -in_types[0].ndim - 1 <= self.axis, self.axis <= in_types[0].ndim ) # XXX: modified for i in range(1, type_check.eval(in_types.size())): type_check.expect( in_types[0].dtype == in_types[i].dtype, in_types[0].shape == in_types[i].shape, ) # XXX: the following doesn't work # dtype = in_types[0].dtype # shape = in_types[0].shape # for x_type in in_types[1:]: # type_check.expect( # x_type.dtype == dtype, # x_type.shape == shape, # )
Example #4
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.expect(in_types[0].ndim > type_check.make_variable(self.axis, 'axis')) type_check.expect( -in_types[0].ndim <= self.axis, self.axis < in_types[0].ndim ) ndim = type_check.eval(in_types[0].ndim) axis = self.axis % ndim for i in range(1, type_check.eval(in_types.size())): type_check.expect( in_types[0].dtype == in_types[i].dtype, in_types[0].ndim == in_types[i].ndim, ) for d in range(0, ndim): if d == axis: continue type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
Example #5
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 #6
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 #7
Source File: tree_lstm.py From chainer with MIT License | 6 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() >= 2) c_types = in_types[:-1] x_type = in_types[-1] n_ary = len(c_types) type_check.expect(x_type.ndim >= 2) for i in six.moves.range(len(c_types)): type_check.expect( c_types[i].dtype.kind == 'f', x_type.dtype == c_types[i].dtype, c_types[i].ndim >= 2, c_types[i].ndim == x_type.ndim, x_type.shape[0] == c_types[i].shape[0], x_type.shape[1] == (3 + n_ary) * c_types[i].shape[1], ) for j in six.moves.range(2, type_check.eval(c_types[i].ndim)): type_check.expect(x_type.shape[i] == c_types[i].shape[j])
Example #8
Source File: ln_lstm.py From knmt with GNU General Public License v3.0 | 6 votes |
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 six.moves.range(2, c_type.ndim.eval()): type_check.expect(x_type.shape[i] == c_type.shape[i])
Example #9
Source File: sum.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 #10
Source File: dropout.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 #11
Source File: hyperbolic.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 #12
Source File: permutate.py From chainer with MIT License | 5 votes |
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)
Example #13
Source File: pad_sequence.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() > 0) for i, in_type in enumerate(in_types): type_check._argname((in_type,), ('x{}'.format(i),)) type_check.expect( in_type.ndim > 0, in_type.shape[1:] == in_types[0].shape[1:], in_type.dtype == in_types[0].dtype ) if self.length is not None: for in_type in in_types: type_check.expect(in_type.shape[0] <= self.length)
Example #14
Source File: gaussian.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('mean', 'ln_var')) m_type, v_type = in_types type_check.expect( m_type.dtype.kind == 'f', m_type.dtype == v_type.dtype, m_type.shape == v_type.shape, )
Example #15
Source File: space2depth.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', in_types[0].ndim == 4 )
Example #16
Source File: simplified_dropconnect.py From chainer with MIT License | 5 votes |
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)
Example #17
Source File: sqrt.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: scatter_add.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('a', 'b')) 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)
Example #19
Source File: fliplr.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[0] type_check.expect( a_type.dtype.kind == 'f', a_type.ndim >= 2 )
Example #20
Source File: spatial_transformer_grid.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('theta',)) theta_type = in_types[0] type_check.expect( theta_type.dtype.kind == 'f', theta_type.ndim == 3, theta_type.shape[1] == 2, theta_type.shape[2] == 3, )
Example #21
Source File: transpose_sequence.py From chainer with MIT License | 5 votes |
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:], )
Example #22
Source File: as_strided.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 1)
Example #23
Source File: squeeze.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 1) x_type = in_types[0] if self.axis is not None: for x in self.axis: if x >= 0: type_check.expect(x < x_type.ndim) else: type_check.expect(-x_type.ndim <= x)
Example #24
Source File: rollaxis.py From chainer with MIT License | 5 votes |
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(x_type.ndim > self.axis) else: type_check.expect(x_type.ndim > -self.axis - 1) if self.start >= 0: type_check.expect(x_type.ndim >= self.start) else: type_check.expect(x_type.ndim > -self.start - 1)
Example #25
Source File: flip.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) x_type = in_types[0] type_check.expect(x_type.ndim > 0) if self.axis >= 0: type_check.expect(x_type.ndim > self.axis) else: type_check.expect(x_type.ndim >= -self.axis)
Example #26
Source File: flipud.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[0] type_check.expect( a_type.dtype.kind == 'f', a_type.ndim >= 1 )
Example #27
Source File: diagonal.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) in_type = in_types[0] type_check.expect(max(self.axis1, self.axis2) < in_type.ndim) type_check.expect(-in_type.ndim <= min(self.axis1, self.axis2))
Example #28
Source File: where.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x', 'y')) x_type, y_type = in_types condition = type_check._make_variable_from_array( # allow scalar `condition` chainer.utils.force_array(self.condition), 'condition') type_check.expect( condition.dtype == numpy.bool_, x_type.dtype == y_type.dtype, ) type_check.expect_broadcast_shapes( condition.shape, x_type.shape, y_type.shape)
Example #29
Source File: tile.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check.expect(in_types.size() == 1)
Example #30
Source File: resize_images.py From chainer with MIT License | 5 votes |
def check_type_forward(self, in_types): type_check._argname(in_types, ('x',)) x_type = in_types[0] type_check.expect( x_type.dtype == numpy.float32, x_type.ndim == 4 )