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.

Math.Test.cs 1.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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Tensorflow;
  7. using Tensorflow.NumPy;
  8. namespace TensorFlowNET.UnitTest.NumPy
  9. {
  10. /// <summary>
  11. /// https://numpy.org/doc/stable/reference/generated/numpy.prod.html
  12. /// </summary>
  13. [TestClass]
  14. public class MathTest : EagerModeTestBase
  15. {
  16. [TestMethod]
  17. public void prod()
  18. {
  19. var p = np.prod(1.0, 2.0);
  20. Assert.AreEqual(p, 2.0);
  21. p = np.prod(new[,] { { 1.0, 2.0 }, { 3.0, 4.0 } });
  22. Assert.AreEqual(p, 24.0);
  23. p = np.prod(new[,] { { 1.0, 2.0 }, { 3.0, 4.0 } }, axis: 1);
  24. Assert.AreEqual(p.shape, 2);
  25. Assert.IsTrue(Equal(p.ToArray<double>(), new[] { 2.0, 12.0 }));
  26. }
  27. [TestMethod]
  28. public void astype()
  29. {
  30. var x = np.array(new byte[] { 1, 100, 200 });
  31. var x1 = x.astype(np.float32);
  32. Assert.AreEqual(x1[2], 200f);
  33. }
  34. [TestMethod]
  35. public void divide()
  36. {
  37. var x = np.array(new float[] { 1, 100, 200 });
  38. var y = x / 2;
  39. Assert.AreEqual(y.dtype, np.float32);
  40. }
  41. }
  42. }