Beispiel #1
0
def _check_array(
        array, expected_dtype, expected_shape, expected_data_list=None,
        device=None):
    expected_dtype = chainerx.dtype(expected_dtype)

    assert isinstance(array.dtype, chainerx.dtype)
    assert isinstance(array.shape, tuple)
    assert array.dtype == expected_dtype
    assert array.shape == expected_shape
    assert array.itemsize == expected_dtype.itemsize
    assert array.size == array_utils.total_size(expected_shape)
    assert array.nbytes == expected_dtype.itemsize * \
        array_utils.total_size(expected_shape)
    if expected_data_list is not None:
        assert array._debug_flat_data == expected_data_list

    assert array.is_contiguous

    array_utils.check_device(array, device)
Beispiel #2
0
def _check_array(
        array, expected_dtype, expected_shape, expected_data_list=None,
        device=None):
    expected_dtype = chainerx.dtype(expected_dtype)

    assert isinstance(array.dtype, chainerx.dtype)
    assert isinstance(array.shape, tuple)
    assert array.dtype == expected_dtype
    assert array.shape == expected_shape
    assert array.itemsize == expected_dtype.itemsize
    assert array.size == array_utils.total_size(expected_shape)
    assert array.nbytes == expected_dtype.itemsize * \
        array_utils.total_size(expected_shape)
    if expected_data_list is not None:
        assert array._debug_flat_data == expected_data_list

    assert array.is_contiguous

    array_utils.check_device(array, device)
Beispiel #3
0
def _make_inputs(shapes, dtypes):
    # Generates input ndarrays.
    assert isinstance(shapes, (list, tuple))
    assert isinstance(dtypes, (list, tuple))
    assert len(shapes) == len(dtypes)

    inputs = []
    for i, (shape, dtype) in enumerate(zip(shapes, dtypes)):
        size = array_utils.total_size(shape)
        a = numpy.arange(i * 100, i * 100 + size)
        a = a.reshape(shape)
        a = a.astype(dtype)
        inputs.append(a)

    assert len(inputs) > 0
    return tuple(inputs)
Beispiel #4
0
def _make_inputs(shapes, dtypes):
    # Generates input ndarrays.
    assert isinstance(shapes, (list, tuple))
    assert isinstance(dtypes, (list, tuple))
    assert len(shapes) == len(dtypes)

    inputs = []
    for i, (shape, dtype) in enumerate(zip(shapes, dtypes)):
        size = array_utils.total_size(shape)
        a = numpy.arange(i * 100, i * 100 + size)
        a = a.reshape(shape)
        a = a.astype(dtype)
        inputs.append(a)

    assert len(inputs) > 0
    return tuple(inputs)
Beispiel #5
0
def test_diagflat_invalid_ndim(xp, k, shape, device):
    v = xp.arange(array_utils.total_size(shape)).reshape(shape)
    return xp.diagflat(v, k)
Beispiel #6
0
def test_diag(xp, k, shape, transpose, device):
    v = xp.arange(array_utils.total_size(shape)).reshape(shape)
    if transpose:  # Test non-contiguous inputs for multi-dimensional shapes.
        v = v.T
    return xp.diag(v, k)
Beispiel #7
0
def test_diagflat_invalid_ndim(xp, k, shape, device):
    v = xp.arange(array_utils.total_size(shape), dtype='int32').reshape(shape)
    return xp.diagflat(v, k)
Beispiel #8
0
def test_diag(xp, k, shape, transpose, device):
    v = xp.arange(array_utils.total_size(shape), dtype='int32').reshape(shape)
    if transpose:  # Test non-contiguous inputs for multi-dimensional shapes.
        v = v.T
    return xp.diag(v, k)
Beispiel #9
0
def test_total_size(expected, shape):
    assert expected == array_utils.total_size(shape)
Beispiel #10
0
def test_diagflat(xp, k, shape, device):
    v = xp.arange(array_utils.total_size(shape), dtype='int32').reshape(shape)
    return xp.diagflat(v, k)
def test_diagflat(xp, k, shape, device):
    v = xp.arange(array_utils.total_size(shape)).reshape(shape)
    return xp.diagflat(v, k)
def test_diag_invalid_ndim(xp, k, shape, device):
    v = xp.arange(array_utils.total_size(shape)).reshape(shape)
    return xp.diag(v, k)
Beispiel #13
0
def test_total_size(expected, shape):
    assert expected == array_utils.total_size(shape)