Skip to content

Commit 87eac0c

Browse files
committed
add math.round
1 parent d21182e commit 87eac0c

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ public static Tensor sum(Tensor input, int axis, bool keep_dims = false, string
287287
public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null)
288288
=> math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices);
289289

290+
public static Tensor round(Tensor x, string name = null)
291+
=> gen_math_ops.round(x, name: name);
292+
290293
public static Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null)
291294
=> math_ops.cast(x, dtype, name);
292295

‎src/TensorFlowNET.Core/Operations/gen_math_ops.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,28 @@ public static Tensor range(Tensor start, Tensor limit, Tensor delta, string name
429429
return _op.outputs[0];
430430
}
431431

432+
/// <summary>
433+
/// Rounds the values of a tensor to the nearest integer, element-wise.
434+
/// </summary>
435+
/// <param name="x">
436+
/// </param>
437+
/// <param name="name">
438+
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'Round'.
439+
/// </param>
440+
/// <returns>
441+
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
442+
/// </returns>
443+
/// <remarks>
444+
/// Rounds half to even. Also known as bankers rounding. If you want to round
445+
/// according to the current system rounding mode use std::cint.
446+
/// </remarks>
447+
public static Tensor round(Tensor x, string name = "Round")
448+
{
449+
var op = _op_def_lib._apply_op_helper("Round", name: name, new { x });
450+
451+
return op.output;
452+
}
453+
432454
/// <summary>
433455
/// Computes reciprocal of square root of x element-wise.
434456
/// </summary>

0 commit comments

Comments
 (0)