From 83151d2b36daf336383f9d6549767e8a713b4d08 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Thu, 15 Jul 2021 22:50:04 -0500 Subject: [PATCH] logical_and --- src/TensorFlowNET.Core/APIs/tf.math.cs | 5 +---- src/TensorFlowNET.Core/NumPy/Axis.cs | 3 +++ .../NumPy/NDArray.Operators.cs | 2 ++ src/TensorFlowNET.Core/NumPy/NumPy.Logical.cs | 18 +++++++++++++++++ .../NumPy/NumPy.Sorting.Searching.Counting.cs | 20 +++++++++++++++++++ .../NumPy/NumPy.Statistics.cs | 18 +++++++++++++++++ .../NumPy/Numpy.Manipulation.cs | 3 +++ src/TensorFlowNET.Core/NumPy/Numpy.Math.cs | 16 +++++++++++++-- .../Numpy/Numpy.Creation.cs | 3 +++ .../Operations/gen_math_ops.cs | 7 ++----- src/TensorFlowNET.Core/Operations/math_ops.cs | 17 +++++----------- 11 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 src/TensorFlowNET.Core/NumPy/NumPy.Logical.cs create mode 100644 src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs create mode 100644 src/TensorFlowNET.Core/NumPy/NumPy.Statistics.cs diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index 4ffa8347..042ab952 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -245,10 +245,7 @@ namespace Tensorflow public Tensor log1p(Tensor x, string name = null) => gen_math_ops.log1p(x, name); - public Tensor logical_and(Tensor x, Tensor y, string name = null) - => gen_math_ops.logical_and(x, y, name); - - public Tensor logical_and(bool x, bool y, string name = null) + public Tensor logical_and(T x, T y, string name = null) => gen_math_ops.logical_and(x, y, name); public Tensor logical_not(Tensor x, string name = null) diff --git a/src/TensorFlowNET.Core/NumPy/Axis.cs b/src/TensorFlowNET.Core/NumPy/Axis.cs index 4c7b6488..7f32fef3 100644 --- a/src/TensorFlowNET.Core/NumPy/Axis.cs +++ b/src/TensorFlowNET.Core/NumPy/Axis.cs @@ -30,6 +30,9 @@ namespace Tensorflow public static implicit operator int[]?(Axis axis) => axis?.axis; + public static implicit operator int(Axis axis) + => axis.axis[0]; + public static implicit operator Axis(int axis) => new Axis(axis); diff --git a/src/TensorFlowNET.Core/NumPy/NDArray.Operators.cs b/src/TensorFlowNET.Core/NumPy/NDArray.Operators.cs index 960fae4b..ec009ef0 100644 --- a/src/TensorFlowNET.Core/NumPy/NDArray.Operators.cs +++ b/src/TensorFlowNET.Core/NumPy/NDArray.Operators.cs @@ -12,5 +12,7 @@ namespace Tensorflow.NumPy public static NDArray operator -(NDArray lhs, NDArray rhs) => lhs.Tensor - rhs.Tensor; public static NDArray operator *(NDArray lhs, NDArray rhs) => lhs.Tensor * rhs.Tensor; public static NDArray operator /(NDArray lhs, NDArray rhs) => lhs.Tensor / rhs.Tensor; + public static NDArray operator >(NDArray lhs, NDArray rhs) => lhs.Tensor > rhs.Tensor; + public static NDArray operator <(NDArray lhs, NDArray rhs) => lhs.Tensor < rhs.Tensor; } } diff --git a/src/TensorFlowNET.Core/NumPy/NumPy.Logical.cs b/src/TensorFlowNET.Core/NumPy/NumPy.Logical.cs new file mode 100644 index 00000000..49d7cd53 --- /dev/null +++ b/src/TensorFlowNET.Core/NumPy/NumPy.Logical.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using System.Text; +using static Tensorflow.Binding; + +namespace Tensorflow.NumPy +{ + public partial class np + { + public static NDArray logical_or(NDArray x1, NDArray x2) + => tf.logical_or(x1, x2); + + public static NDArray logical_and(NDArray x1, NDArray x2) + => tf.logical_and(x1, x2); + } +} diff --git a/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs b/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs new file mode 100644 index 00000000..6d5273d0 --- /dev/null +++ b/src/TensorFlowNET.Core/NumPy/NumPy.Sorting.Searching.Counting.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using System.Text; + +namespace Tensorflow.NumPy +{ + public partial class np + { + public static NDArray argmax(NDArray a, Axis axis = null) + => new NDArray(math_ops.argmax(a, axis)); + + public static NDArray argsort(NDArray a, Axis axis = null) + => new NDArray(math_ops.argmax(a, axis ?? -1)); + + public static NDArray unique(NDArray a) + => throw new NotImplementedException(""); + } +} diff --git a/src/TensorFlowNET.Core/NumPy/NumPy.Statistics.cs b/src/TensorFlowNET.Core/NumPy/NumPy.Statistics.cs new file mode 100644 index 00000000..36e65261 --- /dev/null +++ b/src/TensorFlowNET.Core/NumPy/NumPy.Statistics.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Numerics; +using System.Text; +using static Tensorflow.Binding; + +namespace Tensorflow.NumPy +{ + public partial class np + { + public static NDArray amin(NDArray x, int axis = 0) + => tf.arg_min(x, axis); + + public static NDArray amax(NDArray x, int axis = 0) + => tf.arg_max(x, axis); + } +} diff --git a/src/TensorFlowNET.Core/NumPy/Numpy.Manipulation.cs b/src/TensorFlowNET.Core/NumPy/Numpy.Manipulation.cs index 81a5811f..aa972f5a 100644 --- a/src/TensorFlowNET.Core/NumPy/Numpy.Manipulation.cs +++ b/src/TensorFlowNET.Core/NumPy/Numpy.Manipulation.cs @@ -8,6 +8,9 @@ namespace Tensorflow.NumPy { public partial class np { + public static NDArray reshape(NDArray x1, Shape newshape) + => x1.reshape(newshape); + public static NDArray squeeze(NDArray x1, Axis? axis = null) => new NDArray(array_ops.squeeze(x1, axis)); } diff --git a/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs b/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs index d690629d..4aec90cc 100644 --- a/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs +++ b/src/TensorFlowNET.Core/NumPy/Numpy.Math.cs @@ -9,17 +9,29 @@ namespace Tensorflow.NumPy { public partial class np { + public static NDArray exp(NDArray x) + => tf.exp(x); + public static NDArray log(NDArray x) => tf.log(x); + public static NDArray multiply(NDArray x1, NDArray x2) + => tf.multiply(x1, x2); + + public static NDArray maximum(NDArray x1, NDArray x2) + => tf.maximum(x1, x2); + + public static NDArray minimum(NDArray x1, NDArray x2) + => tf.minimum(x1, x2); + public static NDArray prod(NDArray array, Axis? axis = null, Type? dtype = null, bool keepdims = false) => tf.reduce_prod(array, axis: axis); public static NDArray prod(params T[] array) where T : unmanaged => tf.reduce_prod(ops.convert_to_tensor(array)); - public static NDArray multiply(NDArray x1, NDArray x2) - => tf.multiply(x1, x2); + public static NDArray sqrt(NDArray x) + => tf.sqrt(x); public static NDArray sum(NDArray x1, Axis? axis = null) => tf.math.sum(x1, axis); diff --git a/src/TensorFlowNET.Core/Numpy/Numpy.Creation.cs b/src/TensorFlowNET.Core/Numpy/Numpy.Creation.cs index bdb0b9fd..f1006032 100644 --- a/src/TensorFlowNET.Core/Numpy/Numpy.Creation.cs +++ b/src/TensorFlowNET.Core/Numpy/Numpy.Creation.cs @@ -46,6 +46,9 @@ namespace Tensorflow.NumPy public static (NDArray, NDArray) meshgrid(T x, T y, bool copy = true, bool sparse = false) => tf.numpy.meshgrid(new[] { x, y }, copy: copy, sparse: sparse); + public static NDArray ndarray(Shape shape, TF_DataType dtype = TF_DataType.TF_DOUBLE) + => new NDArray(tf.zeros(shape, dtype: dtype)); + public static NDArray ones(Shape shape, TF_DataType dtype = TF_DataType.TF_DOUBLE) => new NDArray(tf.ones(shape, dtype: dtype)); diff --git a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs index 47774b37..fd3241f0 100644 --- a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs @@ -50,7 +50,7 @@ namespace Tensorflow /// /// /// - public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) + public static Tensor arg_max(Tensor input, Axis dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) => tf.Context.ExecuteOp("ArgMax", name, new ExecuteOpArgs(input, dimension) .SetAttributes(new { output_type })); @@ -308,10 +308,7 @@ namespace Tensorflow public static Tensor log1p(Tensor x, string name = null) => tf.Context.ExecuteOp("Log1p", name, new ExecuteOpArgs(x)); - public static Tensor logical_and(Tensor x, Tensor y, string name = null) - => tf.Context.ExecuteOp("LogicalAnd", name, new ExecuteOpArgs(x, y)); - - public static Tensor logical_and(bool x, bool y, string name = null) + public static Tensor logical_and(T x, T y, string name = null) => tf.Context.ExecuteOp("LogicalAnd", name, new ExecuteOpArgs(x, y)); public static Tensor logical_not(Tensor x, string name = null) diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index 4fb481da..2cfc36f9 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -71,7 +71,7 @@ namespace Tensorflow return gen_math_ops.add_n(inputs, name: name); } - public static Tensor argmax(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) + public static Tensor argmax(Tensor input, Axis dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null) => gen_math_ops.arg_max(input, dimension, output_type: output_type, name: name); public static Tensor round(Tensor x, string name = null) @@ -545,7 +545,7 @@ namespace Tensorflow /// dimensions.Must be in the range `[-rank(input_tensor), rank(input_tensor))`. /// /// The reduced tensor. - public static Tensor reduce_logsumexp(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null) + public static Tensor reduce_logsumexp(Tensor input_tensor, Axis axis = null, bool keepdims = false, string name = null) { return tf_with(ops.name_scope(name, "ReduceLogSumExp", new { input_tensor }), scope => { @@ -565,7 +565,7 @@ namespace Tensorflow }); } - public static Tensor reduce_any(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null) + public static Tensor reduce_any(Tensor input_tensor, Axis axis = null, bool keepdims = false, string name = null) { var r = _ReductionDims(input_tensor, axis); var max = (axis != null) ? gen_math_ops._any(input_tensor, axis, keepdims, name) : @@ -573,7 +573,7 @@ namespace Tensorflow return _may_reduce_to_scalar(keepdims, axis, max); } - public static Tensor reduce_max(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null) + public static Tensor reduce_max(Tensor input_tensor, Axis axis = null, bool keepdims = false, string name = null) { var r = _ReductionDims(input_tensor, axis); var max = (axis != null) ? gen_math_ops._max(input_tensor, axis, keepdims, name) : @@ -581,14 +581,7 @@ namespace Tensorflow return _may_reduce_to_scalar(keepdims, axis, max); } - public static Tensor reduce_max(Tensor input_tensor, int axis, bool keepdims = false, string name = null) - { - var r = _ReductionDims(input_tensor, axis); - var max = gen_math_ops._max(input_tensor, r, keepdims, name); - return _may_reduce_to_scalar(keepdims, axis, max); - } - - public static Tensor reduce_min(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null) + public static Tensor reduce_min(Tensor input_tensor, Axis axis = null, bool keepdims = false, string name = null) { var r = _ReductionDims(input_tensor, axis); var min = gen_math_ops._min(input_tensor, r, keepdims, name);