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.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 : EagerModeTestBase
  9. {
  10. [TestInitialize]
  11. public void Init()
  12. {
  13. tf.enable_eager_execution();
  14. }
  15. [TestMethod]
  16. public void BitwiseAnd()
  17. {
  18. Tensor lhs = tf.constant(new int[] { 0, 5, 3, 14 });
  19. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  20. var bitwise_and_result = tf.bitwise.bitwise_and(lhs, rhs);
  21. var expected = new int[] { 0, 0, 3, 10 };
  22. var actual = bitwise_and_result.ToArray<int>();
  23. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  24. }
  25. [TestMethod]
  26. public void BitwiseOr()
  27. {
  28. Tensor lhs = tf.constant(new int[] { 0, 5, 3, 14 });
  29. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  30. var bitwise_or_result = tf.bitwise.bitwise_or(lhs, rhs);
  31. var expected = new int[] { 5, 5, 7, 15 };
  32. var actual = bitwise_or_result.ToArray<int>();
  33. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  34. }
  35. [TestMethod]
  36. public void BitwiseXOR()
  37. {
  38. Tensor lhs = tf.constant(new int[] { 0, 5, 3, 14 });
  39. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  40. var bitwise_xor_result = tf.bitwise.bitwise_xor(lhs, rhs);
  41. var expected = new int[] { 5, 5, 4, 5 };
  42. var actual = bitwise_xor_result.ToArray<int>();
  43. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  44. }
  45. [TestMethod]
  46. public void Invert()
  47. {
  48. Tensor lhs = tf.constant(new int[] { 0, 1, -3, int.MaxValue });
  49. var invert_result = tf.bitwise.invert(lhs);
  50. var expected = new int[] { -1, -2, 2, int.MinValue };
  51. var actual = invert_result.ToArray<int>();
  52. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  53. }
  54. [TestMethod]
  55. public void LeftShift()
  56. {
  57. Tensor lhs = tf.constant(new int[] { -1, -5, -3, -14 });
  58. Tensor rhs = tf.constant(new int[] { 5, 0, 7, 11 });
  59. var left_shift_result = tf.bitwise.left_shift(lhs, rhs);
  60. var expected = new int[] { -32, -5, -384, -28672 };
  61. var actual = left_shift_result.ToArray<int>();
  62. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  63. }
  64. [TestMethod]
  65. public void RightShift()
  66. {
  67. Tensor lhs = tf.constant(new int[] { -2, 64, 101, 32 });
  68. Tensor rhs = tf.constant(new int[] { -1, -5, -3, -14 });
  69. var right_shift_result = tf.bitwise.right_shift(lhs, rhs);
  70. var expected = new int[] { -2, 64, 101, 32 };
  71. var actual = right_shift_result.ToArray<int>();
  72. Assert.IsTrue(Enumerable.SequenceEqual(expected, actual));
  73. }
  74. }
  75. }