Ejemplo n.º 1
0
def test_array():
    # array's function is very similar to asarray, so we mainly test the
    # `copy` argument.
    test_case = Cases()
    for array in test_case.array_sets:
        arr1 = mnp.asarray(array)
        arr2 = mnp.array(arr1, copy=False)
        arr3 = mnp.array(arr1)
        arr4 = mnp.asarray(array, dtype='int32')
        arr5 = mnp.asarray(arr4, dtype=mnp.int32)
        assert arr1 is arr2
        assert arr1 is not arr3
        assert arr4 is arr5
Ejemplo n.º 2
0
def test_isscalar():
    assert mnp.isscalar(1) == onp.isscalar(1)
    assert mnp.isscalar(2.3) == onp.isscalar(2.3)
    assert mnp.isscalar([4.5]) == onp.isscalar([4.5])
    assert mnp.isscalar(False) == onp.isscalar(False)
    assert mnp.isscalar(mnp.array(True)) == onp.isscalar(onp.array(True))
    assert mnp.isscalar('numpy') == onp.isscalar('numpy')
Ejemplo n.º 3
0
def test_full_like():
    test_case = Cases()
    for mnp_proto, onp_proto in zip(test_case.mnp_prototypes, test_case.onp_prototypes):
        shape = onp.zeros_like(onp_proto).shape
        fill_value = rand_int()
        actual = mnp.full_like(mnp_proto, mnp.array(fill_value)).asnumpy()
        expected = onp.full_like(onp_proto, fill_value)
        match_array(actual, expected)

        for i in range(len(shape) - 1, 0, -1):
            fill_value = rand_int(*shape[i:])
            actual = mnp.full_like(mnp_proto, mnp.array(fill_value)).asnumpy()
            expected = onp.full_like(onp_proto, fill_value)
            match_array(actual, expected)

            fill_value = rand_int(1, *shape[i + 1:])
            actual = mnp.full_like(mnp_proto, mnp.array(fill_value)).asnumpy()
            expected = onp.full_like(onp_proto, fill_value)
            match_array(actual, expected)
Ejemplo n.º 4
0
def test_array():
    # array's function is very similar to asarray, so we mainly test the
    # `copy` argument.
    test_case = Cases()
    for array in test_case.array_sets:
        arr1 = mnp.asarray(array)
        arr2 = mnp.array(arr1, copy=False)
        arr3 = mnp.array(arr1)
        arr4 = mnp.asarray(array, dtype='int32')
        arr5 = mnp.asarray(arr4, dtype=mnp.int32)
        assert arr1 is arr2
        assert arr1 is not arr3
        assert arr4 is arr5

    # Additional tests for nested tensor/numpy_array mixture
    mnp_input = [(mnp.ones(3, ), mnp.ones(3)), [[1, 1, 1], (1, 1, 1)]]
    onp_input = [(onp.ones(3, ), onp.ones(3)), [[1, 1, 1], (1, 1, 1)]]

    actual = onp.array(onp_input)
    expected = mnp.array(mnp_input).asnumpy()
    match_array(actual, expected, error=7)