def test_asfarray(): test_case = Cases() for array in test_case.array_sets: # Check for dtype matching actual = onp.asfarray(array) expected = mnp.asfarray(array).asnumpy() # Since we set float32/int32 as the default dtype in mindspore, we need # to make a conversion between numpy.asarray and mindspore.numpy.asarray if actual.dtype is onp.dtype('float64'): assert expected.dtype == onp.dtype('float32') else: assert actual.dtype == expected.dtype match_array(actual, expected, error=7) for i in range(len(test_case.onp_dtypes)): actual = onp.asfarray(array, test_case.onp_dtypes[i]) expected = mnp.asfarray(array, test_case.mnp_dtypes[i]).asnumpy() match_array(actual, expected, error=7) # 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.asfarray(onp_input) expected = mnp.asfarray(mnp_input).asnumpy() match_array(actual, expected, error=7)
def test_asfarray(): test_case = Cases() for array in test_case.array_sets: # Check for dtype matching actual = onp.asfarray(array) expected = mnp.asfarray(array).asnumpy() # Since we set float32/int32 as the default dtype in mindspore, we need # to make a conversion between numpy.asarray and mindspore.numpy.asarray if actual.dtype is onp.dtype('float64'): assert expected.dtype == onp.dtype('float32') else: assert actual.dtype == expected.dtype match_array(actual, expected, error=7) for i in range(len(test_case.onp_dtypes)): actual = onp.asfarray(array, test_case.onp_dtypes[i]) expected = mnp.asfarray(array, test_case.mnp_dtypes[i]).asnumpy() match_array(actual, expected, error=7)