You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

tf.math.cs 27 kB

4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
6 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*****************************************************************************
  2. Copyright 2023 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. using Tensorflow.Operations;
  14. namespace Tensorflow
  15. {
  16. public partial class tensorflow
  17. {
  18. public MathApi math { get; } = new MathApi();
  19. public class MathApi
  20. {
  21. public Tensor argmax(Tensor input, Axis axis = null, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64)
  22. => gen_math_ops.arg_max(input, axis, name: name, output_type: output_type);
  23. public Tensor count_nonzero(Tensor input, Axis? axis = null, bool? keepdims = null, TF_DataType dtype = TF_DataType.TF_INT64, string name = null)
  24. => math_ops.count_nonzero_v2(input, axis: axis, keepdims: keepdims ?? false, dtype: dtype);
  25. public Tensor log(Tensor x, string name = null)
  26. => gen_math_ops.log(x, name);
  27. /// <summary>
  28. /// Computes the Gauss error function of `x` element-wise.
  29. /// </summary>
  30. /// <param name="x"></param>
  31. /// <param name="name"></param>
  32. /// <returns></returns>
  33. public Tensor erf(Tensor x, string name = null)
  34. => math_ops.erf(x, name);
  35. public Tensor multiply(Tensor x, Tensor y, string name = null)
  36. => math_ops.multiply(x, y, name: name);
  37. public Tensor divide_no_nan(Tensor a, Tensor b, string name = null)
  38. => math_ops.div_no_nan(a, b);
  39. public Tensor square(Tensor x, string name = null)
  40. => math_ops.square(x, name: name);
  41. public Tensor sum(Tensor x, Axis? axis = null, string name = null)
  42. => math_ops.reduce_sum(x, axis: axis, name: name);
  43. public Tensor softplus(Tensor features, string name = null)
  44. => nn_ops.softplus(features, name: name);
  45. public Tensor tanh(Tensor x, string name = null)
  46. => math_ops.tanh(x, name: name);
  47. /// <summary>
  48. /// Finds values and indices of the `k` largest entries for the last dimension.
  49. /// </summary>
  50. /// <param name="input"></param>
  51. /// <param name="k"></param>
  52. /// <param name="sorted"></param>
  53. /// <param name="name"></param>
  54. /// <returns></returns>
  55. public Tensors top_k(Tensor input, int k, bool sorted = true, string name = null)
  56. => nn_ops.top_kv2(input, k, sorted: sorted, name: name);
  57. public Tensor in_top_k(Tensor predictions, Tensor targets, int k, string name = "InTopK")
  58. => nn_ops.in_top_k(predictions, targets, k, name);
  59. /// <summary>
  60. ///
  61. /// </summary>
  62. /// <param name="arr"></param>
  63. /// <param name="weights"></param>
  64. /// <param name="minlength"></param>
  65. /// <param name="maxlength"></param>
  66. /// <param name="dtype"></param>
  67. /// <param name="name"></param>
  68. /// <param name="axis"></param>
  69. /// <param name="binary_output"></param>
  70. /// <returns></returns>
  71. public Tensor bincount(Tensor arr, Tensor weights = null,
  72. Tensor minlength = null,
  73. Tensor maxlength = null,
  74. TF_DataType dtype = TF_DataType.TF_INT32,
  75. string name = null,
  76. Shape axis = null,
  77. bool binary_output = false)
  78. => math_ops.bincount(arr, weights: weights, minlength: minlength, maxlength: maxlength,
  79. dtype: dtype, name: name, axis: axis, binary_output: binary_output);
  80. public Tensor real(Tensor x, string name = null)
  81. => gen_ops.real(x, x.dtype.real_dtype(), name);
  82. public Tensor imag(Tensor x, string name = null)
  83. => gen_ops.imag(x, x.dtype.real_dtype(), name);
  84. public Tensor conj(Tensor x, string name = null)
  85. => gen_ops.conj(x, name);
  86. public Tensor angle(Tensor x, string name = null)
  87. => gen_ops.angle(x, x.dtype.real_dtype(), name);
  88. }
  89. public Tensor abs(Tensor x, string name = null)
  90. => math_ops.abs(x, name);
  91. /// <summary>
  92. /// Computes acos of x element-wise.
  93. /// </summary>
  94. /// <param name="x"></param>
  95. /// <param name="name"></param>
  96. /// <returns></returns>
  97. public Tensor acos(Tensor x, string name = null)
  98. => gen_math_ops.acos(x, name);
  99. /// <summary>
  100. /// Computes asin of x element-wise.
  101. /// </summary>
  102. /// <param name="x"></param>
  103. /// <param name="name"></param>
  104. /// <returns></returns>
  105. public Tensor asin(Tensor x, string name = null)
  106. => gen_math_ops.asin(x, name);
  107. public Tensor add(Tensor a, Tensor b, string name = null)
  108. => gen_math_ops.add(a, b, name: name);
  109. public Tensor add<Tx, Ty>(Tx a, Ty b, string name = null)
  110. => gen_math_ops.add(ops.convert_to_tensor(a), ops.convert_to_tensor(b), name: name);
  111. /// <summary>
  112. /// Adds all input tensors element-wise.
  113. /// </summary>
  114. /// <param name="inputs"></param>
  115. /// <param name="name"></param>
  116. /// <returns>A `Tensor` of same shape and type as the elements of `inputs`.</returns>
  117. public Tensor add_n(Tensor[] inputs, string name = null)
  118. => math_ops.add_n(inputs, name: name);
  119. /// <summary>
  120. /// Computes atan of x element-wise.
  121. /// </summary>
  122. /// <param name="x"></param>
  123. /// <param name="name"></param>
  124. /// <returns></returns>
  125. public Tensor atan(Tensor x, string name = null)
  126. => gen_math_ops.atan(x, name);
  127. public Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
  128. => gen_math_ops.arg_max(input, ops.convert_to_tensor(dimension), output_type: output_type, name: name);
  129. public Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
  130. => gen_math_ops.arg_min(input, ops.convert_to_tensor(dimension), output_type: output_type, name: name);
  131. public Tensor is_finite(Tensor input, string name = null)
  132. => gen_math_ops.is_finite(input, name);
  133. public Tensor is_nan(Tensor input, string name = null)
  134. => gen_math_ops.is_nan(input, name);
  135. /// <summary>
  136. /// Returns element-wise smallest integer not less than x.
  137. /// </summary>
  138. /// <param name="x"></param>
  139. /// <param name="name"></param>
  140. /// <returns></returns>
  141. public Tensor ceil(Tensor x, string name = null)
  142. => gen_math_ops.ceil(x, name);
  143. /// <summary>
  144. /// Computes sin of x element-wise.
  145. /// </summary>
  146. /// <param name="x"></param>
  147. /// <param name="name"></param>
  148. /// <returns></returns>
  149. public Tensor sin(Tensor x, string name = null)
  150. => gen_math_ops.sin(x, name);
  151. /// <summary>
  152. /// Computes hyperbolic sine of x element-wise.
  153. /// </summary>
  154. /// <param name="x"></param>
  155. /// <param name="name"></param>
  156. /// <returns></returns>
  157. public Tensor sinh(Tensor x, string name = null)
  158. => gen_math_ops.sinh(x, name);
  159. /// <summary>
  160. /// Computes cos of x element-wise.
  161. /// </summary>
  162. /// <param name="x"></param>
  163. /// <param name="name"></param>
  164. /// <returns></returns>
  165. public Tensor cos(Tensor x, string name = null)
  166. => gen_math_ops.cos(x, name);
  167. public Tensor cos(float x, string name = null)
  168. => gen_math_ops.cos(ops.convert_to_tensor(x), name);
  169. /// <summary>
  170. /// Computes hyperbolic cosine of x element-wise.
  171. /// </summary>
  172. /// <param name="x"></param>
  173. /// <param name="name"></param>
  174. /// <returns></returns>
  175. public Tensor cosh(Tensor x, string name = null)
  176. => gen_math_ops.cosh(x, name);
  177. public Tensor tan(Tensor x, string name = null)
  178. => gen_math_ops.tan(x, name);
  179. public Tensor tanh(Tensor x, string name = null)
  180. => gen_math_ops.tanh(x, name);
  181. /// <summary>
  182. /// Returns element-wise largest integer not greater than x.
  183. /// </summary>
  184. /// <param name="x"></param>
  185. /// <param name="name"></param>
  186. /// <returns></returns>
  187. public Tensor floor(Tensor x, string name = null)
  188. => gen_math_ops.floor(x, name);
  189. /// <summary>
  190. /// Returns the truth value of (x > y) element-wise.
  191. /// </summary>
  192. /// <typeparam name="Tx"></typeparam>
  193. /// <typeparam name="Ty"></typeparam>
  194. /// <param name="x"></param>
  195. /// <param name="y"></param>
  196. /// <param name="name"></param>
  197. /// <returns></returns>
  198. public Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
  199. => gen_math_ops.greater(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name);
  200. /// <summary>
  201. /// Returns the truth value of (x >= y) element-wise.
  202. /// </summary>
  203. /// <typeparam name="Tx"></typeparam>
  204. /// <typeparam name="Ty"></typeparam>
  205. /// <param name="x"></param>
  206. /// <param name="y"></param>
  207. /// <param name="name"></param>
  208. /// <returns></returns>
  209. public Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  210. => gen_math_ops.greater_equal(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name);
  211. /// <summary>
  212. /// Returns the truth value of (x &lt; y) element-wise.
  213. /// </summary>
  214. /// <typeparam name="Tx"></typeparam>
  215. /// <typeparam name="Ty"></typeparam>
  216. /// <param name="x"></param>
  217. /// <param name="y"></param>
  218. /// <param name="name"></param>
  219. /// <returns></returns>
  220. public Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
  221. => gen_math_ops.less(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name);
  222. /// <summary>
  223. /// Computes the log of the absolute value of `Gamma(x)` element-wise.
  224. /// </summary>
  225. /// <param name="x">A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`.</param>
  226. /// <param name="name">A name for the operation (optional).</param>
  227. /// <returns>A `Tensor`. Has the same type as `x`.</returns>
  228. public Tensor lgamma(Tensor x, string name = null)
  229. => gen_math_ops.lgamma(x, name: name);
  230. /// <summary>
  231. /// Returns the truth value of (x &lt;= y) element-wise.
  232. /// </summary>
  233. /// <typeparam name="Tx"></typeparam>
  234. /// <typeparam name="Ty"></typeparam>
  235. /// <param name="x"></param>
  236. /// <param name="y"></param>
  237. /// <param name="name"></param>
  238. /// <returns></returns>
  239. public Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  240. => gen_math_ops.less_equal(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name);
  241. /// <summary>
  242. /// Computes natural logarithm of (1 + x) element-wise.
  243. /// </summary>
  244. /// <param name="x"></param>
  245. /// <param name="name"></param>
  246. /// <returns></returns>
  247. public Tensor log1p(Tensor x, string name = null)
  248. => gen_math_ops.log1p(x, name);
  249. public Tensor logical_and<T>(T x, T y, string name = null)
  250. => gen_math_ops.logical_and(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name);
  251. public Tensor logical_not(Tensor x, string name = null)
  252. => gen_math_ops.logical_not(x, name);
  253. public Tensor logical_or(Tensor x, Tensor y, string name = null)
  254. => gen_math_ops.logical_or(x, y, name);
  255. public Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor")
  256. {
  257. return gen_math_ops.logical_and(gen_math_ops.logical_or(x, y),
  258. gen_math_ops.logical_not(gen_math_ops.logical_and(x, y)), name);
  259. }
  260. /// <summary>
  261. /// Clips tensor values to a specified min and max.
  262. /// </summary>
  263. /// <param name="t"></param>
  264. /// <param name="clip_value_min"></param>
  265. /// <param name="clip_value_max"></param>
  266. /// <param name="name"></param>
  267. /// <returns></returns>
  268. public Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null)
  269. => gen_math_ops.clip_by_value(t, clip_value_min, clip_value_max);
  270. /// <summary>
  271. /// Clips tensor values to a specified min and max.
  272. /// </summary>
  273. /// <param name="t">
  274. /// A <c>Tensor</c>.
  275. /// </param>
  276. /// <param name="clip_value_min">
  277. /// A 0-D (scalar) <c>Tensor</c>, or a <c>Tensor</c> with the same shape
  278. /// as <c>t</c>. The minimum value to clip by.
  279. /// </param>
  280. /// <param name="clip_value_max">
  281. /// A 0-D (scalar) <c>Tensor</c>, or a <c>Tensor</c> with the same shape
  282. /// as <c>t</c>. The maximum value to clip by.
  283. /// </param>
  284. /// <param name="name">
  285. /// If specified, the created operation in the graph will be this one, otherwise it will be named 'ClipByValue'.
  286. /// </param>
  287. /// <returns>
  288. /// A clipped <c>Tensor</c> with the same shape as input 't'.
  289. /// The Operation can be fetched from the resulting Tensor, by fetching the Operation property from the result.
  290. /// </returns>
  291. /// <remarks>
  292. /// Given a tensor <c>t</c>, this operation returns a tensor of the same type and
  293. /// shape as <c>t</c> with its values clipped to <c>clip_value_min</c> and <c>clip_value_max</c>.
  294. /// Any values less than <c>clip_value_min</c> are set to <c>clip_value_min</c>. Any values
  295. /// greater than <c>clip_value_max</c> are set to <c>clip_value_max</c>.
  296. /// </remarks>
  297. public Tensor clip_by_value<T1, T2>(Tensor t, T1 clip_value_min, T2 clip_value_max, string name = "ClipByValue")
  298. => clip_ops.clip_by_value(t, clip_value_min, clip_value_max, name);
  299. public Tensor sub<Tx, Ty>(Tx a, Ty b, string name = null)
  300. => gen_math_ops.sub(ops.convert_to_tensor(a), ops.convert_to_tensor(b), name: name);
  301. public Tensor divide(Tensor a, Tensor b)
  302. => a / b;
  303. public Tensor sqrt(Tensor a, string name = null)
  304. => gen_math_ops.sqrt(a, name);
  305. public Tensor sign(Tensor a, string name = null)
  306. => gen_math_ops.sign(a, name);
  307. public Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
  308. => gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name);
  309. /// <summary>
  310. /// return x - y
  311. /// </summary>
  312. /// <param name="x"></param>
  313. /// <param name="y"></param>
  314. /// <param name="name"></param>
  315. /// <returns></returns>
  316. public Tensor subtract(Tensor x, Tensor y, string name = null)
  317. => gen_math_ops.sub(x, y, name);
  318. public Tensor log(Tensor x, string name = null)
  319. => gen_math_ops.log(x, name);
  320. public Tensor equal(Tensor x, Tensor y, string name = null)
  321. => gen_math_ops.equal(x, y, name: name);
  322. /// <summary>
  323. /// Computes arctangent of `y/x` element-wise, respecting signs of the arguments.
  324. /// </summary>
  325. /// <param name="y"></param>
  326. /// <param name="x"></param>
  327. /// <param name="name"></param>
  328. /// <returns></returns>
  329. public Tensor atan2(Tensor y, Tensor x, string name = null)
  330. => gen_math_ops.atan2(y, x, name);
  331. /// <summary>
  332. /// Computes the maximum of elements across dimensions of a tensor.
  333. /// </summary>
  334. /// <typeparam name="Tx"></typeparam>
  335. /// <typeparam name="Ty"></typeparam>
  336. /// <param name="input"></param>
  337. /// <param name="axis"></param>
  338. /// <param name="keep_dims"></param>
  339. /// <param name="name"></param>
  340. /// <returns></returns>
  341. public Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
  342. => gen_math_ops.max(ops.convert_to_tensor(input), ops.convert_to_tensor(axis), keep_dims: keep_dims, name: name);
  343. /// <summary>
  344. /// Computes the minimum of elements across dimensions of a tensor.
  345. /// </summary>
  346. /// <typeparam name="Tx"></typeparam>
  347. /// <typeparam name="Ty"></typeparam>
  348. /// <param name="input"></param>
  349. /// <param name="axis"></param>
  350. /// <param name="keep_dims"></param>
  351. /// <param name="name"></param>
  352. /// <returns></returns>
  353. public Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
  354. => gen_math_ops.min(ops.convert_to_tensor(input), ops.convert_to_tensor(axis), keep_dims: keep_dims, name: name);
  355. /// <summary>
  356. /// Returns the max of x and y (i.e. x > y ? x : y) element-wise.
  357. /// </summary>
  358. /// <typeparam name="T1"></typeparam>
  359. /// <typeparam name="T2"></typeparam>
  360. /// <param name="x"></param>
  361. /// <param name="y"></param>
  362. /// <param name="name"></param>
  363. /// <returns></returns>
  364. public Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
  365. => gen_math_ops.maximum(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name: name);
  366. /// <summary>
  367. /// Returns the min of x and y (i.e. x &lt; y ? x : y) element-wise.
  368. /// </summary>
  369. /// <typeparam name="T1"></typeparam>
  370. /// <typeparam name="T2"></typeparam>
  371. /// <param name="x"></param>
  372. /// <param name="y"></param>
  373. /// <param name="name"></param>
  374. /// <returns></returns>
  375. public Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
  376. => gen_math_ops.minimum(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name: name);
  377. public Tensor multiply(Tensor x, Tensor y, string name = null)
  378. => gen_math_ops.mul(x, y, name: name);
  379. /// <summary>
  380. /// return x * y
  381. /// </summary>
  382. /// <typeparam name="Tx"></typeparam>
  383. /// <typeparam name="Ty"></typeparam>
  384. /// <param name="x"></param>
  385. /// <param name="y"></param>
  386. /// <param name="name"></param>
  387. /// <returns></returns>
  388. public Tensor multiply<Tx, Ty>(Tx x, Ty y, string name = null)
  389. => gen_math_ops.mul(ops.convert_to_tensor(x), ops.convert_to_tensor(y), name: name);
  390. public Tensor negative(Tensor x, string name = null)
  391. => gen_math_ops.neg(x, name);
  392. /// <summary>
  393. /// Returns the truth value of (x != y) element-wise.
  394. /// </summary>
  395. /// <param name="x"></param>
  396. /// <param name="y"></param>
  397. /// <param name="name"></param>
  398. /// <returns>A `Tensor` of type bool with the same size as that of x or y.</returns>
  399. public Tensor not_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  400. => math_ops.not_equal(x, y, name: name);
  401. /// <summary>
  402. /// Divides x / y elementwise (using Python 2 division operator semantics).
  403. /// </summary>
  404. /// <param name="x"></param>
  405. /// <param name="y"></param>
  406. /// <param name="name"></param>
  407. /// <returns></returns>
  408. public Tensor div(Tensor x, Tensor y, string name = null)
  409. => math_ops.div(x, y, name: name);
  410. public Tensor divide<T>(Tensor x, T[] y, string name = null) where T : struct
  411. => x / ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y");
  412. public Tensor pow<T1, T2>(T1 x, T2 y, string name = "pow")
  413. => math_ops.pow(x, y, name: name);
  414. /// <summary>
  415. /// Divides `x / y` elementwise, rounding toward the most negative integer.
  416. /// </summary>
  417. /// <param name="x"></param>
  418. /// <param name="y"></param>
  419. /// <param name="name"></param>
  420. /// <returns>`x / y` rounded down.</returns>
  421. public Tensor floordiv(Tensor x, Tensor y, string name = null)
  422. => math_ops.floordiv(x, y, name: name);
  423. /// <summary>
  424. /// Divides x / y elementwise (using Python 3 division operator semantics).
  425. /// </summary>
  426. /// <param name="x"></param>
  427. /// <param name="y"></param>
  428. /// <param name="name"></param>
  429. /// <returns>`x / y` evaluated in floating point.</returns>
  430. public static Tensor truediv(Tensor x, Tensor y, string name = null)
  431. => math_ops.truediv(x, y, name: name);
  432. public Tensor range(object start, object limit = null, object delta = null, TF_DataType? dtype = null, string name = "range")
  433. => math_ops.range(start, limit: limit, delta: delta, dtype: dtype, name: name);
  434. public Tensor real(Tensor input, string name = null)
  435. => math_ops.real(input, name);
  436. /// <summary>
  437. /// Computes the "logical or" of elements across dimensions of a tensor.
  438. /// </summary>
  439. /// <param name="input_tensor">The boolean tensor to reduce.</param>
  440. /// <param name="axis">The dimensions to reduce.</param>
  441. /// <param name="keepdims">If true, retains reduced dimensions with length 1.</param>
  442. /// <param name="name"></param>
  443. /// <returns>The reduced tensor.</returns>
  444. public Tensor reduce_any(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  445. => math_ops.reduce_any(input_tensor, axis: axis, keepdims: keepdims, name: name);
  446. /// <summary>
  447. /// Computes the "logical and" of elements across dimensions of a tensor.
  448. /// </summary>
  449. /// <param name="input_tensor"></param>
  450. /// <param name="axis"></param>
  451. /// <param name="keepdims"></param>
  452. /// <param name="name"></param>
  453. /// <returns>The reduced tensor.</returns>
  454. public Tensor reduce_all(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  455. => math_ops.reduce_all(input_tensor, axis: axis, keepdims: keepdims, name: name);
  456. /// <summary>
  457. /// Computes the product of elements across dimensions of a tensor.
  458. /// </summary>
  459. /// <param name="input_tensor"></param>
  460. /// <param name="axis"></param>
  461. /// <param name="keepdims"></param>
  462. /// <param name="name"></param>
  463. /// <returns></returns>
  464. public Tensor reduce_prod(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  465. => math_ops.reduce_prod(input_tensor, axis: axis, keepdims: keepdims, name: name);
  466. /// <summary>
  467. /// Computes the sum of elements across dimensions of a tensor.
  468. /// </summary>
  469. /// <param name="input"></param>
  470. /// <param name="axis"></param>
  471. /// <returns></returns>
  472. public Tensor reduce_sum(Tensor input, Axis? axis = null, Axis? reduction_indices = null,
  473. bool keepdims = false, string name = null)
  474. {
  475. if (keepdims)
  476. return math_ops.reduce_sum(input, axis: constant_op.constant(axis ?? reduction_indices), keepdims: keepdims, name: name);
  477. else
  478. return math_ops.reduce_sum(input, axis: constant_op.constant(axis ?? reduction_indices));
  479. }
  480. /// <summary>
  481. /// Computes the maximum of elements across dimensions of a tensor.
  482. /// </summary>
  483. /// <param name="input_tensor"></param>
  484. /// <param name="axis"></param>
  485. /// <param name="keepdims"></param>
  486. /// <param name="name"></param>
  487. /// <returns></returns>
  488. public Tensor reduce_max(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  489. => math_ops.reduce_max(input_tensor, axis, keepdims, name);
  490. public Tensor reduce_min(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  491. => math_ops.reduce_min(input_tensor, axis, keepdims, name);
  492. public Tensor reduce_std(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  493. => math_ops.reduce_std(input_tensor, axis, keepdims, name);
  494. public Tensor reduce_variance(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null)
  495. => math_ops.reduce_variance(input_tensor, axis, keepdims, name);
  496. public Tensor sigmoid<T>(T x, string name = null)
  497. => math_ops.sigmoid(x, name: name);
  498. public Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null)
  499. => gen_math_ops.sum(input, ops.convert_to_tensor(axis), keep_dims: keep_dims, name: name);
  500. public Tensor reduce_mean(Tensor input_tensor, Axis? axis = null, bool keepdims = false, string name = null, int? reduction_indices = null)
  501. => math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices);
  502. public Tensor round(Tensor x, string name = null)
  503. => gen_math_ops.round(x, name: name);
  504. public Tensor cast(Tensor x, TF_DataType dtype, string name = null)
  505. => math_ops.cast(x, dtype, name);
  506. public Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null)
  507. => math_ops.cumsum(x, axis: axis, exclusive: exclusive, reverse: reverse, name: name);
  508. public Tensor square(Tensor x, string name = null)
  509. => gen_math_ops.square(x, name: name);
  510. public Tensor squared_difference(Tensor x, Tensor y, string name = null)
  511. => gen_math_ops.squared_difference(x: x, y: y, name: name);
  512. public Tensor complex(Tensor real, Tensor imag, Tensorflow.TF_DataType? dtype = null,
  513. string name = null) => gen_ops.complex(real, imag, dtype, name);
  514. }
  515. }