From 4c66c0bd741442a2a7a4931cc7f5514f4a08f153 Mon Sep 17 00:00:00 2001 From: haiping008 Date: Wed, 27 Mar 2019 16:44:17 -0500 Subject: [PATCH] tf.max, tf.min --- src/TensorFlowNET.Core/APIs/tf.math.cs | 83 +++++++++++++++++++ .../Operations/gen_array_ops.cs | 7 -- .../Operations/gen_math_ops.cs | 35 ++++++++ .../Tensors/Tensor.Operators.cs | 12 +-- 4 files changed, 124 insertions(+), 13 deletions(-) diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index 111b92a7..24f09056 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -105,6 +105,39 @@ namespace Tensorflow public static Tensor greater_equal(Tx x, Ty y, string name = null) => gen_math_ops.greater_equal(x, y, name); + /// + /// Returns the truth value of (x < y) element-wise. + /// + /// + /// + /// + /// + /// + /// + public static Tensor less(Tx x, Ty y, string name = null) + => gen_math_ops.less(x, y, name); + + /// + /// Returns the truth value of (x <= y) element-wise. + /// + /// + /// + /// + /// + /// + /// + public static Tensor less_equal(Tx x, Ty y, string name = null) + => gen_math_ops.less_equal(x, y, name); + + /// + /// Computes natural logarithm of (1 + x) element-wise. + /// + /// + /// + /// + public static Tensor log1p(Tensor x, string name = null) + => gen_math_ops.log1p(x, name); + /// /// Clips tensor values to a specified min and max. /// @@ -141,6 +174,56 @@ namespace Tensorflow public static Tensor atan2(Tensor y, Tensor x, string name = null) => gen_math_ops.atan2(y, x, name); + /// + /// Computes the maximum of elements across dimensions of a tensor. + /// + /// + /// + /// + /// + /// + /// + /// + public static Tensor max(Tx input, Ty axis, bool keep_dims = false, string name = null) + => gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name); + + /// + /// Computes the minimum of elements across dimensions of a tensor. + /// + /// + /// + /// + /// + /// + /// + /// + public static Tensor min(Tx input, Ty axis, bool keep_dims = false, string name = null) + => gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name); + + /// + /// Returns the max of x and y (i.e. x > y ? x : y) element-wise. + /// + /// + /// + /// + /// + /// + /// + public static Tensor maximum(T1 x, T2 y, string name = null) + => gen_math_ops.maximum(x, y, name: name); + + /// + /// Returns the min of x and y (i.e. x < y ? x : y) element-wise. + /// + /// + /// + /// + /// + /// + /// + public static Tensor minimum(T1 x, T2 y, string name = null) + => gen_math_ops.minimum(x, y, name: name); + public static Tensor multiply(Tensor x, Tensor y) => gen_math_ops.mul(x, y); diff --git a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs index 6ce6f57f..e40cf588 100644 --- a/src/TensorFlowNET.Core/Operations/gen_array_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_array_ops.cs @@ -26,13 +26,6 @@ namespace Tensorflow return _op.outputs[0]; } - public static Tensor less(Tx x, Ty y, string name = null) - { - var _op = _op_def_lib._apply_op_helper("Less", name: name, args: new { x, y }); - - return _op.outputs[0]; - } - public static Tensor pack(Tensor[] values, int axis = 0, string name = null) { var _op = _op_def_lib._apply_op_helper("Pack", name: name, args: new { values, axis }); diff --git a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs index b2a72694..a3f017bf 100644 --- a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs @@ -135,6 +135,27 @@ namespace Tensorflow return _op.outputs[0]; } + public static Tensor less(Tx x, Ty y, string name = null) + { + var _op = _op_def_lib._apply_op_helper("Less", name: name, args: new { x, y }); + + return _op.outputs[0]; + } + + public static Tensor less_equal(Tx x, Ty y, string name = null) + { + var _op = _op_def_lib._apply_op_helper("LessEqual", name: name, args: new { x, y }); + + return _op.outputs[0]; + } + + public static Tensor log1p(Tensor x, string name = null) + { + var _op = _op_def_lib._apply_op_helper("Log1p", name, args: new { x }); + + return _op.outputs[0]; + } + public static Tensor squared_difference(Tensor x, Tensor y, string name = null) { var _op = _op_def_lib._apply_op_helper("SquaredDifference", name, args: new { x, y, name }); @@ -308,6 +329,13 @@ namespace Tensorflow return _op.outputs[0]; } + public static Tensor minimum(T1 x, T2 y, string name = null) + { + var _op = _op_def_lib._apply_op_helper("Minimum", name, args: new { x, y }); + + return _op.outputs[0]; + } + public static Tensor _abs(Tensor x, string name = null) { var _op = _op_def_lib._apply_op_helper("Abs", name, new { x }); @@ -322,6 +350,13 @@ namespace Tensorflow return _op.outputs[0]; } + public static Tensor _min(Tx input, Ty axis, bool keep_dims = false, string name = null) + { + var _op = _op_def_lib._apply_op_helper("Min", name, new { input, reduction_indices = axis, keep_dims }); + + return _op.outputs[0]; + } + public static Tensor pow(Tx x, Ty y, string name = null) { var _op = _op_def_lib._apply_op_helper("Pow", name, args: new { x, y }); diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs index 8d941d21..6dd5c0ff 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs @@ -27,12 +27,12 @@ namespace Tensorflow public static Tensor operator %(Tensor x, Tensor y) => BinaryOpWrapper("mod", x, y); - public static Tensor operator >(Tensor x, int y) => gen_array_ops.greater(x, y); - public static Tensor operator >(Tensor x, float y) => gen_array_ops.greater(x, y); - public static Tensor operator >(Tensor x, double y) => gen_array_ops.greater(x, y); - public static Tensor operator <(Tensor x, int y) => gen_array_ops.less(x, y); - public static Tensor operator <(Tensor x, float y) => gen_array_ops.less(x, y); - public static Tensor operator <(Tensor x, double y) => gen_array_ops.less(x, y); + public static Tensor operator >(Tensor x, int y) => gen_math_ops.greater(x, y); + public static Tensor operator >(Tensor x, float y) => gen_math_ops.greater(x, y); + public static Tensor operator >(Tensor x, double y) => gen_math_ops.greater(x, y); + public static Tensor operator <(Tensor x, int y) => gen_math_ops.less(x, y); + public static Tensor operator <(Tensor x, float y) => gen_math_ops.less(x, y); + public static Tensor operator <(Tensor x, double y) => gen_math_ops.less(x, y); private static Tensor BinaryOpWrapper(string name, Tx x, Ty y) {