Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Zero-Dim] fix cases to Support paddle.all/any/min/max/prod/logsumexp/amax/amin #2143

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions framework/api/multithreading_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
"paddlebase": [
"test_fill_diagonal_tensor.py",
"test_multiplex.py",
"test_all.py",
"test_any.py",
"test_max.py",
"test_min.py",
"test_prod.py",
"test_sum.py",
"test_mean.py",
"test_nansum.py",
"test_Tensor_nansum.py",
"test_var.py",
"test_std.py",
"test_Tensor_inner.py",
"test_dot.py",
"test_inner.py",
Expand Down
2 changes: 1 addition & 1 deletion framework/api/nn/rnn_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def numerical_gradients(self):
tmp0, tmp1 = paddle.to_tensor(tmp0), paddle.to_tensor(tmp1)
r1, r2 = self.solve_loss(tmp0), self.solve_loss(tmp1)
g = (r1 - r2) / (2 * self.gap)
gradients.append(g[0])
gradients.append(g.item())
return np.array(gradients).reshape(shape)

def solve_loss(self, inputs):
Expand Down
8 changes: 4 additions & 4 deletions framework/api/paddlebase/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_all0():
default
"""
x = np.random.randint(-4, 4, (10,))
res = np.array([np.all(x)])
res = np.all(x)
obj.base(res=res, x=x)


Expand All @@ -47,7 +47,7 @@ def test_all1():
x: 2d-tensor
"""
x = np.random.randint(-4, 4, (10, 10))
res = np.array([np.all(x)])
res = np.all(x)
obj.base(res=res, x=x)


Expand All @@ -57,7 +57,7 @@ def test_all2():
x: 3d-tensor
"""
x = np.random.randint(-4, 4, (3, 4, 2))
res = np.array([np.all(x)])
res = np.all(x)
obj.base(res=res, x=x)


Expand All @@ -67,7 +67,7 @@ def test_all3():
x: 4d-tensor
"""
x = np.random.randint(-4, 4, (2, 4, 4, 2))
res = np.array([np.all(x)])
res = np.all(x)
obj.base(res=res, x=x)


Expand Down
8 changes: 4 additions & 4 deletions framework/api/paddlebase/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_any0():
default
"""
x = np.random.randint(-4, 4, (10,))
res = np.array([np.any(x)])
res = np.any(x)
obj.base(res=res, x=x)


Expand All @@ -47,7 +47,7 @@ def test_any1():
x: 2d-tensor
"""
x = np.random.randint(-4, 4, (10, 10))
res = np.array([np.any(x)])
res = np.any(x)
obj.base(res=res, x=x)


Expand All @@ -57,7 +57,7 @@ def test_any2():
x: 3d-tensor
"""
x = np.random.randint(-4, 4, (3, 4, 2))
res = np.array([np.any(x)])
res = np.any(x)
obj.base(res=res, x=x)


Expand All @@ -67,7 +67,7 @@ def test_any3():
x: 4d-tensor
"""
x = np.random.randint(-4, 4, (2, 4, 4, 2))
res = np.array([np.any(x)])
res = np.any(x)
obj.base(res=res, x=x)


Expand Down
7 changes: 4 additions & 3 deletions framework/api/paddlebase/test_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_max_base():
max_base
"""
x_data = np.arange(6).reshape(2, 3).astype(np.float32)
res = np.array([5])
res = np.max(x_data)
obj.base(res=res, x=x_data)


Expand All @@ -47,7 +47,7 @@ def test_max_2D_tensor():
max_2D_tensor
"""
x_data = np.arange(6).reshape(2, 3).astype(np.float32)
res = np.array([5])
res = np.max(x_data)
obj.run(res=res, x=x_data)


Expand Down Expand Up @@ -112,5 +112,6 @@ def test_max_1():
special input
"""
x_data = np.array([[-1.00595951, -0.20009832], [-0.35623679, -0.95880121]])
res = np.array([-0.20009832])
res = np.max(x_data)
np.array(-0.20009832)
obj.run(res=res, x=x_data, axis=[-2, 1], keepdim=False)
6 changes: 3 additions & 3 deletions framework/api/paddlebase/test_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_min_base():
min_base
"""
x_data = np.arange(6).reshape(2, 3).astype(np.float32)
res = np.array([0])
res = np.min(x_data)
obj.base(res=res, x=x_data)


Expand All @@ -47,7 +47,7 @@ def test_min_2D_tensor():
min_2D_tensor
"""
x_data = np.arange(6).reshape(2, 3).astype(np.float32)
res = np.array([0])
res = np.min(x_data)
obj.run(res=res, x=x_data)


Expand Down Expand Up @@ -99,7 +99,7 @@ def test_min_1():
special input
"""
x_data = np.array([[-1.00595951, -0.20009832], [-0.35623679, -0.95880121]])
res = np.array([-1.00595951])
res = np.min(x_data)
obj.run(res=res, x=x_data, axis=[-2, 1], keepdim=False)


Expand Down
14 changes: 7 additions & 7 deletions framework/api/paddlebase/test_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_prod_base():
axis=None
"""
x = np.array([[0.8, 0.4], [0.7, 0.9]])
res = [np.prod(x)]
res = np.prod(x)
obj.base(res=res, x=x)


Expand All @@ -56,7 +56,7 @@ def test_prod2():
"""
x = np.array([[0.8, 0.4], [0.7, 0.9]])
axis = 3
obj.exception(mode="c", etype="InvalidArgumentError", x=x, axis=axis)
obj.exception(mode="c", etype="InvalidArgument", x=x, axis=axis)


@pytest.mark.api_base_prod_parameters
Expand All @@ -77,7 +77,7 @@ def test_prod4():
"""
x = np.array([[0.8, 0.4], [0.7, 0.9]])
axis = [0, 1]
res = [0.2016]
res = np.array(0.2016)
obj.run(res=res, x=x, axis=axis)


Expand All @@ -88,7 +88,7 @@ def test_prod5():
"""
x = np.array([[0.8, 0.4], [0.7, 0.9]])
axis = (0, 1)
res = [0.2016]
res = np.array(0.2016)
obj.run(res=res, x=x, axis=axis)


Expand All @@ -98,7 +98,7 @@ def test_prod6():
dtype=float32
"""
x = np.array([[0.8, 0.4], [0.7, 0.9]])
res = [np.prod(x)]
res = np.prod(x)
obj.base(res=res, x=x, dtype="float32")


Expand Down Expand Up @@ -134,7 +134,7 @@ def test_prod8():
dtype=int64
"""
x = np.array([[8, 4], [7, 9]])
res = [np.prod(x)]
res = np.prod(x)
obj1.base(res=res, x=x, dtype="int64")


Expand All @@ -144,7 +144,7 @@ def test_prod9():
input is int32, int64
"""
x = np.array([[3, 5], [6, 2]])
res = [np.prod(x)]
res = np.prod(x)
obj1.run(res=res, x=x)


Expand Down