当前位置: 首页>>代码示例>>Python>>正文


Python testing.product方法代码示例

本文整理汇总了Python中chainer.testing.product方法的典型用法代码示例。如果您正苦于以下问题:Python testing.product方法的具体用法?Python testing.product怎么用?Python testing.product使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainer.testing的用法示例。


在下文中一共展示了testing.product方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_find_snapshot_files

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def test_find_snapshot_files(self):
        noise = ('tmpsnapshot_iter_{}.{}'.format(i, j)
                 for i, j in zip(range(10, 304), range(10, 200)))

        for file in itertools.chain(noise, self.files):
            file = os.path.join(self.path, file)
            open(file, 'w').close()

        snapshot_files = _find_snapshot_files(self.fmt, self.path)

        expected = [self.fmt.format(i*10, j*10)
                    for i, j in itertools.product(range(0, 10), range(0, 10))]

        timestamps, snapshot_files = zip(*snapshot_files)
        expected.sort()
        snapshot_files = sorted(list(snapshot_files))
        assert expected == snapshot_files 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:test_snapshot.py

示例2: inject_backend_tests

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def inject_backend_tests():
    decorator = backend.inject_backend_tests(
        None,
        # CPU tests
        testing.product({
            'use_cuda': [False],
            'use_ideep': ['never', 'always'],
        })
        # GPU tests
        + [{'use_cuda': True}]
        # ChainerX tests
        + [
            {'use_chainerx': True, 'chainerx_device': 'native:0'},
            {'use_chainerx': True, 'chainerx_device': 'cuda:0'},
            {'use_chainerx': True, 'chainerx_device': 'cuda:1'},
        ])
    return decorator 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:test_split_axis.py

示例3: check_forward

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def check_forward(self, x_data, axis):
        eps = self.eps
        x = chainer.Variable(x_data)

        y = functions.normalize(x, eps=eps, axis=axis)
        self.assertEqual(y.data.dtype, self.dtype)
        y_data = cuda.to_cpu(y.data)

        y_expect = numpy.empty_like(self.x)
        shape = self.x.shape
        indices = []
        axis_tuple = axis if isinstance(axis, tuple) else (axis,)
        for i in six.moves.range(len(shape)):
            if i not in axis_tuple:
                indices.append(six.moves.range(shape[i]))
            else:
                indices.append([slice(None)])
        indices_tuple = list(itertools.product(*indices))
        for index in indices_tuple:
            # Note: Casting back the result of `numpy.linalg.norm` to `x.dtype`
            # because old NumPy casts it to float32 when a float16 value is
            # given.
            numerator = numpy.linalg.norm(self.x[index]).astype(x.dtype) + eps
            y_expect[index] = self.x[index] / numerator
        testing.assert_allclose(y_expect, y_data, **self.check_forward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:27,代码来源:test_l2_normalization.py

示例4: _create_parameters

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def _create_parameters():
    params = testing.product({
        'file_obj': [False, True],
        'size': [(48, 32)],
        'dtype': [np.float32, np.uint8, bool]})
    no_color_params = testing.product({
        'format': ['bmp', 'jpeg', 'png'],
        'color': [False],
        'alpha': [None]})
    no_alpha_params = testing.product({
        'format': ['bmp', 'jpeg', 'png'],
        'color': [True],
        'alpha': [None]})
    alpha_params = testing.product({
        # writing alpha image with jpeg encoding didn't work
        'format': ['png'],
        'color': [True],
        'alpha': ['ignore', 'blend_with_white', 'blend_with_black']})
    params = testing.product_dict(
        params,
        no_color_params + no_alpha_params + alpha_params)
    return params 
开发者ID:chainer,项目名称:chainercv,代码行数:24,代码来源:test_read_image.py

示例5: test_first_order

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def test_first_order(self):
        # First order, so its Hessian will contain None
        params, y = self._generate_params_and_first_order_output()

        old_style_funcs = trpo._find_old_style_function([y])
        if old_style_funcs:
            self.skipTest("\
Chainer v{} does not support double backprop of these functions: {}.".format(
                chainer.__version__, old_style_funcs))

        vec = np.random.rand(4).astype(np.float32)
        # Hessian-vector product computation should raise an error due to None
        with self.assertRaises(AssertionError):
            compute_hessian_vector_product(y, params, vec) 
开发者ID:chainer,项目名称:chainerrl,代码行数:16,代码来源:test_trpo.py

示例6: make_array

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def make_array(start, shape, dtype, device):
    size = numpy.product(shape, dtype='i')
    a = numpy.arange(start, start + size)
    a = a.reshape(shape)
    a = a.astype(dtype, copy=False)
    return device.send(a) 
开发者ID:chainer,项目名称:chainer,代码行数:8,代码来源:test_function_node.py

示例7: setUp

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def setUp(self):
        self.path = tempfile.mkdtemp()
        self.files = (self.fmt.format(i*10, j*10) for i, j
                      in itertools.product(range(0, 10), range(0, 10))) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_snapshot.py

示例8: make_array

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def make_array(start, shape, dtype):
    size = numpy.product(shape, dtype='i')
    a = numpy.arange(start, start + size)
    a = a.reshape(shape)
    a = a.astype(dtype, copy=False)
    return a 
开发者ID:chainer,项目名称:chainer,代码行数:8,代码来源:test_function.py

示例9: _crf1d

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def _crf1d(self, cost_data, xs_data, ys_data):
        z = numpy.zeros((self.batches[0],), numpy.float32)
        for b, length in enumerate(self.lengths):
            for ys in itertools.product(range(self.n_label), repeat=length):
                z[b] += numpy.exp(chainer.cuda.to_cpu(self._calc_score(b, ys)))

        score = numpy.zeros((self.batches[0],), numpy.float32)
        for b, length in enumerate(self.lengths):
            ys = [self.ys[i][b] for i in range(length)]
            score[b] = self._calc_score(b, ys)

        loss = -(score - numpy.log(z))
        return numpy.sum(loss) / self.batches[0] 
开发者ID:chainer,项目名称:chainer,代码行数:15,代码来源:test_crf1d.py

示例10: _generate_test_parameter

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def _generate_test_parameter(
        parameter_list, inner_shape, inner_event_shape,
        reinterpreted_batch_ndims):
    shape_pattern = _generate_valid_shape_pattern(
        inner_shape, inner_event_shape, reinterpreted_batch_ndims)
    return [
        dict(dicts[0], **dicts[1])
        for dicts in itertools.product(parameter_list, shape_pattern)
    ] 
开发者ID:chainer,项目名称:chainer,代码行数:11,代码来源:test_independent.py

示例11: inject_backend_tests

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def inject_backend_tests(method_names):
    decorator = backend.inject_backend_tests(
        method_names,
        # CPU tests
        testing.product({
            'use_cuda': [False],
            'use_ideep': ['never', 'always'],
        })
        # GPU tests
        + [{'use_cuda': True}])
    return decorator 
开发者ID:chainer,项目名称:chainer,代码行数:13,代码来源:test_function_lstm.py

示例12: inject_backend_tests

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def inject_backend_tests(method_names):
    decorator = backend.inject_backend_tests(
        method_names,
        # CPU tests
        testing.product({
            'use_cuda': [False],
            'use_ideep': ['never', 'always'],
        }) +
        # GPU tests
        [{'use_cuda': True}])
    return decorator 
开发者ID:chainer,项目名称:chainer,代码行数:13,代码来源:test_function_slstm.py

示例13: xs_iter

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def xs_iter(dims):
    return itertools.product(*[range(d) for d in dims]) 
开发者ID:chainer,项目名称:chainer,代码行数:4,代码来源:test_unpooling_nd.py

示例14: kxs_iter

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def kxs_iter(x, outs, ksize, stride, pad):
    return itertools.product(
        *[range(max(0, -p + s * _x), min(-p + s * _x + k, out))
          for (_x, out, k, s, p) in zip(x, outs, ksize, stride, pad)]) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_unpooling_nd.py

示例15: check_im2col_nd

# 需要导入模块: from chainer import testing [as 别名]
# 或者: from chainer.testing import product [as 别名]
def check_im2col_nd(self, ksize, stride, pad, gpu):
        dims = self.dims
        if gpu:
            img = cuda.to_gpu(self.img)
        else:
            img = self.img

        col = conv_nd.im2col_nd(img, ksize, stride, pad)
        outs = tuple(conv_nd.get_conv_outsize(d, k, s, p)
                     for (d, k, s, p) in zip(dims, ksize, stride, pad))
        expected_shape = (2, 3) + ksize + outs
        self.assertEqual(col.shape, expected_shape)

        col = cuda.to_cpu(col)

        for n in moves.range(2):
            for c in moves.range(3):
                for xs in itertools.product(
                        *[moves.range(out) for out in outs]):
                    for dxs in itertools.product(
                            *[moves.range(k) for k in ksize]):
                        oxs = tuple(x * s - p + dx
                                    for (x, s, p, dx)
                                    in zip(xs, stride, pad, dxs))
                        if all(0 <= ox < d for (ox, d) in zip(oxs, dims)):
                            col_index = (n, c) + dxs + xs
                            img_index = (n, c) + oxs
                            self.assertEqual(
                                col[col_index], self.img[img_index])
                        else:
                            col_index = (n, c) + dxs + xs
                            self.assertEqual(col[col_index], 0) 
开发者ID:chainer,项目名称:chainer,代码行数:34,代码来源:test_conv_nd.py


注:本文中的chainer.testing.product方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。