Skip to content

Commit 4c66c0b

Browse files
committed
tf.max, tf.min
1 parent 4c78760 commit 4c66c0b

4 files changed

Lines changed: 124 additions & 13 deletions

File tree

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@ public static Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
105105
public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
106106
=> gen_math_ops.greater_equal(x, y, name);
107107

108+
/// <summary>
109+
/// Returns the truth value of (x < y) element-wise.
110+
/// </summary>
111+
/// <typeparam name="Tx"></typeparam>
112+
/// <typeparam name="Ty"></typeparam>
113+
/// <param name="x"></param>
114+
/// <param name="y"></param>
115+
/// <param name="name"></param>
116+
/// <returns></returns>
117+
public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
118+
=> gen_math_ops.less(x, y, name);
119+
120+
/// <summary>
121+
/// Returns the truth value of (x <= y) element-wise.
122+
/// </summary>
123+
/// <typeparam name="Tx"></typeparam>
124+
/// <typeparam name="Ty"></typeparam>
125+
/// <param name="x"></param>
126+
/// <param name="y"></param>
127+
/// <param name="name"></param>
128+
/// <returns></returns>
129+
public static Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
130+
=> gen_math_ops.less_equal(x, y, name);
131+
132+
/// <summary>
133+
/// Computes natural logarithm of (1 + x) element-wise.
134+
/// </summary>
135+
/// <param name="x"></param>
136+
/// <param name="name"></param>
137+
/// <returns></returns>
138+
public static Tensor log1p(Tensor x, string name = null)
139+
=> gen_math_ops.log1p(x, name);
140+
108141
/// <summary>
109142
/// Clips tensor values to a specified min and max.
110143
/// </summary>
@@ -141,6 +174,56 @@ public static Tensor equal(Tensor x, Tensor y, string name = null)
141174
public static Tensor atan2(Tensor y, Tensor x, string name = null)
142175
=> gen_math_ops.atan2(y, x, name);
143176

177+
/// <summary>
178+
/// Computes the maximum of elements across dimensions of a tensor.
179+
/// </summary>
180+
/// <typeparam name="Tx"></typeparam>
181+
/// <typeparam name="Ty"></typeparam>
182+
/// <param name="input"></param>
183+
/// <param name="axis"></param>
184+
/// <param name="keep_dims"></param>
185+
/// <param name="name"></param>
186+
/// <returns></returns>
187+
public static Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
188+
=> gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name);
189+
190+
/// <summary>
191+
/// Computes the minimum of elements across dimensions of a tensor.
192+
/// </summary>
193+
/// <typeparam name="Tx"></typeparam>
194+
/// <typeparam name="Ty"></typeparam>
195+
/// <param name="input"></param>
196+
/// <param name="axis"></param>
197+
/// <param name="keep_dims"></param>
198+
/// <param name="name"></param>
199+
/// <returns></returns>
200+
public static Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
201+
=> gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name);
202+
203+
/// <summary>
204+
/// Returns the max of x and y (i.e. x > y ? x : y) element-wise.
205+
/// </summary>
206+
/// <typeparam name="T1"></typeparam>
207+
/// <typeparam name="T2"></typeparam>
208+
/// <param name="x"></param>
209+
/// <param name="y"></param>
210+
/// <param name="name"></param>
211+
/// <returns></returns>
212+
public static Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
213+
=> gen_math_ops.maximum(x, y, name: name);
214+
215+
/// <summary>
216+
/// Returns the min of x and y (i.e. x < y ? x : y) element-wise.
217+
/// </summary>
218+
/// <typeparam name="T1"></typeparam>
219+
/// <typeparam name="T2"></typeparam>
220+
/// <param name="x"></param>
221+
/// <param name="y"></param>
222+
/// <param name="name"></param>
223+
/// <returns></returns>
224+
public static Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
225+
=> gen_math_ops.minimum(x, y, name: name);
226+
144227
public static Tensor multiply(Tensor x, Tensor y)
145228
=> gen_math_ops.mul(x, y);
146229

src/TensorFlowNET.Core/Operations/gen_array_ops.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ public static Tensor gather_v2(Tensor @params, Tensor indices, int axis, string
2626
return _op.outputs[0];
2727
}
2828

29-
public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
30-
{
31-
var _op = _op_def_lib._apply_op_helper("Less", name: name, args: new { x, y });
32-
33-
return _op.outputs[0];
34-
}
35-
3629
public static Tensor pack(Tensor[] values, int axis = 0, string name = null)
3730
{
3831
var _op = _op_def_lib._apply_op_helper("Pack", name: name, args: new { values, axis });

src/TensorFlowNET.Core/Operations/gen_math_ops.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
135135
return _op.outputs[0];
136136
}
137137

138+
public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
139+
{
140+
var _op = _op_def_lib._apply_op_helper("Less", name: name, args: new { x, y });
141+
142+
return _op.outputs[0];
143+
}
144+
145+
public static Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
146+
{
147+
var _op = _op_def_lib._apply_op_helper("LessEqual", name: name, args: new { x, y });
148+
149+
return _op.outputs[0];
150+
}
151+
152+
public static Tensor log1p(Tensor x, string name = null)
153+
{
154+
var _op = _op_def_lib._apply_op_helper("Log1p", name, args: new { x });
155+
156+
return _op.outputs[0];
157+
}
158+
138159
public static Tensor squared_difference(Tensor x, Tensor y, string name = null)
139160
{
140161
var _op = _op_def_lib._apply_op_helper("SquaredDifference", name, args: new { x, y, name });
@@ -308,6 +329,13 @@ public static Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
308329
return _op.outputs[0];
309330
}
310331

332+
public static Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
333+
{
334+
var _op = _op_def_lib._apply_op_helper("Minimum", name, args: new { x, y });
335+
336+
return _op.outputs[0];
337+
}
338+
311339
public static Tensor _abs(Tensor x, string name = null)
312340
{
313341
var _op = _op_def_lib._apply_op_helper("Abs", name, new { x });
@@ -322,6 +350,13 @@ public static Tensor _max<Tx, Ty>(Tx input, Ty axis, bool keep_dims=false, strin
322350
return _op.outputs[0];
323351
}
324352

353+
public static Tensor _min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
354+
{
355+
var _op = _op_def_lib._apply_op_helper("Min", name, new { input, reduction_indices = axis, keep_dims });
356+
357+
return _op.outputs[0];
358+
}
359+
325360
public static Tensor pow<Tx, Ty>(Tx x, Ty y, string name = null)
326361
{
327362
var _op = _op_def_lib._apply_op_helper("Pow", name, args: new { x, y });

src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public partial class Tensor
2727

2828
public static Tensor operator %(Tensor x, Tensor y) => BinaryOpWrapper("mod", x, y);
2929

30-
public static Tensor operator >(Tensor x, int y) => gen_array_ops.greater(x, y);
31-
public static Tensor operator >(Tensor x, float y) => gen_array_ops.greater(x, y);
32-
public static Tensor operator >(Tensor x, double y) => gen_array_ops.greater(x, y);
33-
public static Tensor operator <(Tensor x, int y) => gen_array_ops.less(x, y);
34-
public static Tensor operator <(Tensor x, float y) => gen_array_ops.less(x, y);
35-
public static Tensor operator <(Tensor x, double y) => gen_array_ops.less(x, y);
30+
public static Tensor operator >(Tensor x, int y) => gen_math_ops.greater(x, y);
31+
public static Tensor operator >(Tensor x, float y) => gen_math_ops.greater(x, y);
32+
public static Tensor operator >(Tensor x, double y) => gen_math_ops.greater(x, y);
33+
public static Tensor operator <(Tensor x, int y) => gen_math_ops.less(x, y);
34+
public static Tensor operator <(Tensor x, float y) => gen_math_ops.less(x, y);
35+
public static Tensor operator <(Tensor x, double y) => gen_math_ops.less(x, y);
3636

3737
private static Tensor BinaryOpWrapper<Tx, Ty>(string name, Tx x, Ty y)
3838
{

0 commit comments

Comments
 (0)