예제 #1
0
파일: matmul.py 프로젝트: km-t/dcpython
    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])
예제 #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_ndim = type_check.eval(a_type.ndim)
        b_ndim = type_check.eval(b_type.ndim)
        if a_ndim == 0 or b_ndim == 0:
            pass
        elif a_ndim == 1 or b_ndim == 1:
            type_check.expect(
                a_type.ndim == b_type.ndim,
                a_type.shape == b_type.shape,
            )
        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.ndim == b_type.ndim,
                a_type.shape[:-2] == b_type.shape[:-2],
                a_type.shape[a_idx] == b_type.shape[b_idx],
            )
예제 #3
0
파일: matmul.py 프로젝트: jnishi/chainer
    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])
예제 #4
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(tkerola): 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,
         )
예제 #5
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.kind == 'f',
         beta_type.dtype == gamma_type.dtype,
         mean_type.dtype == gamma_type.dtype,
         var_type.dtype == gamma_type.dtype,
         beta_type.shape == gamma_type.shape,
         mean_type.shape == gamma_type.shape,
         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],
         )
예제 #6
0
파일: matmul.py 프로젝트: Fhrozen/chainer
    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_ndim = type_check.eval(a_type.ndim)
        b_ndim = type_check.eval(b_type.ndim)
        if a_ndim == 0 or b_ndim == 0:
            pass
        elif a_ndim == 1 or b_ndim == 1:
            type_check.expect(
                a_type.ndim == b_type.ndim,
                a_type.shape == b_type.shape,
            )
        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.ndim == b_type.ndim,
                a_type.shape[:-2] == b_type.shape[:-2],
                a_type.shape[a_idx] == b_type.shape[b_idx],
            )
예제 #7
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,
         )
예제 #8
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() == 2)
        x_type, t_type = in_types

        type_check.expect(x_type.dtype.kind == 'f', t_type.dtype == np.int32)

        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 moves.range(t_ndim + 1, type_check.eval(x_type.ndim)):
            type_check.expect(x_type.shape[i] == 1)
    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)
예제 #11
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() > 0)

        ndim = type_check.eval(in_types[0].ndim)
        for i in six.moves.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,
            )
            if ndim <= 1:
                type_check.expect(in_types[0].shape == in_types[i].shape)
                continue
            for d in six.moves.range(1, ndim):
                type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
예제 #12
0
 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,
     )
예제 #13
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() > 0)

        ndim = type_check.eval(in_types[0].ndim)
        for i in six.moves.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,
            )
            if ndim <= 1:
                type_check.expect(in_types[0].shape == in_types[i].shape)
                continue
            for d in six.moves.range(1, ndim):
                type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
예제 #14
0
    def check_type_forward(self, in_types):
        type_check._argname(in_types, ('c_prev1', 'c_prev2', 'x1', 'x2'))
        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, type_check.eval(c1_type.ndim)):
            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])
예제 #15
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)
	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]
			)
예제 #17
0
    def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(4 <= n_in, n_in <= 5)

        x_type = in_types[0]
        w_type = in_types[1]
        b_type = in_types[2]
        ct_type = in_types[3]
        type_check.expect(
            x_type.dtype.kind == "f",
            w_type.dtype.kind == "f",
            b_type.dtype.kind == "f",
            x_type.ndim == 3,
            w_type.ndim == 2,
            b_type.ndim == 1,
            b_type.shape[0] * 3 == w_type.shape[0] * 2,
            ct_type.dtype == x_type.dtype,
            ct_type.ndim == 2,
            ct_type.shape[1] == x_type.shape[1],
        )

        if type_check.eval(n_in) == 5:
            mask_x_type = in_types[4]
            type_check.expect(
                mask_x_type.dtype == x_type.dtype,
                mask_x_type.ndim == 2,
                mask_x_type.shape[1] == x_type.shape[1],
            )
예제 #18
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]
            )
예제 #19
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 >= 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.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)
예제 #20
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     x_type, W_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f', W_type.dtype == x_type.dtype,
         x_type.ndim >= W_type.ndim + 1,
         x_type.shape[1:1 + type_check.eval(W_type.ndim)] == W_type.shape)
예제 #21
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     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],
         )
예제 #22
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, type_check.eval(c1_type.ndim)):
            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])
예제 #23
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('x', 'W'))
     x_type, W_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f', W_type.dtype == x_type.dtype,
         x_type.ndim >= W_type.ndim + 1,
         x_type.shape[1:1 + type_check.eval(W_type.ndim)] == W_type.shape)
예제 #24
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 == self.ndim + 2,
                          w_type.ndim == self.ndim + 2,
                          x_type.shape[1] == w_type.shape[0])

        if self.outs is not None:
            for i, (out, s, p, di) in enumerate(
                    zip(self.outs, self.stride, self.pad, self.dilate)):
                lower_bound = conv.get_conv_outsize(out,
                                                    w_type.shape[i + 2],
                                                    s,
                                                    p,
                                                    d=di)
                upper_bound = conv.get_conv_outsize(out,
                                                    w_type.shape[i + 2],
                                                    s,
                                                    p,
                                                    cover_all=True,
                                                    d=di)
                type_check.expect(lower_bound <= x_type.shape[i + 2],
                                  x_type.shape[i + 2] <= upper_bound)

        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,
                # Need to consider the case that group count > 1.
                # b_type.shape[0] == w_type.shape[1]
            )
예제 #25
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:
            lower_bound = conv.get_conv_outsize(self.outh, w_type.shape[2],
                                                self.sy, self.ph)
            upper_bound = conv.get_conv_outsize(self.outh,
                                                w_type.shape[2],
                                                self.sy,
                                                self.ph,
                                                cover_all=True)
            type_check.expect(lower_bound <= x_type.shape[2],
                              x_type.shape[2] <= upper_bound)
        if self.outw is not None:
            lower_bound = conv.get_conv_outsize(self.outw, w_type.shape[3],
                                                self.sx, self.pw)
            upper_bound = conv.get_conv_outsize(self.outw,
                                                w_type.shape[3],
                                                self.sx,
                                                self.pw,
                                                cover_all=True)
            type_check.expect(lower_bound <= x_type.shape[3],
                              x_type.shape[3] <= upper_bound)

        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):
        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])
예제 #27
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],
         )
예제 #28
0
파일: slstm.py 프로젝트: zox312/chainer
    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, type_check.eval(c1_type.ndim)):
            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])
예제 #29
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 == self.ndim + 2,
            w_type.ndim == self.ndim + 2,
            x_type.shape[1] == w_type.shape[0]
        )

        if self.outs is not None:
            for i, (out, s, p) in enumerate(zip(
                    self.outs, self.stride, self.pad)):
                type_check.expect(
                    x_type.shape[i + 2] ==
                    conv.get_conv_outsize(out, w_type.shape[i + 2], s, p)
                )

        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]
            )
예제 #30
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     a_type, b_type = in_types
     # a_type.shape: ((nb,) _m, _k) when transa is False
     # b_type.shape: ((nb,) _k, _n) when transb is False
     a_m_axis, a_k_axis = -2, -1
     b_k_axis, b_n_axis = -2, -1
     sp_m_axis, sp_n_axis = -2, -1
     if self.transa:
         a_m_axis, a_k_axis = -1, -2
     if self.transb:
         b_k_axis, b_n_axis = -1, -2
     if self.transc:
         sp_m_axis, sp_n_axis = -1, -2
     type_check.expect(
         a_type.dtype.kind == 'f',
         b_type.dtype.kind == 'f',
         a_type.ndim >= 2,
         a_type.ndim <= 3,
         a_type.ndim == b_type.ndim,
         a_type.shape[a_m_axis] == self.sp_shape[sp_m_axis],
         b_type.shape[b_n_axis] == self.sp_shape[sp_n_axis],
         a_type.shape[a_k_axis] == b_type.shape[b_k_axis],
     )
     a_ndim = type_check.eval(a_type.ndim)
     if a_ndim == 3:
         type_check.expect(
             a_type.shape[0] == self.sp_row.shape[0],
             b_type.shape[0] == self.sp_row.shape[0],
         )
예제 #31
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 == self.ndim + 2,
            w_type.ndim == self.ndim + 2,
            x_type.shape[1] == w_type.shape[0]
        )

        if self.outs is not None:
            for i, (out, s, p, di) in enumerate(zip(
                    self.outs, self.stride, self.pad, self.dilate)):
                lower_bound = conv.get_conv_outsize(
                    out, w_type.shape[i + 2], s, p, d=di)
                upper_bound = conv.get_conv_outsize(
                    out, w_type.shape[i + 2], s, p, cover_all=True, d=di)
                type_check.expect(
                    lower_bound <= x_type.shape[i + 2],
                    x_type.shape[i + 2] <= upper_bound)

        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,
                # Need to consider the case that group count > 1.
                # b_type.shape[0] == w_type.shape[1]
            )
예제 #32
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     a_type, b_type = in_types
     # a_type.shape: ((nb,) _m, _k) when transa is False
     # b_type.shape: ((nb,) _k, _n) when transb is False
     a_m_axis, a_k_axis = -2, -1
     b_k_axis, b_n_axis = -2, -1
     sp_m_axis, sp_n_axis = -2, -1
     if self.transa:
         a_m_axis, a_k_axis = -1, -2
     if self.transb:
         b_k_axis, b_n_axis = -1, -2
     if self.transc:
         sp_m_axis, sp_n_axis = -1, -2
     type_check.expect(
         a_type.dtype.kind == 'f',
         b_type.dtype.kind == 'f',
         a_type.ndim >= 2,
         a_type.ndim <= 3,
         a_type.ndim == b_type.ndim,
         a_type.shape[a_m_axis] == self.sp_shape[sp_m_axis],
         b_type.shape[b_n_axis] == self.sp_shape[sp_n_axis],
         a_type.shape[a_k_axis] == b_type.shape[b_k_axis],
     )
     a_ndim = type_check.eval(a_type.ndim)
     if a_ndim == 3:
         type_check.expect(
             a_type.shape[0] == self.sp_row.shape[0],
             b_type.shape[0] == self.sp_row.shape[0],
         )
예제 #33
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1)
        a_type = self.value
        b_type = in_types[0]

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

        ndim = type_check.eval(a_type.ndim)
        if ndim == 1:
            type_check.expect(a_type.shape == b_type.shape)
        else:
            a_idx = _matmul._get_check_index(False,
                                             False,
                                             row_idx=-2,
                                             col_idx=-1)
            b_idx = _matmul._get_check_index(False,
                                             True,
                                             row_idx=-2,
                                             col_idx=-1)
            type_check.expect(
                a_type.shape[:-2] == b_type.shape[:-2],
                a_type.shape[a_idx] == b_type.shape[b_idx],
            )
예제 #34
0
파일: slstm.py 프로젝트: okuta/chainer
    def check_type_forward(self, in_types):
        type_check._argname(in_types, ('c_prev1', 'c_prev2', 'x1', 'x2'))
        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, type_check.eval(c1_type.ndim)):
            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])
예제 #35
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 = 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)
예제 #36
0
파일: accuracy.py 프로젝트: asi1024/chainer
    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)
예제 #37
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('x', 'beta'))
     x_type, beta_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f', beta_type.dtype == x_type.dtype,
         beta_type.ndim <= x_type.ndim - 1,
         beta_type.shape == x_type.shape[1:1 +
                                         type_check.eval(beta_type.ndim)])
예제 #38
0
    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])
예제 #39
0
파일: hstack.py 프로젝트: mitmul/chainer
    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])
예제 #40
0
파일: prelu.py 프로젝트: okuta/chainer
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x', 'W'))
     x_type, W_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f',
         W_type.dtype == x_type.dtype,
         x_type.ndim >= W_type.ndim + 1,
         x_type.shape[1:1 + type_check.eval(W_type.ndim)] == W_type.shape
     )
예제 #41
0
파일: concat.py 프로젝트: pombredanne/ideep
    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 six.moves.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 six.moves.range(0, ndim):
                if d == axis:
                    continue
                type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
예제 #42
0
파일: prelu.py 프로젝트: Fhrozen/chainer
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     x_type, W_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f',
         W_type.dtype == x_type.dtype,
         x_type.ndim >= W_type.ndim + 1,
         x_type.shape[1:1 + type_check.eval(W_type.ndim)] == W_type.shape
     )
예제 #43
0
파일: swish.py 프로젝트: hvy/chainer
 def check_type_forward(self, in_types):
     type_check._argname(in_types, ('x', 'beta'))
     x_type, beta_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f',
         beta_type.dtype == x_type.dtype,
         beta_type.ndim <= x_type.ndim - 1,
         beta_type.shape == x_type.shape[1:1 +
                                         type_check.eval(beta_type.ndim)]
     )
예제 #44
0
파일: swish.py 프로젝트: z331565360/chainer
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 2)
     x_type, beta_type = in_types
     type_check.expect(
         x_type.dtype.kind == 'f',
         beta_type.dtype == x_type.dtype,
         beta_type.ndim <= x_type.ndim - 1,
         beta_type.shape == x_type.shape[1:1 +
                                         type_check.eval(beta_type.ndim)]
     )
예제 #45
0
파일: concat.py 프로젝트: fukatani/chainer
    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 six.moves.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 six.moves.range(0, ndim):
                if d == axis:
                    continue
                type_check.expect(in_types[0].shape[d] == in_types[i].shape[d])
예제 #46
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() > 0)

        shapes = [type_check.eval(t).shape for t in in_types]
        r_shapes = [s[::-1] for s in shapes]
        r_filled = six.moves.zip_longest(*r_shapes, fillvalue=1)
        for ss in r_filled:
            d = max(ss)
            if not all(s == d or s == 1 for s in ss):
                expect = 'each dimension has the same size or is 1'
                actual = 'shapes: ' + ', '.join(map(str, shapes))
                raise type_check.InvalidType(expect, actual)
예제 #47
0
파일: broadcast.py 프로젝트: d0i/chainer
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() > 0)

        shapes = [type_check.eval(t).shape for t in in_types]
        r_shapes = [s[::-1] for s in shapes]
        r_filled = six.moves.zip_longest(*r_shapes, fillvalue=1)
        for ss in r_filled:
            d = max(ss)
            if not all(s == d or s == 1 for s in ss):
                expect = 'each dimension has the same size or is 1'
                actual = 'shapes: ' + ', '.join(map(str, shapes))
                raise type_check.InvalidType(expect, actual)
예제 #48
0
 def check_type_forward(self, in_types):
     type_check.expect(in_types.size() == 3)
     x_type, gamma_type, beta_type = in_types
     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(tkerola): Check shape
         gamma_type.dtype == x_type.dtype,
         beta_type.dtype == x_type.dtype,
         gamma_type.shape == beta_type.shape,
     )
예제 #49
0
    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,
            )
예제 #50
0
파일: lstm.py 프로젝트: yuwata/chainer
    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, type_check.eval(c_type.ndim)):
            type_check.expect(x_type.shape[i] == c_type.shape[i])
예제 #51
0
    def check_type_forward(self, in_types):
        type_check.expect(in_types.size() == 1)

        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)
예제 #52
0
    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)
예제 #53
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 == 6,
            x_type.shape[1] == w_type.shape[3],
        )
        if type_check.eval(n_in) == 3:
            b_type = in_types[2]
            type_check.expect(b_type.dtype == x_type.dtype, b_type.ndim == 3,
                              b_type.shape == w_type.shape[:3])
예제 #54
0
파일: lstm.py 프로젝트: asi1024/chainer
    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])
예제 #55
0
파일: tree_lstm.py 프로젝트: okuta/chainer
    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])
예제 #56
0
파일: linear.py 프로젝트: delta2323/chainer
    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 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[0],
            )
예제 #57
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 == 6,
            x_type.shape[1] == w_type.shape[3],
        )
        if type_check.eval(n_in) == 3:
            b_type = in_types[2]
            type_check.expect(
                b_type.dtype == x_type.dtype,
                b_type.ndim == 3,
                b_type.shape == w_type.shape[:3]
            )
예제 #58
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:
            lower_bound = conv.get_conv_outsize(
                self.outh, w_type.shape[2], self.sy, self.ph,
                d=self.dy)
            upper_bound = conv.get_conv_outsize(
                self.outh, w_type.shape[2], self.sy, self.ph, cover_all=True,
                d=self.dy)
            type_check.expect(
                lower_bound <= x_type.shape[2],
                x_type.shape[2] <= upper_bound)
        if self.outw is not None:
            lower_bound = conv.get_conv_outsize(
                self.outw, w_type.shape[3], self.sx, self.pw,
                d=self.dx)
            upper_bound = conv.get_conv_outsize(
                self.outw, w_type.shape[3], self.sx, self.pw, cover_all=True,
                d=self.dx)
            type_check.expect(
                lower_bound <= x_type.shape[3],
                x_type.shape[3] <= upper_bound)

        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,
                # Need to consider the case that group count > 1.
                # b_type.shape[0] == w_type.shape[1],
            )