|
|
|
@ -21,6 +21,7 @@ import mindspore.nn as nn
|
|
|
|
|
from mindspore import Tensor
|
|
|
|
|
from mindspore.common.api import ms_function
|
|
|
|
|
from mindspore.ops import operations as P
|
|
|
|
|
from mindspore.ops.operations import _inner_ops as inner
|
|
|
|
|
|
|
|
|
|
x0 = np.array([[True, True], [True, False], [False, False]])
|
|
|
|
|
axis0 = 0
|
|
|
|
@ -77,18 +78,51 @@ def test_ReduceAny():
|
|
|
|
|
reduce_any = ReduceAny()
|
|
|
|
|
output = reduce_any()
|
|
|
|
|
|
|
|
|
|
expect0 = np.all(x0, axis=axis0, keepdims=keep_dims0)
|
|
|
|
|
np.allclose(output[0].asnumpy(), expect0)
|
|
|
|
|
expect0 = np.any(x0, axis=axis0, keepdims=keep_dims0)
|
|
|
|
|
assert np.allclose(output[0].asnumpy(), expect0)
|
|
|
|
|
assert output[0].shape == expect0.shape
|
|
|
|
|
|
|
|
|
|
expect1 = np.all(x1, axis=axis1, keepdims=keep_dims1)
|
|
|
|
|
np.allclose(output[1].asnumpy(), expect1)
|
|
|
|
|
expect1 = np.any(x1, axis=axis1, keepdims=keep_dims1)
|
|
|
|
|
assert np.allclose(output[1].asnumpy(), expect1)
|
|
|
|
|
assert output[1].shape == expect1.shape
|
|
|
|
|
|
|
|
|
|
expect2 = np.all(x2, axis=axis2, keepdims=keep_dims2)
|
|
|
|
|
np.allclose(output[2].asnumpy(), expect2)
|
|
|
|
|
expect2 = np.any(x2, axis=axis2, keepdims=keep_dims2)
|
|
|
|
|
assert np.allclose(output[2].asnumpy(), expect2)
|
|
|
|
|
assert output[2].shape == expect2.shape
|
|
|
|
|
|
|
|
|
|
expect3 = np.all(x3, axis=axis3, keepdims=keep_dims3)
|
|
|
|
|
np.allclose(output[3].asnumpy(), expect3)
|
|
|
|
|
expect3 = np.any(x3, axis=axis3, keepdims=keep_dims3)
|
|
|
|
|
assert np.allclose(output[3].asnumpy(), expect3)
|
|
|
|
|
assert output[3].shape == expect3.shape
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReduceAnyDynamic(nn.Cell):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(ReduceAnyDynamic, self).__init__()
|
|
|
|
|
self.reduceany = P.ReduceAny(False)
|
|
|
|
|
self.test_dynamic = inner.GpuConvertToDynamicShape()
|
|
|
|
|
|
|
|
|
|
def construct(self, x, axis):
|
|
|
|
|
x = self.test_dynamic(x)
|
|
|
|
|
return self.reduceany(x, axis)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_reduce_any_dynamic():
|
|
|
|
|
context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
|
|
|
|
|
net = ReduceAnyDynamic()
|
|
|
|
|
|
|
|
|
|
x_1 = np.array([[True, True], [True, False], [False, False]])
|
|
|
|
|
axis_1 = 0
|
|
|
|
|
expect_1 = np.any(x_1, axis=axis_1, keepdims=False)
|
|
|
|
|
|
|
|
|
|
x_2 = np.array([[True, True], [True, True], [True, False], [False, False]])
|
|
|
|
|
axis_2 = 0
|
|
|
|
|
expect_2 = np.any(x_2, axis=axis_2, keepdims=False)
|
|
|
|
|
|
|
|
|
|
output_1 = net(Tensor(x_1), axis_1)
|
|
|
|
|
output_2 = net(Tensor(x_2), axis_2)
|
|
|
|
|
|
|
|
|
|
np.testing.assert_almost_equal(output_1.asnumpy(), expect_1)
|
|
|
|
|
np.testing.assert_almost_equal(output_2.asnumpy(), expect_2)
|
|
|
|
|