diff --git a/kernels/test/op_bitwise_and_test.cpp b/kernels/test/op_bitwise_and_test.cpp index 3bf1742bba..be9f69e32f 100644 --- a/kernels/test/op_bitwise_and_test.cpp +++ b/kernels/test/op_bitwise_and_test.cpp @@ -20,19 +20,83 @@ using exec_aten::ScalarType; using exec_aten::Tensor; using torch::executor::testing::TensorFactory; -class OpwiseBitwiseAndTest : public OperatorTest { +class OpBitwiseAndTensorOutTest : public OperatorTest { protected: - Tensor& op_bitwise_and_scalar_out( + Tensor& op_bitwise_and_tensor_out( const Tensor& self, - const Scalar& other, + const Tensor& other, Tensor& out) { return torch::executor::aten::bitwise_and_outf(context_, self, other, out); } +}; - Tensor& op_bitwise_and_tensor_out( +class OpBitwiseAndScalarOutTest : public OperatorTest { + protected: + Tensor& op_bitwise_and_scalar_out( const Tensor& self, - const Tensor& other, + const Scalar& other, Tensor& out) { return torch::executor::aten::bitwise_and_outf(context_, self, other, out); } }; + +TEST_F(OpBitwiseAndTensorOutTest, SmokeTestInt) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {2, 3, 2, 5}); + Tensor b = tf.make({2, 2}, {1, 6, 2, 3}); + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_and_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {0, 2, 2, 1})); +} + +TEST_F(OpBitwiseAndTensorOutTest, SmokeTestBool) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {true, false, true, false}); + Tensor b = tf.make({2, 2}, {true, true, false, false}); + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_and_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {true, false, false, false})); +} + +TEST_F(OpBitwiseAndTensorOutTest, SmokeTestMixed) { + TensorFactory tfInt; + TensorFactory tfBool; + + Tensor a = tfInt.make({2, 2}, {2, 3, 2, 5}); + Tensor b = tfBool.make({2, 2}, {true, true, false, false}); + + Tensor out = tfInt.zeros({2, 2}); + + op_bitwise_and_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tfInt.make({2, 2}, {0, 1, 0, 0})); +} + +TEST_F(OpBitwiseAndScalarOutTest, SmokeTestInt) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {2, 3, 2, 5}); + Scalar b = 6; + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_and_scalar_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {2, 2, 2, 4})); +} + +TEST_F(OpBitwiseAndScalarOutTest, SmokeTestBool) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {true, false, true, false}); + Scalar b = true; + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_and_scalar_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {true, false, true, false})); +} diff --git a/kernels/test/op_bitwise_or_test.cpp b/kernels/test/op_bitwise_or_test.cpp index 7d84d16318..f2c52ff7a7 100644 --- a/kernels/test/op_bitwise_or_test.cpp +++ b/kernels/test/op_bitwise_or_test.cpp @@ -20,19 +20,83 @@ using exec_aten::ScalarType; using exec_aten::Tensor; using torch::executor::testing::TensorFactory; -class OpBitwiseOrTest : public OperatorTest { +class OpBitwiseOrTensorOutTest : public OperatorTest { protected: - Tensor& op_bitwise_or_scalar_out( + Tensor& op_bitwise_or_tensor_out( const Tensor& self, - const Scalar& other, + const Tensor& other, Tensor& out) { return torch::executor::aten::bitwise_or_outf(context_, self, other, out); } +}; - Tensor& op_bitwise_or_tensor_out( +class OpBitwiseOrScalarOutTest : public OperatorTest { + protected: + Tensor& op_bitwise_or_scalar_out( const Tensor& self, - const Tensor& other, + const Scalar& other, Tensor& out) { return torch::executor::aten::bitwise_or_outf(context_, self, other, out); } }; + +TEST_F(OpBitwiseOrTensorOutTest, SmokeTestInt) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {2, 3, 2, 5}); + Tensor b = tf.make({2, 2}, {1, 6, 2, 3}); + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_or_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {3, 7, 2, 7})); +} + +TEST_F(OpBitwiseOrTensorOutTest, SmokeTestBool) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {true, false, true, false}); + Tensor b = tf.make({2, 2}, {true, true, false, false}); + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_or_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {true, true, true, false})); +} + +TEST_F(OpBitwiseOrTensorOutTest, SmokeTestMixed) { + TensorFactory tfInt; + TensorFactory tfBool; + + Tensor a = tfInt.make({2, 2}, {2, 3, 2, 5}); + Tensor b = tfBool.make({2, 2}, {true, true, false, false}); + + Tensor out = tfInt.zeros({2, 2}); + + op_bitwise_or_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tfInt.make({2, 2}, {3, 3, 2, 5})); +} + +TEST_F(OpBitwiseOrScalarOutTest, SmokeTestInt) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {2, 3, 2, 5}); + Scalar b = 6; + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_or_scalar_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {6, 7, 6, 7})); +} + +TEST_F(OpBitwiseOrScalarOutTest, SmokeTestBool) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {true, false, true, false}); + Scalar b = true; + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_or_scalar_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {true, true, true, true})); +} diff --git a/kernels/test/op_bitwise_xor_test.cpp b/kernels/test/op_bitwise_xor_test.cpp index 234fd33850..5da260dc74 100644 --- a/kernels/test/op_bitwise_xor_test.cpp +++ b/kernels/test/op_bitwise_xor_test.cpp @@ -20,19 +20,83 @@ using exec_aten::ScalarType; using exec_aten::Tensor; using torch::executor::testing::TensorFactory; -class OpBitwiseOrTest : public OperatorTest { +class OpBitwiseXorTensorOutTest : public OperatorTest { protected: - Tensor& op_bitwise_xor_scalar_out( + Tensor& op_bitwise_xor_tensor_out( const Tensor& self, - const Scalar& other, + const Tensor& other, Tensor& out) { return torch::executor::aten::bitwise_xor_outf(context_, self, other, out); } +}; - Tensor& op_bitwise_xor_tensor_out( +class OpBitwiseXorScalarOutTest : public OperatorTest { + protected: + Tensor& op_bitwise_xor_scalar_out( const Tensor& self, - const Tensor& other, + const Scalar& other, Tensor& out) { return torch::executor::aten::bitwise_xor_outf(context_, self, other, out); } }; + +TEST_F(OpBitwiseXorTensorOutTest, SmokeTestInt) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {2, 3, 2, 5}); + Tensor b = tf.make({2, 2}, {1, 6, 2, 3}); + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_xor_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {3, 5, 0, 6})); +} + +TEST_F(OpBitwiseXorTensorOutTest, SmokeTestBool) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {true, false, true, false}); + Tensor b = tf.make({2, 2}, {true, true, false, false}); + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_xor_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {false, true, true, false})); +} + +TEST_F(OpBitwiseXorTensorOutTest, SmokeTestMixed) { + TensorFactory tfInt; + TensorFactory tfBool; + + Tensor a = tfInt.make({2, 2}, {2, 3, 2, 5}); + Tensor b = tfBool.make({2, 2}, {true, true, false, false}); + + Tensor out = tfInt.zeros({2, 2}); + + op_bitwise_xor_tensor_out(a, b, out); + EXPECT_TENSOR_EQ(out, tfInt.make({2, 2}, {3, 2, 2, 5})); +} + +TEST_F(OpBitwiseXorScalarOutTest, SmokeTestInt) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {2, 3, 2, 5}); + Scalar b = 6; + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_xor_scalar_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {4, 5, 4, 3})); +} + +TEST_F(OpBitwiseXorScalarOutTest, SmokeTestBool) { + TensorFactory tf; + + Tensor a = tf.make({2, 2}, {true, false, true, false}); + Scalar b = true; + + Tensor out = tf.zeros({2, 2}); + + op_bitwise_xor_scalar_out(a, b, out); + EXPECT_TENSOR_EQ(out, tf.make({2, 2}, {false, true, false, true})); +}