/third_party/mindspore/tests/ut/python/ops/ |
D | test_math_ops_check.py | 17 import numpy as np namespace 34 …self.inputdata = Parameter(Tensor(np.zeros([1]).astype(np.bool_), mstype.bool_), name="assign_add1… 45 …self.inputdata = Parameter(Tensor(np.zeros([1]).astype(np.bool_), mstype.bool_), name="assign_sub1… 85 …'desc_inputs': [Tensor(np.ones([3, 5]).astype(np.float32)), Tensor(np.ones([3, 4]).astype(np.float… 91 'desc_inputs': [Tensor(np.ones([1]).astype(np.bool_), mstype.bool_)], 97 'desc_inputs': [Tensor(np.ones([1]).astype(np.bool_), mstype.bool_)], 104 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))], 110 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))], 117 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))], 123 'desc_inputs': [Tensor(np.ones([2, 3, 5]).astype(np.float32))], [all …]
|
D | test_nn_ops_check.py | 16 import numpy as np namespace 67 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))], 72 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))], 83 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.float32))], 94 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.bool_))], 105 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))], 116 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))], 127 'desc_inputs': [Tensor(np.ones([3, 4]).astype(np.int32))], 144 …'desc_inputs': [Tensor(np.ones([5, 3]).astype(np.float32)), Tensor(np.ones([5, 3]).astype(np.float… 145 Tensor(np.ones([5, 3]).astype(np.float32)), None, None], [all …]
|
D | test_ops.py | 19 import numpy as np namespace 92 … self.input_x = Parameter(Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32))) 416 def __init__(self, ref_shape, dtype=np.float32, use_locking=False): 419 self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)), name="ref") 429 def __init__(self, dtype=np.float32, use_locking=False): 432 … self.ref = Parameter(Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype)), name="ref") 442 def __init__(self, dtype=np.float32, use_locking=False): 445 … self.ref = Parameter(Tensor(np.array([[-1.0, 2.0, 3.0], [-4.0, 1.0, 6.0]], dtype)), name="ref") 455 def __init__(self, ref_shape, dtype=np.float32, use_locking=False): 458 self.ref = Parameter(Tensor(np.ones(ref_shape, dtype)), name="ref") [all …]
|
/third_party/mindspore/tests/st/ops/cpu/ |
D | test_cast_op.py | 16 import numpy as np namespace 41 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.bool))) 42 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.float16))) 43 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.float32))) 44 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.float64))) 45 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.int8))) 46 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.int16))) 47 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.int32))) 48 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.int64))) 49 tensor_to_cast.append(Tensor(np.random.uniform(-2, 2, (3, 2)).astype(np.uint8))) [all …]
|
D | test_resize_bilinear_op.py | 15 import numpy as np namespace 33 def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16): 34 input_tensor = Tensor(np.array( 40 expected_output = Tensor(np.array([[[[0.1, 0.1333, 0.1666, 0.2, 0.2333, 0.2666, 0.3, 0.3, 0.3], 49 ).astype(np.float16)) 50 error = np.ones(shape=[9, 9]) * 1.0e-6 52 assert np.all(abs(diff) < error) 57 expected_output = Tensor(np.array([[[[0.1]]]]).astype(np.float16)) 58 error = np.ones(shape=[1, 1]) * 1.0e-6 60 assert np.all(abs(diff) < error) [all …]
|
D | test_shift_op.py | 15 import numpy as np namespace 65 def numpy_shift(array: np.ndarray, periods: int, axis: int, fill_value=np.nan) -> np.ndarray: 86 result = np.empty_like(array) 93 def compare(arr: np.ndarray, periods: int, axis: int, fill_value=np.nan): 102 assert np.allclose(numpy_result, mindspore_result, equal_nan=True) 109 … [(np.float32, 0.0), (np.float32, 5.3), (np.float32, -5.5), (np.float32, np.nan), 110 … (np.float64, 0.0), (np.float64, 5.3), (np.float64, -5.5), (np.float64, np.nan), 111 (np.int32, 0), (np.int32, 1), (np.int32, 5), (np.int32, -4), 112 (np.int64, 0), (np.int64, 1), (np.int64, 5), (np.int64, -4), 113 (np.bool_, True), (np.bool_, False)]) [all …]
|
D | test_arithmetic_op.py | 15 import numpy as np namespace 76 x = np.random.rand(2, 3, 4, 4).astype(np.float32) 77 y = np.random.rand(4, 1).astype(np.float32) 81 assert np.all(output.asnumpy() == expect_output) 88 prop = 1 if np.random.random() < 0.5 else -1 89 x0_np = np.random.randint(1, 100, (2, 3, 4, 4)).astype(np.float32) * prop 90 y0_np = np.random.randint(1, 100, (2, 3, 4, 4)).astype(np.float32) * prop 91 x1_np = np.random.randint(1, 100, (2, 3, 4, 4)).astype(np.float32) * prop 92 y1_np = np.random.randint(1, 100, (2, 1, 4, 4)).astype(np.float32) * prop 93 x2_np = np.random.randint(1, 100, (2, 1, 1, 4)).astype(np.float16) * prop [all …]
|
D | test_argminwithvalue_op.py | 16 import numpy as np namespace 40 x = np.array([[1., 20., 5.], 43 [-0.5, 25, 100]]).astype(np.float32) 47 expect0 = np.array([3, 1, 0]).astype(np.int32) 48 expect1 = np.array([-0.5, 8., 5.]).astype(np.float32) 49 error = np.ones(shape=expect1.shape) * 1.0e-6 50 assert np.all(output0.asnumpy() == expect0) 51 assert np.all(np.abs(output1.asnumpy() - expect1) < error) 56 expect0 = np.array([[3, 1, 0]]).astype(np.int32) 57 expect1 = np.array([[-0.5, 8., 5.]]).astype(np.float32) [all …]
|
D | test_arithmetic_self_op.py | 15 import numpy as np namespace 84 x = np.array([1, 2, 3]).astype(np.int16) 87 expect_output = np.array([1, 4, 9]).astype(np.int16) 89 assert np.all(output.asnumpy() == expect_output) 91 x = np.array([1, 2, 3]).astype(np.int32) 94 expect_output = np.array([1, 4, 9]).astype(np.int32) 96 assert np.all(output.asnumpy() == expect_output) 98 x = np.array([1, 2, 3]).astype(np.int64) 101 expect_output = np.array([1, 4, 9]).astype(np.int64) 103 assert np.all(output.asnumpy() == expect_output) [all …]
|
D | test_scatter_arithmetic_op.py | 16 import numpy as np namespace 55 inputx = Tensor(np.zeros((2, 3)).astype(np.float32)) 56 indices = Tensor(np.array([[0, 1], [0, 1]]).astype(np.int32)) 57 updates = Tensor(np.arange(12).reshape((2, 2, 3)).astype(np.float32)) 59 expected = np.array([[6., 8., 10.], 61 np.testing.assert_array_almost_equal(output.asnumpy(), expected) 68 inputx = Tensor(np.zeros((2, 3)).astype(np.float32)) 69 indices = Tensor(np.array([[0, 1], [0, 1]]).astype(np.int32)) 70 updates = Tensor(np.arange(12).reshape((2, 2, 3)).astype(np.float32)) 74 expected = np.array([[6., 8., 10.], [all …]
|
/third_party/mindspore/tests/st/ops/gpu/ |
D | test_fake_quant_perchannel.py | 16 import numpy as np namespace 44 x = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 45 min_val = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 46 max_val = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 47 expect = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 52 error = np.ones(shape=expect.shape) * 1.0e-5 56 assert np.all(np.abs(diff) < error) 65 x = np.array([-0.1, 0.0, 63.75, 63.8]).astype(np.float32) 66 min_val = np.array([-0.1, -0.1, -0.1, -0.1]).astype(np.float32) 67 max_val = np.array([63.65, 63.65, 63.65, 63.65]).astype(np.float32) [all …]
|
D | test_fake_quant_perlayer.py | 16 import numpy as np namespace 52 x = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).reshape(2, 3).astype(np.float32) 53 min_val = np.array([0]).reshape(1).astype(np.float32) 54 max_val = np.array([0]).reshape(1).astype(np.float32) 55 expect = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).astype(np.float32) 60 error = np.ones(shape=expect.shape) * 1.0e-5 64 assert np.all(np.abs(diff) < error) 74 x = np.array([-10.1, -10.0, -9.9, -9.75, 53.75, 53.8]).reshape(2, 3).astype(np.float32) 75 min_val = np.array([-10.0]).reshape(1).astype(np.float32) 76 max_val = np.array([53.75]).reshape(1).astype(np.float32) [all …]
|
D | test_scatter_func_op.py | 16 import numpy as np namespace 108 inputx = Tensor(np.zeros((2, 3)).astype(np.float32)) 109 indices = Tensor(np.array([[0, 1], [0, 1]]).astype(np.int32)) 110 updates = Tensor(np.arange(12).reshape((2, 2, 3)).astype(np.float32)) 114 expected = np.array([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]) 115 np.testing.assert_array_almost_equal(output.asnumpy(), expected) 119 expected = np.array([[6.0, 8.0, 10.0], [12.0, 14.0, 16.0]]) 120 np.testing.assert_array_almost_equal(output.asnumpy(), expected) 124 expected = np.array([[-6.0, -8.0, -10.0], [-12.0, -14.0, -16.0]]) 125 np.testing.assert_array_almost_equal(output.asnumpy(), expected) [all …]
|
D | test_resize_bilinear_op.py | 15 import numpy as np namespace 37 def test_resize_nn_grayscale_integer_ratio_half(datatype=np.float16): 38 input_tensor = Tensor(np.array( 44 expected_output = Tensor(np.array([[[[0.1, 0.1333, 0.1666, 0.2, 0.2333, 0.2666, 0.3, 0.3, 0.3], 53 0.8994, 0.8994, 0.8994]]]]).astype(np.float16)) 54 error = np.ones(shape=[9, 9]) * 1.0e-6 56 assert np.all(abs(diff) < error) 61 expected_output = Tensor(np.array([[[[0.1]]]]).astype(np.float16)) 62 error = np.ones(shape=[1, 1]) * 1.0e-6 64 assert np.all(abs(diff) < error) [all …]
|
D | test_fake_quant_perchannel_grad.py | 16 import numpy as np namespace 41 dout = np.random.uniform(-1, 1, size=[4]).astype('float32') 42 x = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 43 min_val = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 44 max_val = np.array([0.0, 0.0, 0.0, 0.0]).astype(np.float32) 50 error = np.ones(shape=expect.shape) * 1.0e-5 55 assert np.all(np.abs(diff) < error) 63 dout = np.random.uniform(-1, 1, size=[4]).astype('float32') 64 x = np.array([-0.1, 0.0, 63.75, 63.8]).astype(np.float32) 65 min_val = np.array([-0.1, -0.1, -0.1, -0.1]).astype(np.float32) [all …]
|
D | test_nll_loss.py | 16 import numpy as np namespace 51 np.array([[0.53, 0.74, -2.12], [1.29, -0.34, -1.13]]).astype(nptype_input)) 53 target = Tensor(np.array([0, 1]).astype(np.int32)) 55 weight = Tensor(np.array([0.45, -0.32, 1.21]).astype(nptype_weight)) 62 expected_tot_weight = np.array(0.129999995) 65 expected_loss = np.array([-0.238499984, -0.108800001]) 67 expected_loss = np.array(-2.67153859) 69 expected_loss = np.array(-0.347299993) 71 if nptype_input == np.float32 and nptype_weight == np.float32: 73 elif nptype_input == np.float16 or nptype_weight == np.float16: [all …]
|
D | test_layer_norm_grad_grad_op.py | 16 import numpy as np namespace 25 np.random.seed(0) 46 mean = np.mean(x, axis=tuple(norm_axis), keepdims=True) 47 var = np.var(x, axis=tuple(norm_axis), keepdims=True) 50 …dg = np.sum(dy * np.power(var + epsilon, -0.5) * (x - mean), axis=tuple(param_axis), keepdims=True) 51 db = np.sum(dy, axis=tuple(param_axis), keepdims=True) 53 …sum1 = np.sum((-0.5) * dy * gamma * (x - mean) * np.power(var + epsilon, -1.5), axis=tuple(norm_ax… 55 sum2 = np.sum(dy * gamma, axis=tuple(norm_axis), keepdims=True) 56 sum3 = np.sum(-2.0 * (x - mean), axis=tuple(norm_axis), keepdims=True) 58 dx1 = dy * gamma * np.power(var + epsilon, -0.5) [all …]
|
D | test_lstm_op.py | 16 import numpy as np namespace 41 …input_np = np.array([[[0.6755, -1.6607, 0.1367, -0.9209, -1.7088, 0.3953, 2.7120, 0.1103, 0.1504, … 55 -0.4313]]]).astype(np.float32) 60 … Tensor(np.ones((num_layers * num_directions, batch_size, hidden_size)).astype(np.float32)), 64 … Tensor(np.ones((num_layers * num_directions, batch_size, hidden_size)).astype(np.float32)), 67 wih = np.array([[3.4021e-01, -4.6622e-01, 4.5117e-01, 2.3627e-01, 3.7844e-01, 82 … -6.1343e-01, -5.8236e-02, -3.7682e-01, 4.8338e-01, -2.1551e-01]]).astype(np.float32).reshape( 85 whh = np.array([[-0.4820, -0.2350], 92 [0.1831, 0.0850]]).astype(np.float32).reshape([1, -1]) 94 …bih = np.array([-0.2862, 0.0034, 0.2059, -0.6544, 0.3244, -0.2472, 0.0852, -0.3050]).astype(np.flo… [all …]
|
/third_party/mindspore/tests/syntax/simple_expression/ |
D | test_assignment_ops.py | 16 import numpy as np namespace 39 x = Tensor(np.ones([3, 3]).astype(np.bool_)) 40 y = Tensor(np.zeros([3, 3]).astype(np.bool_)) 44 output_expect = np.ones([3, 3]).astype(np.bool_) 46 assert np.all(output == output_expect) 50 x = Tensor(np.ones([3, 3]).astype(np.int8)) 51 y = Tensor(np.zeros([3, 3]).astype(np.int8)) 55 output_expect = np.ones([3, 3]).astype(np.int8) 57 assert np.all(output == output_expect) 61 x = Tensor(np.ones([3, 3]).astype(np.uint8)) [all …]
|
D | test_math_ops.py | 16 import numpy as np namespace 47 input_x = Tensor(np.ones(shape=[3])).astype(np.int8) 48 input_y = Tensor(np.zeros(shape=[3])).astype(np.int8) 52 expect = np.ones(shape=[3]) 53 assert np.all(result1.asnumpy() == expect) 54 assert np.all(result2.asnumpy() == expect) 58 input_x = Tensor(np.ones(shape=[3])).astype(np.int16) 59 input_y = Tensor(np.zeros(shape=[3])).astype(np.int16) 63 expect = np.ones(shape=[3]) 64 assert np.all(result1.asnumpy() == expect) [all …]
|
/third_party/mindspore/tests/ut/python/mindrecord/ |
D | test_mindrecord_exception.py | 19 import numpy as np namespace 472 … = [{"filename": "001.jpg", "label": 43, "score": 0.8, "mask": np.array([3, 6, 9], dtype=np.int64), 473 "segments": np.array([[5.0, 1.6], [65.2, 8.3]], dtype=np.float32), 475 … {"filename": "002.jpg", "label": 91, "score": 5.4, "mask": np.array([1, 4, 7], dtype=np.int64), 476 "segments": np.array([[5.1, 9.1], [2.0, 65.4]], dtype=np.float32), 478 … {"filename": "003.jpg", "label": 61, "score": 6.4, "mask": np.array([7, 6, 3], dtype=np.int64), 479 "segments": np.array([[0.0, 5.6], [3.0, 16.3]], dtype=np.float32), 481 … {"filename": "004.jpg", "label": 29, "score": 8.1, "mask": np.array([2, 8, 0], dtype=np.int64), 482 "segments": np.array([[5.9, 7.2], [4.0, 89.0]], dtype=np.float32), 484 … {"filename": "005.jpg", "label": 78, "score": 7.7, "mask": np.array([3, 1, 2], dtype=np.int64), [all …]
|
/third_party/mindspore/tests/st/gradient/ |
D | test_jvp_graph.py | 17 import numpy as np namespace 51 x = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32)) 52 v = Tensor(np.array([[1, 1], [1, 1]]).astype(np.float32)) 54 expect_primal = Tensor(np.array([[1, 8], [27, 64]]).astype(np.float32)) 55 expect_grad = Tensor(np.array([[3, 12], [27, 48]]).astype(np.float32)) 57 assert np.allclose(primal.asnumpy(), expect_primal.asnumpy()) 58 assert np.allclose(grad.asnumpy(), expect_grad.asnumpy()) 65 x = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32)) 66 v = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32)) 68 expect_primal = Tensor(np.array([[1, 8], [27, 64]]).astype(np.float32)) [all …]
|
D | test_jvp_pynative.py | 17 import numpy as np namespace 50 x = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32)) 51 v = Tensor(np.array([[1, 1], [1, 1]]).astype(np.float32)) 53 expect_primal = Tensor(np.array([[1, 8], [27, 64]]).astype(np.float32)) 54 expect_grad = Tensor(np.array([[3, 12], [27, 48]]).astype(np.float32)) 56 assert np.allclose(primal.asnumpy(), expect_primal.asnumpy()) 57 assert np.allclose(grad.asnumpy(), expect_grad.asnumpy()) 64 x = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32)) 65 v = Tensor(np.array([[1, 2], [3, 4]]).astype(np.float32)) 67 expect_primal = Tensor(np.array([[1, 8], [27, 64]]).astype(np.float32)) [all …]
|
/third_party/mindspore/tests/st/ops/ascend/test_aicpu_ops/ |
D | test_meshgrid.py | 15 import numpy as np namespace 36 x = np.random.randn(4,) > 0 37 y = np.random.randn(3,) > 0 38 z = np.random.randn(6,) > 0 47 np_output = np.meshgrid(x, y, z, indexing=indexing) 48 assert np.array_equal(output[0].asnumpy(), np_output[0]) 49 assert np.array_equal(output[1].asnumpy(), np_output[1]) 50 assert np.array_equal(output[2].asnumpy(), np_output[2]) 54 x = np.random.randn(4,).astype(np.int8) 55 y = np.random.randn(3,).astype(np.int8) [all …]
|
/third_party/mindspore/tests/ut/python/pynative_mode/vm/ |
D | test_vm.py | 16 import numpy as np namespace 23 input_data = np.array([[[[-4., -3., 1., 9.], 26 [-2., -1., -2., -15.]]]]).astype(np.float32) 37 input_data = np.array([[[[1., 2, 3, 4], 40 [13, 14, 15, 16]]]]).astype(np.float32) 50 input_data = np.random.randint(0, 255, [1, 3, 224, 224]) 59 x = np.array([[[ 65 [2, 4, 5, 2, 3, 9]]]]).astype(np.float32) 66 weight = np.array([[[[1, 0, -1], [1, 0, -1], [1, 0, -1]]]]).astype(np.float32) 68 expect_out = np.array([[[ [all …]
|