Repository navigation
Expand file tree
/
Copy pathgen_math_ops.cs
More file actions
543 lines (434 loc) · 20.5 KB
/
Copy pathgen_math_ops.cs
File metadata and controls
543 lines (434 loc) · 20.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Tensorflow
{
public static class gen_math_ops
{
public static OpDefLibrary _op_def_lib = new OpDefLibrary();
public static Tensor _all(Tensor input, Tensor axis, bool keep_dims = false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("All", name, args: new { input, reduction_indices = axis, keep_dims = keep_dims });
return _op.outputs[0];
}
/// <summary>
/// Returns the index with the largest value across dimensions of a tensor.
/// </summary>
/// <param name="input"></param>
/// <param name="dimension"></param>
/// <param name="output_type"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
=> _op_def_lib._apply_op_helper("ArgMax", name, args: new { input, dimension, output_type }).outputs[0];
/// <summary>
/// Returns the index with the smallest value across dimensions of a tensor.
/// </summary>
/// <param name="input"></param>
/// <param name="dimension"></param>
/// <param name="output_type"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor arg_min(Tensor input, int dimension, TF_DataType output_type= TF_DataType.TF_INT64, string name= null)
=>_op_def_lib._apply_op_helper("ArgMin", name, args: new { input, dimension, output_type }).outputs[0];
/// <summary>
/// Returns 0 if the denominator is zero.
/// </summary>
/// <param name="x">
/// </param>
/// <param name="y">
/// </param>
/// <param name="name">
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'DivNoNan'.
/// </param>
/// <returns>
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
/// </returns>
/// <remarks>
///
/// *NOTE*: <c>DivNoNan</c> supports broadcasting. More about broadcasting
/// [here](http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
/// </remarks>
public static Tensor div_no_nan(Tensor x, Tensor y, string name = null)
{
var op = _op_def_lib._apply_op_helper("DivNoNan", name: name, args: new { x, y });
return op.output;
}
/// <summary>
/// Computes the mean of elements across dimensions of a tensor.
/// Reduces `input` along the dimensions given in `axis`. Unless
/// `keep_dims` is true, the rank of the tensor is reduced by 1 for each entry in
/// `axis`. If `keep_dims` is true, the reduced dimensions are retained with length 1.
/// </summary>
/// <param name="input">A `Tensor`. Must be one of the following types:
/// `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `complex64`, `int64`, `qint8`, `quint8`, `qint32`, `bfloat16`, `uint16`, `complex128`, `half`, `uint32`, `uint64`.
/// The tensor to reduce.</param>
/// <param name="axis">A `Tensor`. Must be one of the following types: `int32`, `int64`. The dimensions to reduce.</param>
/// <param name="keep_dims"> An optional `bool`. Defaults to `False`. If true, retain reduced dimensions with length 1.</param>
/// <param name="name"> A name for the operation (optional).</param>
/// <returns> A `Tensor`. Has the same type as `input`.</returns>
public static Tensor mean<T1, T2>(T1 input, T2 axis, bool keep_dims= false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Mean", name, args: new { input, reduction_indices = axis, keep_dims = keep_dims });
return _op.outputs[0];
}
public static Tensor prod<T1, T2>(T1 input, T2 axis, bool keep_dims = false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Prod", name, args: new { input, reduction_indices = axis, keep_dims });
return _op.outputs[0];
}
public static Tensor acos(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Acos", name, args: new { x });
return _op.outputs[0];
}
public static Tensor asin(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Asin", name, args: new { x });
return _op.outputs[0];
}
public static Tensor add<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Add", name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor atan(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Atan", name, args: new { x });
return _op.outputs[0];
}
public static Tensor ceil(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Ceil", name, args: new { x });
return _op.outputs[0];
}
public static Tensor sin(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sin", name, args: new { x });
return _op.outputs[0];
}
/// <summary>
/// Computes sigmoid of <c>x</c> element-wise.
/// </summary>
/// <param name="x">
/// </param>
/// <param name="name">
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'Sigmoid'.
/// </param>
/// <returns>
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
/// </returns>
/// <remarks>
/// Specifically, <c>y = 1 / (1 + exp(-x))</c>.
/// </remarks>
public static Tensor sigmoid(Tensor x, string name = "Sigmoid")
{
var op = _op_def_lib._apply_op_helper("Sigmoid", name: name, new { x });
return op.output;
}
/// <summary>
/// Computes the gradient of the sigmoid of <c>x</c> wrt its input.
/// </summary>
/// <param name="y">
/// </param>
/// <param name="dy">
/// </param>
/// <param name="name">
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'SigmoidGrad'.
/// </param>
/// <returns>
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
/// </returns>
/// <remarks>
/// Specifically, <c>grad = dy * y * (1 - y)</c>, where <c>y = sigmoid(x)</c>, and
/// <c>dy</c> is the corresponding input gradient.
/// </remarks>
public static Tensor sigmoid_grad(Tensor y, Tensor dy, string name = "SigmoidGrad")
{
var op = _op_def_lib._apply_op_helper("SigmoidGrad", name: name, args: new { y, dy });
return op.outputs[0];
}
public static Tensor sinh(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sinh", name, args: new { x });
return _op.outputs[0];
}
public static Tensor cos(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Cos", name, args: new { x });
return _op.outputs[0];
}
public static Tensor cosh(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Cosh", name, args: new { x });
return _op.outputs[0];
}
public static Tensor tan(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Tan", name, args: new { x });
return _op.outputs[0];
}
public static Tensor tanh(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Tanh", name, args: new { x });
return _op.outputs[0];
}
public static Tensor floor(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Floor", name, args: new { x });
return _op.outputs[0];
}
public static Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null)
{
var _op = _op_def_lib._apply_op_helper("ClipByValue", name, args: new { t, clip_value_min, clip_value_max });
return _op.outputs[0];
}
public static Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Greater", name: name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("GreaterEqual", name: name, args: new { x, y });
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 });
return _op.outputs[0];
}
/// <summary>
/// Computes square of x element-wise.
/// </summary>
/// <param name="x"> A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `int32`, `int64`, `complex64`, `complex128`.</param>
/// <param name="name"> A name for the operation (optional).</param>
/// <returns> A `Tensor`. Has the same type as `x`.</returns>
public static Tensor square(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Square", name, args: new { x });
return _op.outputs[0];
}
/// <summary>
/// Returns which elements of x are finite.
/// </summary>
/// <param name="x"> A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`.</param>
/// <param name="name"> A name for the operation (optional).</param>
/// <returns> A `Tensor` of type `bool`.</returns>
public static Tensor is_finite(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("IsFinite", name, args: new { x });
return _op.outputs[0];
}
/// <summary>
/// Computes exponential of x element-wise. \\(y = e^x\\).
/// </summary>
/// <param name="x"> A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `complex64`, `complex128`.</param>
/// <param name="name"> A name for the operation (optional).</param>
/// <returns> A `Tensor`. Has the same type as `x`.</returns>
public static Tensor exp(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Exp", name, args: new { x });
return _op.outputs[0];
}
/// <summary>
/// Computes natural logarithm of x element-wise.
/// </summary>
/// <param name="x"> A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `complex64`, `complex128`.</param>
/// <param name="name"> name: A name for the operation (optional).</param>
/// <returns> A `Tensor`. Has the same type as `x`.</returns>
public static Tensor log(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Log", name, args: new { x });
return _op.outputs[0];
}
public static Tensor cast(Tensor x, TF_DataType DstT, bool Truncate= false, string name= "")
{
var _op = _op_def_lib._apply_op_helper("Cast", name, args: new { x, DstT, Truncate });
return _op.outputs[0];
}
public static Tensor neg(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Neg", name, args: new { x });
return _op.outputs[0];
}
public static Tensor sqrt(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sqrt", name, args: new { x });
return _op.outputs[0];
}
public static Tensor sub<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sub", name, args: new { x, y });
return _op.outputs[0];
}
/// <summary>
/// Returns the truth value of (x == y) element-wise.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor equal<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Equal", name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor atan2(Tensor y, Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Atan2", name, args: new { y, x });
return _op.outputs[0];
}
public static Tensor mul<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Mul", name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor mul_no_nan<Tx, Ty>(Tx x, Ty y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("MulNoNan", name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor real_div(Tensor x, Tensor y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("RealDiv", name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor reciprocal(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Reciprocal", name, args: new { x });
return _op.outputs[0];
}
public static Tensor floor_mod(Tensor x, Tensor y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("FloorMod", name, args: new { x, y });
return _op.outputs[0];
}
public static Tensor floor_div(Tensor x, Tensor y, string name = null)
{
var _op = _op_def_lib._apply_op_helper("FloorDiv", name, args: new { x, y });
return _op.outputs[0];
}
/// <summary>
/// Multiply the matrix "a" by the matrix "b".
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="transpose_a"></param>
/// <param name="transpose_b"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor mat_mul(Tensor a, Tensor b, bool transpose_a = false, bool transpose_b = false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("MatMul", name, args: new { a, b, transpose_a, transpose_b });
return _op.outputs[0];
}
/// <summary>
/// Returns the max of x and y (i.e. x > y ? x : y) element-wise.
/// </summary>
/// <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)
{
var _op = _op_def_lib._apply_op_helper("Maximum", name, args: new { x, y });
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 });
return _op.outputs[0];
}
public static Tensor _max<Tx, Ty>(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 });
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 });
return _op.outputs[0];
}
public static Tensor _sum(Tensor input, Tensor axis = null, bool keep_dims = false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sum", name, args: new { input, reduction_indices = axis, keep_dims });
return _op.outputs[0];
}
public static Tensor _sum(Tensor input, int axis, bool keep_dims = false, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Sum", name, args: new { input, reduction_indices = axis, keep_dims });
return _op.outputs[0];
}
/// <summary>
/// Creates a sequence of numbers.
/// </summary>
/// <param name="start"></param>
/// <param name="limit"></param>
/// <param name="delta"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor range(Tensor start, Tensor limit, Tensor delta, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Range", name, new { start, limit, delta });
return _op.outputs[0];
}
/// <summary>
/// Rounds the values of a tensor to the nearest integer, element-wise.
/// </summary>
/// <param name="x">
/// </param>
/// <param name="name">
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'Round'.
/// </param>
/// <returns>
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
/// </returns>
/// <remarks>
/// Rounds half to even. Also known as bankers rounding. If you want to round
/// according to the current system rounding mode use std::cint.
/// </remarks>
public static Tensor round(Tensor x, string name = "Round")
{
var op = _op_def_lib._apply_op_helper("Round", name: name, new { x });
return op.output;
}
/// <summary>
/// Computes reciprocal of square root of x element-wise.
/// </summary>
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor rsqrt(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Rsqrt", name, new { x });
return _op.outputs[0];
}
}
}