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.

Randomize.Test.cs 1.3 kB

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/1.20/reference/random/index.html
  12. /// </summary>
  13. [TestClass]
  14. public class RandomizeTest : EagerModeTestBase
  15. {
  16. [TestMethod]
  17. public void permutation()
  18. {
  19. var x = np.random.permutation(10);
  20. Assert.AreEqual(x.shape, 10);
  21. var y = np.random.permutation(x);
  22. Assert.AreEqual(x.shape, 10);
  23. Assert.AreNotEqual(x.ToArray<int>(), y.ToArray<int>());
  24. }
  25. /// <summary>
  26. /// https://numpy.org/doc/stable/reference/random/generated/numpy.random.normal.html
  27. /// </summary>
  28. [TestMethod]
  29. public void normal()
  30. {
  31. var x = np.random.normal(0, 0.1f, 1000);
  32. Equal(np.mean(x), 0f);
  33. }
  34. [TestMethod]
  35. public void randn()
  36. {
  37. var x = np.random.randn();
  38. Assert.AreEqual(np.float32, x.dtype);
  39. x = np.random.randn(2, 4);
  40. Equal(np.mean(x), 0f);
  41. }
  42. }
  43. }