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.

BitwiseApiTest.cs 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System.Linq;
  3. using Tensorflow;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest.ManagedAPI
  6. {
  7. [TestClass]
  8. public class BitwiseApiTest : TFNetApiTest
  9. {
  10. [TestMethod]
  11. public void BitwiseAnd()
  12. {
  13. Tensor lhs = tf.constant(new int[] { 0, 5, 3, 14 });
  14. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  15. var bitwise_and_result = tf.bitwise.bitwise_and(lhs, rhs);
  16. var expected = new int[] { 0, 0, 3, 10 };
  17. var actual = bitwise_and_result.ToArray<int>();
  18. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  19. }
  20. [TestMethod]
  21. public void BitwiseOr()
  22. {
  23. Tensor lhs = tf.constant(new int[] { 0, 5, 3, 14 });
  24. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  25. var bitwise_or_result = tf.bitwise.bitwise_or(lhs, rhs);
  26. var expected = new int[] { 5, 5, 7, 15 };
  27. var actual = bitwise_or_result.ToArray<int>();
  28. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  29. }
  30. [TestMethod]
  31. public void BitwiseXOR()
  32. {
  33. Tensor lhs = tf.constant(new int[] { 0, 5, 3, 14 });
  34. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  35. var bitwise_xor_result = tf.bitwise.bitwise_xor(lhs, rhs);
  36. var expected = new int[] { 5, 5, 4, 5 };
  37. var actual = bitwise_xor_result.ToArray<int>();
  38. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  39. }
  40. [TestMethod]
  41. public void Invert()
  42. {
  43. Tensor lhs = tf.constant(new int[] { 0, 1, -3, int.MaxValue });
  44. var invert_result = tf.bitwise.invert(lhs);
  45. var expected = new int[] { -1, -2, 2, int.MinValue };
  46. var actual = invert_result.ToArray<int>();
  47. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  48. }
  49. [TestMethod]
  50. public void LeftShift()
  51. {
  52. Tensor lhs = tf.constant(new int[] { -1, -5, -3, -14 });
  53. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  54. var left_shift_result = tf.bitwise.left_shift(lhs, rhs);
  55. var expected = new int[] { -32, -5, -384, -28672 };
  56. var actual = left_shift_result.ToArray<int>();
  57. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  58. }
  59. [TestMethod]
  60. public void RightShift()
  61. {
  62. Tensor lhs = tf.constant(new int[] { -2, 64, 101, 32 });
  63. Tensor rhs = tf.constant(new int[] { -1, -5, -3, -14 });
  64. var right_shift_result = tf.bitwise.right_shift(lhs, rhs);
  65. var expected = new int[] { -2, 64, 101, 32 };
  66. var actual = right_shift_result.ToArray<int>();
  67. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  68. }
  69. }
  70. }