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.

ArrayOpsTest.cs 907 B

123456789101112131415161718192021222324252627
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using NumSharp;
  3. using Tensorflow;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest.ManagedAPI
  6. {
  7. [TestClass]
  8. public class ArrayOpsTest : EagerModeTestBase
  9. {
  10. /// <summary>
  11. /// https://www.tensorflow.org/api_docs/python/tf/keras/layers/Embedding
  12. /// </summary>
  13. [TestMethod]
  14. public void Gather()
  15. {
  16. var input_array = tf.constant(np.arange(12).reshape(3, 4).astype(np.float32));
  17. var indices = tf.constant(np.array(new int[] { 0, 2 }));
  18. var result = array_ops.gather(input_array, indices);
  19. Assert.AreEqual(new TensorShape(2, 4), result.shape);
  20. Assert.AreEqual(result.numpy()[0,0], 0.0f);
  21. Assert.AreEqual(result.numpy()[0,1], 1.0f);
  22. Assert.AreEqual(result.numpy()[1,3], 11.0f);
  23. }
  24. }
  25. }