Browse Source

tf.max, tf.min

tags/v0.9
haiping008 6 years ago
parent
commit
4c66c0bd74
4 changed files with 124 additions and 13 deletions
  1. +83
    -0
      src/TensorFlowNET.Core/APIs/tf.math.cs
  2. +0
    -7
      src/TensorFlowNET.Core/Operations/gen_array_ops.cs
  3. +35
    -0
      src/TensorFlowNET.Core/Operations/gen_math_ops.cs
  4. +6
    -6
      src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs

+ 83
- 0
src/TensorFlowNET.Core/APIs/tf.math.cs View File

@@ -105,6 +105,39 @@ namespace Tensorflow
public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.greater_equal(x, y, name);

/// <summary>
/// Returns the truth value of (x < y) element-wise.
/// </summary>
/// <typeparam name="Tx"></typeparam>
/// <typeparam name="Ty"></typeparam>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.less(x, y, name);

/// <summary>
/// Returns the truth value of (x <= y) element-wise.
/// </summary>
/// <typeparam name="Tx"></typeparam>
/// <typeparam name="Ty"></typeparam>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.less_equal(x, y, name);

/// <summary>
/// Computes natural logarithm of (1 + x) element-wise.
/// </summary>
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor log1p(Tensor x, string name = null)
=> gen_math_ops.log1p(x, name);

/// <summary>
/// Clips tensor values to a specified min and max.
/// </summary>
@@ -141,6 +174,56 @@ namespace Tensorflow
public static Tensor atan2(Tensor y, Tensor x, string name = null)
=> gen_math_ops.atan2(y, x, name);

/// <summary>
/// Computes the maximum of elements across dimensions of a tensor.
/// </summary>
/// <typeparam name="Tx"></typeparam>
/// <typeparam name="Ty"></typeparam>
/// <param name="input"></param>
/// <param name="axis"></param>
/// <param name="keep_dims"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
=> gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name);

/// <summary>
/// Computes the minimum of elements across dimensions of a tensor.
/// </summary>
/// <typeparam name="Tx"></typeparam>
/// <typeparam name="Ty"></typeparam>
/// <param name="input"></param>
/// <param name="axis"></param>
/// <param name="keep_dims"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
=> gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name);

/// <summary>
/// Returns the max of x and y (i.e. x > y ? x : y) element-wise.
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
=> gen_math_ops.maximum(x, y, name: name);

/// <summary>
/// Returns the min of x and y (i.e. x < y ? x : y) element-wise.
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor minimum<T1, T2>(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);



+ 0
- 7
src/TensorFlowNET.Core/Operations/gen_array_ops.cs View File

@@ -26,13 +26,6 @@ namespace Tensorflow
return _op.outputs[0];
}

public static Tensor less<Tx, Ty>(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 });


+ 35
- 0
src/TensorFlowNET.Core/Operations/gen_math_ops.cs View File

@@ -135,6 +135,27 @@ namespace Tensorflow
return _op.outputs[0];
}
public static Tensor less<Tx, Ty>(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, Ty>(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, T2>(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, Ty>(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, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Pow", name, args: new { x, y });


+ 6
- 6
src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs View File

@@ -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<Tx, Ty>(string name, Tx x, Ty y)
{


Loading…
Cancel
Save