Skip to content

Commit f61e260

Browse files
committed
tf.reduce_any SciSharp#396
1 parent f378640 commit f61e260

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/TensorFlowNET.Core/APIs/tf.math.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,20 @@ public static Tensor truediv(Tensor x, Tensor y, string name = null)
389389
public Tensor range(object start, object limit = null, object delta = null, TF_DataType dtype = TF_DataType.DtInvalid, string name = "range")
390390
=> math_ops.range(start, limit: limit, delta: delta, dtype: dtype, name: name);
391391

392+
/// <summary>
393+
/// Computes the "logical or" of elements across dimensions of a tensor.
394+
/// </summary>
395+
/// <param name="input_tensor">The boolean tensor to reduce.</param>
396+
/// <param name="axis">The dimensions to reduce.</param>
397+
/// <param name="keepdims">If true, retains reduced dimensions with length 1.</param>
398+
/// <param name="name"></param>
399+
/// <returns>The reduced tensor.</returns>
400+
public Tensor reduce_any(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
401+
=> math_ops.reduce_any(input_tensor, axis: axis, keepdims: keepdims, name: name);
402+
403+
public Tensor reduce_any(Tensor input_tensor, int axis = 0, bool keepdims = false, string name = null)
404+
=> math_ops.reduce_any(input_tensor, axis: new[] { axis }, keepdims: keepdims, name: name);
405+
392406
/// <summary>
393407
/// Computes the "logical and" of elements across dimensions of a tensor.
394408
/// </summary>

src/TensorFlowNET.Core/APIs/tf.variable.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ public RefVariable get_variable(string name,
6464
trainable: trainable,
6565
collections: collections);
6666
}
67+
68+
public VariableScope get_variable_scope()
69+
=> Tensorflow.variable_scope.get_variable_scope();
6770
}
6871
}

src/TensorFlowNET.Core/Operations/gen_math_ops.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,13 @@ public static Tensor _abs(Tensor x, string name = null)
632632
return _op.outputs[0];
633633
}
634634

635+
public static Tensor _any<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
636+
{
637+
var _op = _op_def_lib._apply_op_helper("Any", name, new { input, reduction_indices = axis, keep_dims });
638+
639+
return _op.outputs[0];
640+
}
641+
635642
public static Tensor _max<Tx, Ty>(Tx input, Ty axis, bool keep_dims=false, string name = null)
636643
{
637644
var _op = _op_def_lib._apply_op_helper("Max", name, new { input, reduction_indices = axis, keep_dims });

src/TensorFlowNET.Core/Operations/math_ops.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ public static Tensor reduce_logsumexp(Tensor input_tensor, int[] axis = null, bo
361361
});
362362
}
363363

364+
public static Tensor reduce_any(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
365+
{
366+
var r = _ReductionDims(input_tensor, axis);
367+
var max = (axis != null) ? gen_math_ops._any(input_tensor, axis, keepdims, name) :
368+
gen_math_ops._any(input_tensor, r, keepdims, name);
369+
return _may_reduce_to_scalar(keepdims, axis, max);
370+
}
371+
364372
public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
365373
{
366374
var r = _ReductionDims(input_tensor, axis);

0 commit comments

Comments
 (0)