|
|
|
@ -18,7 +18,10 @@ import mindspore.nn as nn
|
|
|
|
|
from mindspore.common.api import ms_function
|
|
|
|
|
import numpy as np
|
|
|
|
|
import mindspore.context as context
|
|
|
|
|
|
|
|
|
|
context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Net(nn.Cell):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(Net, self).__init__()
|
|
|
|
@ -35,6 +38,7 @@ def test_net_bool():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_int8():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.int8)
|
|
|
|
|
net = Net()
|
|
|
|
@ -42,6 +46,7 @@ def test_net_int8():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_uint8():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.uint8)
|
|
|
|
|
net = Net()
|
|
|
|
@ -49,6 +54,7 @@ def test_net_uint8():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_int16():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.int16)
|
|
|
|
|
net = Net()
|
|
|
|
@ -56,6 +62,7 @@ def test_net_int16():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_uint16():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.uint16)
|
|
|
|
|
net = Net()
|
|
|
|
@ -63,6 +70,7 @@ def test_net_uint16():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_int32():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.int32)
|
|
|
|
|
net = Net()
|
|
|
|
@ -70,6 +78,7 @@ def test_net_int32():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_uint32():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.uint32)
|
|
|
|
|
net = Net()
|
|
|
|
@ -77,6 +86,7 @@ def test_net_uint32():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_int64():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.int64)
|
|
|
|
|
net = Net()
|
|
|
|
@ -84,6 +94,7 @@ def test_net_int64():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_uint64():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.uint64)
|
|
|
|
|
net = Net()
|
|
|
|
@ -91,6 +102,7 @@ def test_net_uint64():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_float16():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.float16)
|
|
|
|
|
net = Net()
|
|
|
|
@ -98,6 +110,7 @@ def test_net_float16():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_float32():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.float32)
|
|
|
|
|
net = Net()
|
|
|
|
@ -105,10 +118,10 @@ def test_net_float32():
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_net_float64():
|
|
|
|
|
x = np.random.randn(1, 16, 1, 1).astype(np.float64)
|
|
|
|
|
net = Net()
|
|
|
|
|
output = net(Tensor(x))
|
|
|
|
|
print(output.asnumpy())
|
|
|
|
|
assert (np.all(output.asnumpy() == np.reshape(x, (4, 4))))
|
|
|
|
|
|
|
|
|
|