From 3474a8565f8970416faf90542f88421cfd1b90bd Mon Sep 17 00:00:00 2001 From: RayWang <75263275+RayWang-iat@users.noreply.github.com> Date: Fri, 2 Jun 2023 23:16:38 +0800 Subject: [PATCH 1/3] Update Numpy.Math.cs --- src/TensorFlowNET.Core/NumPy/Numpy.Math.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs b/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs index 0e50cd56..ea85048f 100644 --- a/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs +++ b/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs @@ -28,7 +28,16 @@ namespace Tensorflow.NumPy public static NDArray multiply(NDArray x1, NDArray x2) => new NDArray(tf.multiply(x1, x2)); [AutoNumPy] - public static NDArray maximum(NDArray x1, NDArray x2) => new NDArray(tf.maximum(x1, x2)); + //public static NDArray maximum(NDArray x1, NDArray x2) => new NDArray(tf.maximum(x1, x2)); + public static NDArray maximum(NDArray x1, NDArray x2, int? axis = null) + { + var maxValues = tf.maximum(x1, x2); + if (axis.HasValue) + { + maxValues = tf.reduce_max(maxValues, axis: axis.Value); + } + return new NDArray(maxValues); + } [AutoNumPy] public static NDArray minimum(NDArray x1, NDArray x2) => new NDArray(tf.minimum(x1, x2)); From 94edda54cdfdddda889a1ce544d91e9d3e189481 Mon Sep 17 00:00:00 2001 From: RayWang <75263275+RayWang-iat@users.noreply.github.com> Date: Fri, 2 Jun 2023 23:23:33 +0800 Subject: [PATCH 2/3] Update Math.Test.cs --- test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs b/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs index a0e6fa4e..6e00504b 100644 --- a/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs +++ b/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs @@ -65,5 +65,17 @@ namespace TensorFlowNET.UnitTest.NumPy var y = np.power(x, 3); Assert.AreEqual(y, new[] { 0, 1, 8, 27, 64, 125 }); } + [TestMethod] + public void maximum() + { + var x1 = new NDArray(new[,] { { 1, 2, 3 }, { 4, 5.1, 6 } }); + var x2 = new NDArray(new[,] { { 3, 2, 1 }, { 6, 5.1, 4 } }); + var y = np.maximum(x1,x2); + var y1 = np.maximum(x1, x2, axis: 0); + var y2 = new NDArray(new[,] { { 3, 2, 3 }, { 6, 5.1, 6 } }); + var y3 = new NDArray(new[] { 6, 5.1, 6 }); + Assert.AreEqual(y, y2); + Assert.AreEqual(y1, y3); + } } } From f45b35b4cf43b73207905b350129d55144b17bd6 Mon Sep 17 00:00:00 2001 From: RayWang <75263275+RayWang-iat@users.noreply.github.com> Date: Mon, 5 Jun 2023 11:26:06 +0800 Subject: [PATCH 3/3] Update Math.Test.cs --- test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs b/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs index 6e00504b..32b517e4 100644 --- a/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs +++ b/test/TensorFlowNET.UnitTest/Numpy/Math.Test.cs @@ -66,16 +66,19 @@ namespace TensorFlowNET.UnitTest.NumPy Assert.AreEqual(y, new[] { 0, 1, 8, 27, 64, 125 }); } [TestMethod] - public void maximum() + public void maximum() { var x1 = new NDArray(new[,] { { 1, 2, 3 }, { 4, 5.1, 6 } }); var x2 = new NDArray(new[,] { { 3, 2, 1 }, { 6, 5.1, 4 } }); - var y = np.maximum(x1,x2); + var y0 = np.maximum(x1,x2); var y1 = np.maximum(x1, x2, axis: 0); - var y2 = new NDArray(new[,] { { 3, 2, 3 }, { 6, 5.1, 6 } }); - var y3 = new NDArray(new[] { 6, 5.1, 6 }); - Assert.AreEqual(y, y2); - Assert.AreEqual(y1, y3); + var y2 = np.maximum(x1, x2, axis: 1); + var y3 = new NDArray(new[,] { { 3, 2, 3 }, { 6, 5.1, 6 } }); + var y4 = new NDArray(new[] { 6, 5.1, 6 }); + var y5 = new NDArray(new[] { 3.0, 6 }); + Assert.AreEqual(y0, y3); + Assert.AreEqual(y1, y4); + Assert.AreEqual(y2, y5); } } }