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 16 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*****************************************************************************
  2. Copyright 2018 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. namespace Tensorflow
  14. {
  15. public static partial class tf
  16. {
  17. public static Tensor abs(Tensor x, string name = null)
  18. => math_ops.abs(x, name);
  19. /// <summary>
  20. /// Computes acos of x element-wise.
  21. /// </summary>
  22. /// <param name="x"></param>
  23. /// <param name="name"></param>
  24. /// <returns></returns>
  25. public static Tensor acos(Tensor x, string name = null)
  26. => gen_math_ops.acos(x, name);
  27. /// <summary>
  28. /// Computes asin of x element-wise.
  29. /// </summary>
  30. /// <param name="x"></param>
  31. /// <param name="name"></param>
  32. /// <returns></returns>
  33. public static Tensor asin(Tensor x, string name = null)
  34. => gen_math_ops.asin(x, name);
  35. public static Tensor add<Tx, Ty>(Tx a, Ty b)
  36. => gen_math_ops.add(a, b);
  37. /// <summary>
  38. /// Computes atan of x element-wise.
  39. /// </summary>
  40. /// <param name="x"></param>
  41. /// <param name="name"></param>
  42. /// <returns></returns>
  43. public static Tensor atan(Tensor x, string name = null)
  44. => gen_math_ops.atan(x, name);
  45. public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
  46. => gen_math_ops.arg_max(input, dimension, output_type: output_type, name: name);
  47. public static Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
  48. => gen_math_ops.arg_min(input, dimension, output_type: output_type, name: name);
  49. public static Tensor is_finite(Tensor input, string name = null)
  50. => gen_math_ops.is_finite(input, name);
  51. public static Tensor is_nan(Tensor input, string name = null)
  52. => gen_math_ops.is_nan(input, name);
  53. /// <summary>
  54. /// Returns element-wise smallest integer not less than x.
  55. /// </summary>
  56. /// <param name="x"></param>
  57. /// <param name="name"></param>
  58. /// <returns></returns>
  59. public static Tensor ceil(Tensor x, string name = null)
  60. => gen_math_ops.ceil(x, name);
  61. /// <summary>
  62. /// Computes sin of x element-wise.
  63. /// </summary>
  64. /// <param name="x"></param>
  65. /// <param name="name"></param>
  66. /// <returns></returns>
  67. public static Tensor sin(Tensor x, string name = null)
  68. => gen_math_ops.sin(x, name);
  69. /// <summary>
  70. /// Computes hyperbolic sine of x element-wise.
  71. /// </summary>
  72. /// <param name="x"></param>
  73. /// <param name="name"></param>
  74. /// <returns></returns>
  75. public static Tensor sinh(Tensor x, string name = null)
  76. => gen_math_ops.sinh(x, name);
  77. /// <summary>
  78. /// Computes cos of x element-wise.
  79. /// </summary>
  80. /// <param name="x"></param>
  81. /// <param name="name"></param>
  82. /// <returns></returns>
  83. public static Tensor cos(Tensor x, string name = null)
  84. => gen_math_ops.cos(x, name);
  85. /// <summary>
  86. /// Computes hyperbolic cosine of x element-wise.
  87. /// </summary>
  88. /// <param name="x"></param>
  89. /// <param name="name"></param>
  90. /// <returns></returns>
  91. public static Tensor cosh(Tensor x, string name = null)
  92. => gen_math_ops.cosh(x, name);
  93. public static Tensor tan(Tensor x, string name = null)
  94. => gen_math_ops.tan(x, name);
  95. public static Tensor tanh(Tensor x, string name = null)
  96. => gen_math_ops.tanh(x, name);
  97. /// <summary>
  98. /// Returns element-wise largest integer not greater than x.
  99. /// </summary>
  100. /// <param name="x"></param>
  101. /// <param name="name"></param>
  102. /// <returns></returns>
  103. public static Tensor floor(Tensor x, string name = null)
  104. => gen_math_ops.floor(x, name);
  105. /// <summary>
  106. /// Returns the truth value of (x > y) element-wise.
  107. /// </summary>
  108. /// <typeparam name="Tx"></typeparam>
  109. /// <typeparam name="Ty"></typeparam>
  110. /// <param name="x"></param>
  111. /// <param name="y"></param>
  112. /// <param name="name"></param>
  113. /// <returns></returns>
  114. public static Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
  115. => gen_math_ops.greater(x, y, name);
  116. /// <summary>
  117. /// Returns the truth value of (x >= y) element-wise.
  118. /// </summary>
  119. /// <typeparam name="Tx"></typeparam>
  120. /// <typeparam name="Ty"></typeparam>
  121. /// <param name="x"></param>
  122. /// <param name="y"></param>
  123. /// <param name="name"></param>
  124. /// <returns></returns>
  125. public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  126. => gen_math_ops.greater_equal(x, y, name);
  127. /// <summary>
  128. /// Returns the truth value of (x < y) element-wise.
  129. /// </summary>
  130. /// <typeparam name="Tx"></typeparam>
  131. /// <typeparam name="Ty"></typeparam>
  132. /// <param name="x"></param>
  133. /// <param name="y"></param>
  134. /// <param name="name"></param>
  135. /// <returns></returns>
  136. public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
  137. => gen_math_ops.less(x, y, name);
  138. /// <summary>
  139. /// Computes the log of the absolute value of `Gamma(x)` element-wise.
  140. /// </summary>
  141. /// <param name="x">A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`.</param>
  142. /// <param name="name">A name for the operation (optional).</param>
  143. /// <returns>A `Tensor`. Has the same type as `x`.</returns>
  144. public static Tensor lgamma(Tensor x, string name = null)
  145. => gen_math_ops.lgamma(x, name: name);
  146. /// <summary>
  147. /// Returns the truth value of (x <= y) element-wise.
  148. /// </summary>
  149. /// <typeparam name="Tx"></typeparam>
  150. /// <typeparam name="Ty"></typeparam>
  151. /// <param name="x"></param>
  152. /// <param name="y"></param>
  153. /// <param name="name"></param>
  154. /// <returns></returns>
  155. public static Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  156. => gen_math_ops.less_equal(x, y, name);
  157. /// <summary>
  158. /// Computes natural logarithm of (1 + x) element-wise.
  159. /// </summary>
  160. /// <param name="x"></param>
  161. /// <param name="name"></param>
  162. /// <returns></returns>
  163. public static Tensor log1p(Tensor x, string name = null)
  164. => gen_math_ops.log1p(x, name);
  165. public static Tensor logical_and(Tensor x, Tensor y, string name = null)
  166. => gen_math_ops.logical_and(x, y, name);
  167. public static Tensor logical_not(Tensor x, string name = null)
  168. => gen_math_ops.logical_not(x, name);
  169. public static Tensor logical_or(Tensor x, Tensor y, string name = null)
  170. => gen_math_ops.logical_or(x, y, name);
  171. /// <summary>
  172. /// Clips tensor values to a specified min and max.
  173. /// </summary>
  174. /// <param name="t"></param>
  175. /// <param name="clip_value_min"></param>
  176. /// <param name="clip_value_max"></param>
  177. /// <param name="name"></param>
  178. /// <returns></returns>
  179. public static Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null)
  180. => gen_math_ops._clip_by_value(t, clip_value_min, clip_value_max);
  181. public static Tensor sub(Tensor a, Tensor b)
  182. => gen_math_ops.sub(a, b);
  183. public static Tensor divide(Tensor a, Tensor b)
  184. => gen_math_ops.real_div(a, b);
  185. public static Tensor sqrt(Tensor a, string name = null)
  186. => gen_math_ops.sqrt(a, name);
  187. public static Tensor sign(Tensor a, string name = null)
  188. => gen_math_ops.sign(a, name);
  189. public static Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
  190. => gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name);
  191. public static Tensor log(Tensor x, string name = null)
  192. => gen_math_ops.log(x, name);
  193. public static Tensor equal(Tensor x, Tensor y, string name = null)
  194. => gen_math_ops.equal(x, y, name);
  195. /// <summary>
  196. /// Computes arctangent of `y/x` element-wise, respecting signs of the arguments.
  197. /// </summary>
  198. /// <param name="y"></param>
  199. /// <param name="x"></param>
  200. /// <param name="name"></param>
  201. /// <returns></returns>
  202. public static Tensor atan2(Tensor y, Tensor x, string name = null)
  203. => gen_math_ops.atan2(y, x, name);
  204. /// <summary>
  205. /// Computes the maximum of elements across dimensions of a tensor.
  206. /// </summary>
  207. /// <typeparam name="Tx"></typeparam>
  208. /// <typeparam name="Ty"></typeparam>
  209. /// <param name="input"></param>
  210. /// <param name="axis"></param>
  211. /// <param name="keep_dims"></param>
  212. /// <param name="name"></param>
  213. /// <returns></returns>
  214. public static Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
  215. => gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name);
  216. /// <summary>
  217. /// Computes the minimum of elements across dimensions of a tensor.
  218. /// </summary>
  219. /// <typeparam name="Tx"></typeparam>
  220. /// <typeparam name="Ty"></typeparam>
  221. /// <param name="input"></param>
  222. /// <param name="axis"></param>
  223. /// <param name="keep_dims"></param>
  224. /// <param name="name"></param>
  225. /// <returns></returns>
  226. public static Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
  227. => gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name);
  228. /// <summary>
  229. /// Returns the max of x and y (i.e. x > y ? x : y) element-wise.
  230. /// </summary>
  231. /// <typeparam name="T1"></typeparam>
  232. /// <typeparam name="T2"></typeparam>
  233. /// <param name="x"></param>
  234. /// <param name="y"></param>
  235. /// <param name="name"></param>
  236. /// <returns></returns>
  237. public static Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
  238. => gen_math_ops.maximum(x, y, name: name);
  239. /// <summary>
  240. /// Returns the min of x and y (i.e. x < y ? x : y) element-wise.
  241. /// </summary>
  242. /// <typeparam name="T1"></typeparam>
  243. /// <typeparam name="T2"></typeparam>
  244. /// <param name="x"></param>
  245. /// <param name="y"></param>
  246. /// <param name="name"></param>
  247. /// <returns></returns>
  248. public static Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
  249. => gen_math_ops.minimum(x, y, name: name);
  250. public static Tensor multiply<Tx, Ty>(Tx x, Ty y)
  251. => gen_math_ops.mul(x, y);
  252. public static Tensor negative(Tensor x, string name = null)
  253. => gen_math_ops.neg(x, name);
  254. /// <summary>
  255. /// Divides x / y elementwise (using Python 2 division operator semantics).
  256. /// </summary>
  257. /// <param name="x"></param>
  258. /// <param name="y"></param>
  259. /// <param name="name"></param>
  260. /// <returns></returns>
  261. public static Tensor div(Tensor x, Tensor y, string name = null)
  262. => math_ops.div(x, y, name: name);
  263. public static Tensor divide<T>(Tensor x, T[] y, string name = null) where T : struct
  264. => x / ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y");
  265. public static Tensor pow<T1, T2>(T1 x, T2 y)
  266. => gen_math_ops.pow(x, y);
  267. /// <summary>
  268. /// Computes the sum of elements across dimensions of a tensor.
  269. /// </summary>
  270. /// <param name="input"></param>
  271. /// <param name="axis"></param>
  272. /// <returns></returns>
  273. public static Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices = null)
  274. {
  275. if(!axis.HasValue && reduction_indices.HasValue)
  276. return math_ops.reduce_sum(input, reduction_indices.Value);
  277. return math_ops.reduce_sum(input);
  278. }
  279. public static Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null)
  280. => math_ops.reduce_sum(input, axis);
  281. /// <summary>
  282. /// Computes the maximum of elements across dimensions of a tensor.
  283. /// </summary>
  284. /// <param name="input_tensor"></param>
  285. /// <param name="axis"></param>
  286. /// <param name="keepdims"></param>
  287. /// <param name="name"></param>
  288. /// <returns></returns>
  289. public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
  290. => math_ops.reduce_max(input_tensor, axis, keepdims, name);
  291. public static Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
  292. => math_ops.reduce_min(input_tensor, axis, keepdims, name);
  293. public static Tensor sigmoid<T>(T x, string name = null)
  294. => math_ops.sigmoid(x, name: name);
  295. public static Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null)
  296. => gen_math_ops._sum(input, axis, keep_dims: keep_dims, name: name);
  297. public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null)
  298. => math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices);
  299. public static Tensor round(Tensor x, string name = null)
  300. => gen_math_ops.round(x, name: name);
  301. public static Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null)
  302. => math_ops.cast(x, dtype, name);
  303. public static Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null)
  304. => math_ops.cumsum(x, axis: axis, exclusive: exclusive, reverse: reverse, name: name);
  305. public static Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64)
  306. => gen_math_ops.arg_max(input, axis, name: name, output_type: output_type);
  307. public static Tensor square(Tensor x, string name = null)
  308. => gen_math_ops.square(x, name: name);
  309. }
  310. }