Beispiel #1
0
def test_mul_scalar(scalar, device, shape, dtype):
    x_np = array_utils.create_dummy_ndarray(numpy, shape, dtype)
    # Implicit casting in NumPy's multiply depends on the 'casting' argument,
    # which is not yet supported (ChainerX always casts).
    # Therefore, we explicitly cast the scalar to the dtype of the ndarray
    # before the multiplication for NumPy.
    expected = x_np * numpy.dtype(dtype).type(scalar)

    x = chainerx.array(x_np)
    chainerx.testing.assert_array_equal_ex(x * scalar, expected)
    chainerx.testing.assert_array_equal_ex(scalar * x, expected)
    chainerx.testing.assert_array_equal_ex(chainerx.multiply(x, scalar),
                                           expected)
    chainerx.testing.assert_array_equal_ex(chainerx.multiply(scalar, x),
                                           expected)
Beispiel #2
0
def test_mul_scalar(scalar, device, shape, dtype):
    x_np = array_utils.create_dummy_ndarray(numpy, shape, dtype)
    # Implicit casting in NumPy's multiply depends on the 'casting' argument,
    # which is not yet supported (ChainerX always casts).
    # Therefore, we explicitly cast the scalar to the dtype of the ndarray
    # before the multiplication for NumPy.
    expected = x_np * numpy.dtype(dtype).type(scalar)

    x = chainerx.array(x_np)
    scalar_chx = chainerx.Scalar(scalar, dtype)
    chainerx.testing.assert_array_equal_ex(x * scalar, expected)
    chainerx.testing.assert_array_equal_ex(x * scalar_chx, expected)
    chainerx.testing.assert_array_equal_ex(scalar * x, expected)
    chainerx.testing.assert_array_equal_ex(scalar_chx * x, expected)
    chainerx.testing.assert_array_equal_ex(
        chainerx.multiply(x, scalar), expected)
    chainerx.testing.assert_array_equal_ex(
        chainerx.multiply(x, scalar_chx), expected)
    chainerx.testing.assert_array_equal_ex(
        chainerx.multiply(scalar, x), expected)
    chainerx.testing.assert_array_equal_ex(
        chainerx.multiply(scalar_chx, x), expected)