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.

Numpy.Math.cs 3.3 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5. using System.Text;
  6. using static Tensorflow.Binding;
  7. namespace Tensorflow.NumPy
  8. {
  9. public partial class np
  10. {
  11. [AutoNumPy]
  12. public static NDArray cos(NDArray x) => new NDArray(math_ops.cos(x));
  13. [AutoNumPy]
  14. public static NDArray exp(NDArray x) => new NDArray(tf.exp(x));
  15. [AutoNumPy]
  16. public static NDArray floor(NDArray x) => new NDArray(math_ops.floor(x));
  17. [AutoNumPy]
  18. public static NDArray log(NDArray x) => new NDArray(tf.log(x));
  19. [AutoNumPy]
  20. public static NDArray mean(NDArray x) => new NDArray(math_ops.reduce_mean(x));
  21. [AutoNumPy]
  22. public static NDArray multiply(NDArray x1, NDArray x2) => new NDArray(tf.multiply(x1, x2));
  23. [AutoNumPy]
  24. //public static NDArray maximum(NDArray x1, NDArray x2) => new NDArray(tf.maximum(x1, x2));
  25. public static NDArray maximum(NDArray x1, NDArray x2, int? axis = null)
  26. {
  27. var maxValues = tf.maximum(x1, x2);
  28. if (axis.HasValue)
  29. {
  30. maxValues = tf.reduce_max(maxValues, axis: axis.Value);
  31. }
  32. return new NDArray(maxValues);
  33. }
  34. [AutoNumPy]
  35. public static NDArray minimum(NDArray x1, NDArray x2) => new NDArray(tf.minimum(x1, x2));
  36. [AutoNumPy]
  37. public static NDArray prod(NDArray array, Axis? axis = null, Type? dtype = null, bool keepdims = false)
  38. => new NDArray(tf.reduce_prod(array, axis: axis));
  39. [AutoNumPy]
  40. public static NDArray prod<T>(params T[] array) where T : unmanaged
  41. => new NDArray(tf.reduce_prod(new NDArray(array)));
  42. [AutoNumPy]
  43. public static NDArray dot(NDArray x1, NDArray x2, NDArray? axes = null, string? name = null)
  44. {
  45. //if axes mentioned
  46. if (axes != null)
  47. {
  48. return new NDArray(tf.dot_prod(x1, x2, axes, name));
  49. }
  50. if (x1.shape.ndim > 1)
  51. {
  52. x1 = GetFlattenArray(x1);
  53. }
  54. if (x2.shape.ndim > 1)
  55. {
  56. x2 = GetFlattenArray(x2);
  57. }
  58. //if axes not mentioned, default 0,0
  59. return new NDArray(tf.dot_prod(x1, x2, axes: new int[] { 0, 0 }, name));
  60. }
  61. [AutoNumPy]
  62. public static NDArray power(NDArray x, NDArray y) => new NDArray(tf.pow(x, y));
  63. [AutoNumPy]
  64. public static NDArray square(NDArray x) => new NDArray(tf.square(x));
  65. [AutoNumPy]
  66. public static NDArray sin(NDArray x) => new NDArray(math_ops.sin(x));
  67. [AutoNumPy]
  68. public static NDArray sqrt(NDArray x) => new NDArray(tf.sqrt(x));
  69. [AutoNumPy]
  70. public static NDArray sum(NDArray x1, Axis? axis = null) => new NDArray(tf.math.sum(x1, axis));
  71. [AutoNumPy]
  72. public static NDArray add(NDArray x, NDArray y) => new NDArray(math_ops.add(x, y));
  73. [AutoNumPy]
  74. public static NDArray greater(NDArray x, NDArray y) => new NDArray(tf.greater(x, y));
  75. [AutoNumPy]
  76. public static NDArray less(NDArray x, NDArray y) => new NDArray(tf.less(x, y));
  77. }
  78. }