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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Tensorflow
  5. {
  6. public static partial class tf
  7. {
  8. public static Tensor abs(Tensor x, string name = null)
  9. => math_ops.abs(x, name);
  10. /// <summary>
  11. /// Computes acos of x element-wise.
  12. /// </summary>
  13. /// <param name="x"></param>
  14. /// <param name="name"></param>
  15. /// <returns></returns>
  16. public static Tensor acos(Tensor x, string name = null)
  17. => gen_math_ops.acos(x, name);
  18. /// <summary>
  19. /// Computes asin of x element-wise.
  20. /// </summary>
  21. /// <param name="x"></param>
  22. /// <param name="name"></param>
  23. /// <returns></returns>
  24. public static Tensor asin(Tensor x, string name = null)
  25. => gen_math_ops.asin(x, name);
  26. public static Tensor add(Tensor a, Tensor b)
  27. => gen_math_ops.add(a, b);
  28. /// <summary>
  29. /// Computes atan of x element-wise.
  30. /// </summary>
  31. /// <param name="x"></param>
  32. /// <param name="name"></param>
  33. /// <returns></returns>
  34. public static Tensor atan(Tensor x, string name = null)
  35. => gen_math_ops.atan(x, name);
  36. public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
  37. => gen_math_ops.arg_max(input, dimension, output_type: output_type, name: name);
  38. public static Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
  39. => gen_math_ops.arg_min(input, dimension, output_type: output_type, name: name);
  40. /// <summary>
  41. /// Returns element-wise smallest integer not less than x.
  42. /// </summary>
  43. /// <param name="x"></param>
  44. /// <param name="name"></param>
  45. /// <returns></returns>
  46. public static Tensor ceil(Tensor x, string name = null)
  47. => gen_math_ops.ceil(x, name);
  48. /// <summary>
  49. /// Computes cos of x element-wise.
  50. /// </summary>
  51. /// <param name="x"></param>
  52. /// <param name="name"></param>
  53. /// <returns></returns>
  54. public static Tensor cos(Tensor x, string name = null)
  55. => gen_math_ops.cos(x, name);
  56. /// <summary>
  57. /// Computes hyperbolic cosine of x element-wise.
  58. /// </summary>
  59. /// <param name="x"></param>
  60. /// <param name="name"></param>
  61. /// <returns></returns>
  62. public static Tensor cosh(Tensor x, string name = null)
  63. => gen_math_ops.cosh(x, name);
  64. /// <summary>
  65. /// Returns element-wise largest integer not greater than x.
  66. /// </summary>
  67. /// <param name="x"></param>
  68. /// <param name="name"></param>
  69. /// <returns></returns>
  70. public static Tensor floor(Tensor x, string name = null)
  71. => gen_math_ops.floor(x, name);
  72. /// <summary>
  73. /// Returns the truth value of (x > y) element-wise.
  74. /// </summary>
  75. /// <typeparam name="Tx"></typeparam>
  76. /// <typeparam name="Ty"></typeparam>
  77. /// <param name="x"></param>
  78. /// <param name="y"></param>
  79. /// <param name="name"></param>
  80. /// <returns></returns>
  81. public static Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
  82. => gen_math_ops.greater(x, y, name);
  83. /// <summary>
  84. /// Returns the truth value of (x >= y) element-wise.
  85. /// </summary>
  86. /// <typeparam name="Tx"></typeparam>
  87. /// <typeparam name="Ty"></typeparam>
  88. /// <param name="x"></param>
  89. /// <param name="y"></param>
  90. /// <param name="name"></param>
  91. /// <returns></returns>
  92. public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  93. => gen_math_ops.greater_equal(x, y, name);
  94. /// <summary>
  95. /// Returns the truth value of (x < y) element-wise.
  96. /// </summary>
  97. /// <typeparam name="Tx"></typeparam>
  98. /// <typeparam name="Ty"></typeparam>
  99. /// <param name="x"></param>
  100. /// <param name="y"></param>
  101. /// <param name="name"></param>
  102. /// <returns></returns>
  103. public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
  104. => gen_math_ops.less(x, y, 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 less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
  115. => gen_math_ops.less_equal(x, y, name);
  116. /// <summary>
  117. /// Computes natural logarithm of (1 + x) element-wise.
  118. /// </summary>
  119. /// <param name="x"></param>
  120. /// <param name="name"></param>
  121. /// <returns></returns>
  122. public static Tensor log1p(Tensor x, string name = null)
  123. => gen_math_ops.log1p(x, name);
  124. /// <summary>
  125. /// Clips tensor values to a specified min and max.
  126. /// </summary>
  127. /// <param name="t"></param>
  128. /// <param name="clip_value_min"></param>
  129. /// <param name="clip_value_max"></param>
  130. /// <param name="name"></param>
  131. /// <returns></returns>
  132. public static Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null)
  133. => gen_math_ops._clip_by_value(t, clip_value_min, clip_value_max);
  134. public static Tensor sub(Tensor a, Tensor b)
  135. => gen_math_ops.sub(a, b);
  136. public static Tensor divide(Tensor a, Tensor b)
  137. => gen_math_ops.real_div(a, b);
  138. public static Tensor sqrt(Tensor a, string name = null)
  139. => gen_math_ops.sqrt(a, name);
  140. public static Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
  141. => gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name);
  142. public static Tensor log(Tensor x, string name = null)
  143. => gen_math_ops.log(x, name);
  144. public static Tensor equal(Tensor x, Tensor y, string name = null)
  145. => gen_math_ops.equal(x, y, name);
  146. /// <summary>
  147. /// Computes arctangent of `y/x` element-wise, respecting signs of the arguments.
  148. /// </summary>
  149. /// <param name="y"></param>
  150. /// <param name="x"></param>
  151. /// <param name="name"></param>
  152. /// <returns></returns>
  153. public static Tensor atan2(Tensor y, Tensor x, string name = null)
  154. => gen_math_ops.atan2(y, x, name);
  155. /// <summary>
  156. /// Computes the maximum of elements across dimensions of a tensor.
  157. /// </summary>
  158. /// <typeparam name="Tx"></typeparam>
  159. /// <typeparam name="Ty"></typeparam>
  160. /// <param name="input"></param>
  161. /// <param name="axis"></param>
  162. /// <param name="keep_dims"></param>
  163. /// <param name="name"></param>
  164. /// <returns></returns>
  165. public static Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
  166. => gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name);
  167. /// <summary>
  168. /// Computes the minimum of elements across dimensions of a tensor.
  169. /// </summary>
  170. /// <typeparam name="Tx"></typeparam>
  171. /// <typeparam name="Ty"></typeparam>
  172. /// <param name="input"></param>
  173. /// <param name="axis"></param>
  174. /// <param name="keep_dims"></param>
  175. /// <param name="name"></param>
  176. /// <returns></returns>
  177. public static Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
  178. => gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name);
  179. /// <summary>
  180. /// Returns the max of x and y (i.e. x > y ? x : y) element-wise.
  181. /// </summary>
  182. /// <typeparam name="T1"></typeparam>
  183. /// <typeparam name="T2"></typeparam>
  184. /// <param name="x"></param>
  185. /// <param name="y"></param>
  186. /// <param name="name"></param>
  187. /// <returns></returns>
  188. public static Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
  189. => gen_math_ops.maximum(x, y, name: name);
  190. /// <summary>
  191. /// Returns the min of x and y (i.e. x < y ? x : y) element-wise.
  192. /// </summary>
  193. /// <typeparam name="T1"></typeparam>
  194. /// <typeparam name="T2"></typeparam>
  195. /// <param name="x"></param>
  196. /// <param name="y"></param>
  197. /// <param name="name"></param>
  198. /// <returns></returns>
  199. public static Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
  200. => gen_math_ops.minimum(x, y, name: name);
  201. public static Tensor multiply(Tensor x, Tensor y)
  202. => gen_math_ops.mul(x, y);
  203. public static Tensor negative(Tensor x, string name = null)
  204. => gen_math_ops.neg(x, name);
  205. public static Tensor divide<T>(Tensor x, T[] y, string name = null) where T : struct
  206. => x / ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y");
  207. public static Tensor pow<T1, T2>(T1 x, T2 y)
  208. => gen_math_ops.pow(x, y);
  209. /// <summary>
  210. /// Computes the sum of elements across dimensions of a tensor.
  211. /// </summary>
  212. /// <param name="input"></param>
  213. /// <param name="axis"></param>
  214. /// <returns></returns>
  215. public static Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices = null)
  216. {
  217. if(!axis.HasValue && reduction_indices.HasValue)
  218. return math_ops.reduce_sum(input, reduction_indices.Value);
  219. return math_ops.reduce_sum(input);
  220. }
  221. public static Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null)
  222. {
  223. return math_ops.reduce_sum(input, axis);
  224. }
  225. public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null)
  226. => math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices);
  227. public static Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null)
  228. => math_ops.cast(x, dtype, name);
  229. public static Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64)
  230. => gen_math_ops.arg_max(input, axis, name: name, output_type: output_type);
  231. }
  232. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。