Repository navigation
Expand file tree
/
Copy pathgen_array_ops.cs
More file actions
356 lines (307 loc) · 14.1 KB
/
Copy pathgen_array_ops.cs
File metadata and controls
356 lines (307 loc) · 14.1 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
using NumSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Tensorflow.Eager;
namespace Tensorflow
{
public static class gen_array_ops
{
public static OpDefLibrary _op_def_lib = new OpDefLibrary();
public static Execute _execute = new Execute();
/// <summary>
/// Concatenates tensors along one dimension.
/// </summary>
/// <param name="values"></param>
/// <param name="axis"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor concat_v2(Tensor[] values, int axis, string name = null)
{
var _op = _op_def_lib._apply_op_helper("ConcatV2", name: name, args: new { values, axis });
return _op.outputs[0];
}
/// <summary>
/// Returns a diagonal tensor with a given diagonal values.
/// </summary>
/// <param name="diagonal">
/// Rank k tensor where k is at most 1.
/// </param>
/// <param name="name">
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'Diag'.
/// </param>
/// <returns>
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
/// </returns>
/// <remarks>
/// Given a <c>diagonal</c>, this operation returns a tensor with the <c>diagonal</c> and
/// everything else padded with zeros. The diagonal is computed as follows:
///
/// Assume <c>diagonal</c> has dimensions [D1,..., Dk], then the output is a tensor of
/// rank 2k with dimensions [D1,..., Dk, D1,..., Dk] where:
///
/// <c>output[i1,..., ik, i1,..., ik] = diagonal[i1, ..., ik]</c> and 0 everywhere else.
///
/// For example:
///
/// <code>
/// # 'diagonal' is [1, 2, 3, 4]
/// tf.diag(diagonal) ==&gt; [[1, 0, 0, 0]
/// [0, 2, 0, 0]
/// [0, 0, 3, 0]
/// [0, 0, 0, 4]]
/// </code>
/// </remarks>
public static Tensor diag(Tensor diagonal, string name = null)
{
var op = _op_def_lib._apply_op_helper("Diag", name: name, args: new { diagonal });
return op.output;
}
public static Tensor expand_dims(Tensor input, int axis, string name = null)
{
var _op = _op_def_lib._apply_op_helper("ExpandDims", name: name, args: new { input, dim = axis });
return _op.outputs[0];
}
public static Tensor gather_v2(Tensor @params, Tensor indices, int axis, string name = null)
{
var _op = _op_def_lib._apply_op_helper("GatherV2", name: name, new { @params, indices, axis });
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 });
return _op.outputs[0];
}
public static Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Placeholder", name: name, args: new { dtype, shape });
var _result = _op.outputs;
var _inputs_flat = _op.inputs;
var _attrs = new Dictionary<string, object>();
_attrs["dtype"] = _op.get_attr("dtype");
_attrs["shape"] = _op.get_attr("shape");
_execute.record_gradient("Placeholder", _inputs_flat, _attrs, _result, name);
return new Tensor(_op, 0, dtype);
}
/// <summary>
/// An identity op that triggers an error if a gradient is requested.
/// </summary>
/// <param name="input">
/// any tensor.
/// </param>
/// <param name="name">
/// If specified, the created operation in the graph will be this one, otherwise it will be named 'PreventGradient'.
/// </param>
/// <param name="message">
/// Will be printed in the error when anyone tries to differentiate
/// this operation.
/// </param>
/// <returns>
/// the same input tensor.
/// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
/// </returns>
/// <remarks>
/// When executed in a graph, this op outputs its input tensor as-is.
///
/// When building ops to compute gradients, the TensorFlow gradient system
/// will return an error when trying to lookup the gradient of this op,
/// because no gradient must ever be registered for this function. This
/// op exists to prevent subtle bugs from silently returning unimplemented
/// gradients in some corner cases.
/// </remarks>
public static Tensor prevent_gradient(Tensor input, string message = "", string name = null)
{
var op = _op_def_lib._apply_op_helper("PreventGradient", name: name, args: new { input, message });
return op.output;
}
/// <summary>
/// Return a tensor with the same shape and contents as the input tensor or value.
/// </summary>
/// <param name="input"></param>
/// <param name="name"></param>
public static Tensor identity(Tensor input, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Identity", name, new { input });
return _op.outputs[0];
}
public static Tensor invert_permutation(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("InvertPermutation", name, new { x });
return _op.outputs[0];
}
public static Tensor log(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Log", name: name, args: new { x });
return _op.outputs[0];
}
public static Tensor rank(Tensor input, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Rank", name: name, args: new { input });
return _op.outputs[0];
}
/// <summary>
/// Creates a tensor filled with a scalar value.
/// </summary>
/// <param name="dims">A `Tensor`.</param>
/// <param name="value">A `Tensor`. 0-D (scalar). Value to fill the returned tensor.</param>
/// <param name="name">A name for the operation (optional).</param>
/// <returns>A `Tensor`. Has the same type as `value`.</returns>
public static Tensor fill<T>(Tensor dims, T value, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Fill", name, new { dims, value });
return _op.outputs[0];
}
/// <summary>
/// Return the reduction indices for computing gradients of s0 op s1 with broadcast.
/// </summary>
/// <param name="s0">A `Tensor`. Must be one of the following types: `int32`, `int64`.</param>
/// <param name="s1">A `Tensor`. Must have the same type as `s0`.</param>
/// <param name="name">A name for the operation (optional).</param>
/// <returns>A tuple of `Tensor` objects (r0, r1).</returns>
public static (Tensor, Tensor) broadcast_gradient_args(Tensor s0, Tensor s1, string name = "")
{
var _op = _op_def_lib._apply_op_helper("BroadcastGradientArgs", name, new { s0, s1 });
return (_op.outputs[0], _op.outputs[1]);
}
public static Tensor reshape<T1, T2>(T1 tensor, T2 shape, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Reshape", name, new { tensor, shape });
return _op.outputs[0];
}
public static Tensor reshape(Tensor tensor, int[] shape, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Reshape", name, new { tensor, shape });
return _op.outputs[0];
}
public static Tensor where()
{
throw new NotImplementedException("where");
}
public static Tensor one_hot(Tensor indices, int depth,
Tensor on_value = null,
Tensor off_value = null,
TF_DataType dtype = TF_DataType.DtInvalid,
int axis = -1,
string name = null)
{
var _op = _op_def_lib._apply_op_helper("OneHot", name, new { indices, depth, on_value, off_value, axis });
return _op.outputs[0];
}
/// <summary>
/// A placeholder op that passes through `input` when its output is not fed.
/// </summary>
/// <param name="input">The default value to produce when output is not fed.</param>
/// <param name="shape"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor placeholder_with_default<T>(T input, int[] shape, string name = null)
{
var _op = _op_def_lib._apply_op_helper("PlaceholderWithDefault", name, new { input, shape, name });
return _op.outputs[0];
}
public static Tensor select<Tx, Ty>(Tensor condition, Tx t, Ty e, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Select", name, new { condition, t, e });
return _op.outputs[0];
}
public static Tensor scatter_nd(Tensor indices, Tensor updates, Tensor[] shape, string name = null)
{
var _op = _op_def_lib._apply_op_helper("ScatterNd", name, new { indices, updates, shape });
return _op.outputs[0];
}
public static Tensor shape(Tensor input, TF_DataType out_type = TF_DataType.TF_INT32, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Shape", name, new { input, out_type });
return _op.outputs[0];
}
public static Tensor size(Tensor input, TF_DataType out_type = TF_DataType.TF_INT32, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Size", name, new { input, out_type });
return _op.outputs[0];
}
public static Tensor tile(Tensor input, Tensor multiples, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Tile", name, new { input, multiples });
return _op.outputs[0];
}
public static Tensor tile(NDArray input, int[] multiples, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Tile", name, new { input, multiples });
return _op.outputs[0];
}
public static Tensor transpose<T1, T2>(T1 x, T2 perm, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Transpose", name, new { x, perm });
return _op.outputs[0];
}
public static Tensor zeros_like(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("ZerosLike", name, new { x });
return _op.outputs[0];
}
public static Tensor stop_gradient(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("StopGradient", name, args: new { input = x, name });
return _op.outputs[0];
}
public static Tensor strided_slice(Tensor input, Tensor begin, Tensor end, Tensor strides,
int begin_mask = 0,
int end_mask = 0,
int ellipsis_mask = 0,
int new_axis_mask = 0,
int shrink_axis_mask = 0,
string name = null)
{
var _op = _op_def_lib._apply_op_helper("StridedSlice", name, new
{
input,
begin,
end,
strides,
begin_mask,
end_mask,
ellipsis_mask,
new_axis_mask,
shrink_axis_mask
});
return _op.outputs[0];
}
public static Tensor slice<Tb, Ts>(Tensor input, Tb[] begin, Ts[] size, string name = null)
{
var _op = _op_def_lib._apply_op_helper("Slice", name, new { input, begin, size });
return _op.outputs[0];
}
/// <summary>
/// Removes dimensions of size 1 from the shape of a tensor.
/// Given a tensor `input`, this operation returns a tensor of the same type with
/// all dimensions of size 1 removed.If you don't want to remove all size 1
/// dimensions, you can remove specific size 1 dimensions by specifying
/// `axis`.
/// </summary>
/// <param name="input"> A `Tensor`. The `input` to squeeze.</param>
/// <param name="axis"> An optional list of `ints`. Defaults to `[]`. If specified, only squeezes the dimensions listed.</param>
/// <param name="name"> A name for the operation (optional).</param>
/// <returns> A `Tensor`. Has the same type as `input`.</returns>
public static Tensor squeeze(Tensor input, int[] axis = null, string name = null)
{
if (axis == null) axis = new int[0];
var _op = _op_def_lib._apply_op_helper("Squeeze", name, args: new { input, squeeze_dims = axis });
return _op.outputs[0];
}
/// <summary>
/// Return the shape of s0 op s1 with broadcast.
/// Given `s0` and `s1`, tensors that represent shapes, compute `r0`, the
/// broadcasted shape. `s0`, `s1` and `r0` are all integer vectors.
/// </summary>
/// <param name="s0"> A `Tensor`. Must be one of the following types: `int32`, `int64`.</param>
/// <param name="s1"> A `Tensor`. Must have the same type as `s0`.</param>
/// <param name="name"> A name for the operation (optional).</param>
/// <returns> `Tensor`. Has the same type as `s0`.</returns>
public static Tensor broadcast_args(Tensor s0, Tensor s1, string name = null)
{
var _op = _op_def_lib._apply_op_helper("BroadcastArgs", name, args: new { s0, s1, name });
return _op.outputs[0];
}
}
}