Exemplo n.º 1
0
 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',
     )
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    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])
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('y', 'z'))
        y_type, z_type = in_types

        type_check.expect(y_type.dtype.kind == 'f',
                          y_type.dtype == z_type.dtype, y_type.ndim == 2,
                          z_type.ndim == 2, y_type.shape[0] == z_type.shape[0])
Exemplo n.º 5
0
 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)
Exemplo n.º 6
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],
         )
Exemplo n.º 7
0
 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',
     )
Exemplo n.º 8
0
 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
     )
Exemplo n.º 9
0
 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.argname(in_types, ('x', ))
     x_type = in_types[0]
     type_check.expect(x_type.dtype.kind == 'f')
Exemplo n.º 10
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('x1', 'x2'))
     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
     )
Exemplo n.º 11
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])
Exemplo n.º 12
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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
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],
         )
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
    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 == numpy.float32,
                          t_type.dtype.kind == 'i',
                          x_type.shape == t_type.shape)
Exemplo n.º 17
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)
Exemplo n.º 18
0
    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
        )
Exemplo n.º 19
0
 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)
Exemplo n.º 20
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,
     )
Exemplo n.º 21
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,
     )
Exemplo n.º 22
0
 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
     )
Exemplo n.º 23
0
    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])
Exemplo n.º 24
0
 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
     )
Exemplo n.º 25
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)])
Exemplo n.º 26
0
 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])
Exemplo n.º 27
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x',))
        x_type, = in_types

        type_check.expect(
            x_type.dtype.kind == 'f',
            x_type.ndim >= 2,
        )
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x', ))
        x_type, = in_types

        type_check.expect(
            x_type.dtype.kind == 'f',
            x_type.ndim >= 2,
        )
Exemplo n.º 29
0
    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',
        )
Exemplo n.º 30
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x', ))
        x_type, = in_types

        type_check.expect(
            x_type.dtype == numpy.float32,
            x_type.ndim >= 2,
        )
Exemplo n.º 31
0
 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)
Exemplo n.º 32
0
    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',
        )
Exemplo n.º 33
0
 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)
Exemplo n.º 34
0
    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',
        )
Exemplo n.º 35
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('h', ))
        h_type, = in_types

        type_check.expect(
            h_type.dtype.kind == 'f',
            h_type.ndim == 2,
        )
Exemplo n.º 36
0
    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
        )
Exemplo n.º 37
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('h',))
        h_type, = in_types

        type_check.expect(
            h_type.dtype.kind == 'f',
            h_type.ndim == 2,
        )
Exemplo n.º 38
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('a',))
     a_type, = in_types
     type_check.expect(a_type.dtype == numpy.float32)
     # 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])
Exemplo n.º 39
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('lhs', 'rhs'))
     type_check.expect(
         in_types[0].dtype.kind == 'f',
         in_types[0].dtype == in_types[1].dtype,
     )
     type_check.expect_broadcast_shapes(in_types[0].shape,
                                        in_types[1].shape)
Exemplo n.º 40
0
    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',
        )
Exemplo n.º 41
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x', ))
        x_type, = in_types

        type_check.expect(
            x_type.dtype.kind == 'f',
            -x_type.ndim <= self.axis < x_type.ndim,
        )
Exemplo n.º 42
0
    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
        )
Exemplo n.º 43
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('pred', 'true'))
        pred_type, true_type = in_types

        type_check.expect(pred_type.dtype.kind == 'f',
                          true_type.dtype.kind == 'f')

        type_check.expect(pred_type.shape == true_type.shape, )
Exemplo n.º 44
0
    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
        )
Exemplo n.º 45
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
     )
Exemplo n.º 46
0
    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
        )
Exemplo n.º 47
0
    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,
        )
Exemplo n.º 48
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x0', 'x1', 'y'))

        x0_type, x1_type, y_type = in_types
        type_check.expect(
            x0_type.dtype.kind == 'f', x0_type.dtype == x1_type.dtype,
            y_type.dtype.kind == 'i', x0_type.shape == x1_type.shape,
            x1_type.shape[0] == y_type.shape[0], x1_type.shape[0] > 0,
            x0_type.ndim == 2, x1_type.ndim == 2, y_type.ndim == 1)
Exemplo n.º 49
0
    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_type.shape == x_type.shape,
        )
Exemplo n.º 50
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('x',))
     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])
Exemplo n.º 51
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('real', 'imag'))
     r_type, i_type = in_types
     type_check.expect(
         r_type.dtype.kind == 'f',
         r_type.ndim > 0,
         r_type.shape == i_type.shape,
         r_type.dtype == i_type.dtype,
     )
Exemplo n.º 52
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x',))

        x_type = in_types[0]
        type_check.expect(
            x_type.dtype.kind == 'f',
            x_type.ndim == 4,
            x_type.shape[1] >= self.kh * self.kw,
        )
Exemplo n.º 53
0
 def check_type_forward(self, in_types):
     type_check.argname(in_types, ('x', ))
     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])
Exemplo n.º 54
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('x', 't'))

        x_type, t_type = in_types
        type_check.expect(
            t_type.dtype.kind == 'i',
            x_type.ndim == 2,
            t_type.ndim == 1,
            x_type.shape[0] == t_type.shape[0],
        )
Exemplo n.º 55
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)]
     )
Exemplo n.º 56
0
    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,
        )
Exemplo n.º 57
0
    def check_type_forward(self, in_types):
        type_check.argname(in_types, ('y', 'z'))
        y_type, z_type = in_types

        type_check.expect(
            y_type.dtype.kind == 'f',
            y_type.dtype == z_type.dtype,
            y_type.ndim == 2,
            z_type.ndim == 2,
            y_type.shape[0] == z_type.shape[0]
        )