From f61e260bfe245841d10ae9ffe4f552eedbb6a0a5 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Wed, 18 Sep 2019 07:21:59 -0500 Subject: [PATCH] tf.reduce_any #396 --- src/TensorFlowNET.Core/APIs/tf.math.cs | 14 ++++++++++++++ src/TensorFlowNET.Core/APIs/tf.variable.cs | 3 +++ src/TensorFlowNET.Core/Operations/gen_math_ops.cs | 7 +++++++ src/TensorFlowNET.Core/Operations/math_ops.cs | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index b89ab310..fd051daa 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -389,6 +389,20 @@ namespace Tensorflow public Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range") => math_ops.range(start, limit: limit, delta: delta, dtype: dtype, name: name); + /// + /// Computes the "logical or" of elements across dimensions of a tensor. + /// + /// The boolean tensor to reduce. + /// The dimensions to reduce. + /// If true, retains reduced dimensions with length 1. + /// + /// The reduced tensor. + public Tensor reduce_any(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) + => math_ops.reduce_any(input_tensor, axis: axis, keepdims: keepdims, name: name); + + public Tensor reduce_any(Tensor input_tensor, int axis = 0, bool keepdims = false, string name = null) + => math_ops.reduce_any(input_tensor, axis: new[] { axis }, keepdims: keepdims, name: name); + /// /// Computes the "logical and" of elements across dimensions of a tensor. /// diff --git a/src/TensorFlowNET.Core/APIs/tf.variable.cs b/src/TensorFlowNET.Core/APIs/tf.variable.cs index ef6d65c9..179cedee 100644 --- a/src/TensorFlowNET.Core/APIs/tf.variable.cs +++ b/src/TensorFlowNET.Core/APIs/tf.variable.cs @@ -64,5 +64,8 @@ namespace Tensorflow trainable: trainable, collections: collections); } + + public VariableScope get_variable_scope() + => Tensorflow.variable_scope.get_variable_scope(); } } diff --git a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs index c1257e19..81870e5b 100644 --- a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs @@ -632,6 +632,13 @@ namespace Tensorflow return _op.outputs[0]; } + public static Tensor _any(Tx input, Ty axis, bool keep_dims = false, string name = null) + { + var _op = _op_def_lib._apply_op_helper("Any", name, new { input, reduction_indices = axis, keep_dims }); + + return _op.outputs[0]; + } + public static Tensor _max(Tx input, Ty axis, bool keep_dims=false, string name = null) { var _op = _op_def_lib._apply_op_helper("Max", name, new { input, reduction_indices = axis, keep_dims }); diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index 2f8accd7..94c42ba2 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -361,6 +361,14 @@ namespace Tensorflow }); } + public static Tensor reduce_any(Tensor input_tensor, int[] 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) : + gen_math_ops._any(input_tensor, r, keepdims, name); + return _may_reduce_to_scalar(keepdims, axis, max); + } + public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null) { var r = _ReductionDims(input_tensor, axis);