Python chainer.utils.type_check 模块,eval() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用chainer.utils.type_check.eval()

项目:chainer-speech-recognition    作者:musyoku    | 项目源码 | 文件源码
def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(3 <= n_in, n_in <= 4)
        x_type = in_types[0]
        v_type = in_types[1]
        g_type = in_types[2]
        type_check.expect(
            x_type.dtype.kind == "f",
            v_type.dtype.kind == "f",
            g_type.dtype.kind == "f",
            x_type.ndim == 4,
            v_type.ndim == 4,
            g_type.ndim == 4,
            x_type.shape[1] == v_type.shape[1],
        )

        if type_check.eval(n_in) == 4:
            b_type = in_types[3]
            type_check.expect(
                b_type.dtype == x_type.dtype,
                b_type.ndim == 1,
                b_type.shape[0] == v_type.shape[0],
            )
项目:chainer-qrnn    作者:musyoku    | 项目源码 | 文件源码
def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(2 <= n_in, n_in <= 4)

        x_type = in_types[0]
        v_type = in_types[1]
        g_type = in_types[1]
        type_check.expect(
            x_type.dtype.kind == "f",
            v_type.dtype.kind == "f",
            g_type.dtype.kind == "f",
            x_type.ndim == self.ndim + 2,
            v_type.ndim == self.ndim + 2,
            g_type.ndim == self.ndim + 2,
            x_type.shape[1] == v_type.shape[1],
        )

        if type_check.eval(n_in) == 4:
            b_type = in_types[3]
            type_check.expect(
                b_type.dtype == x_type.dtype,
                b_type.ndim == 1,
                b_type.shape[0] == v_type.shape[0],
            )
项目:chainermn    作者:chainer    | 项目源码 | 文件源码
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,
            )
项目:chainer-glu    作者:musyoku    | 项目源码 | 文件源码
def check_type_forward(self, in_types):
        n_in = in_types.size()
        type_check.expect(2 <= n_in, n_in <= 4)

        x_type = in_types[0]
        v_type = in_types[1]
        g_type = in_types[1]
        type_check.expect(
            x_type.dtype.kind == "f",
            v_type.dtype.kind == "f",
            g_type.dtype.kind == "f",
            x_type.ndim == self.ndim + 2,
            v_type.ndim == self.ndim + 2,
            g_type.ndim == self.ndim + 2,
            x_type.shape[1] == v_type.shape[1],
        )

        if type_check.eval(n_in) == 4:
            b_type = in_types[3]
            type_check.expect(
                b_type.dtype == x_type.dtype,
                b_type.ndim == 1,
                b_type.shape[0] == v_type.shape[0],
            )
项目:resnetfamily    作者:takedarts    | 项目源码 | 文件源码
def check_type_forward(self, in_types):
    n_in = in_types.size()
    type_check.expect(2 <= n_in, n_in <= 3)

    x_type = in_types[0]
    w_type = in_types[1]
    type_check.expect(
      x_type.dtype.kind == 'f',
      w_type.dtype.kind == 'f',
      x_type.ndim == 4,
      w_type.ndim == 5,
      x_type.shape[1] == w_type.shape[0] * w_type.shape[2],
    )

    if type_check.eval(n_in) == 3:
      b_type = in_types[2]
      type_check.expect(
        b_type.dtype == x_type.dtype,
        b_type.ndim == 2,
        b_type.shape[0] == w_type.shape[0],
        b_type.shape[1] == w_type.shape[1],
      )
项目:instance_normalization_chainer    作者:crcrpar    | 项目源码 | 文件源码
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,
        )
项目:chainer-speech-recognition    作者:musyoku    | 项目源码 | 文件源码
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],
            )

    # x: (batchsize, feature_dimension, seq_length)