Exemplo n.º 1
0
    def test_xor(self):
        int16_tensor = ht.array([[1, 1], [2, 2]], dtype=ht.int16)
        int16_vector = ht.array([[3, 4]], dtype=ht.int16)

        self.assertTrue(
            ht.equal(int16_tensor ^ int16_vector, ht.bitwise_xor(int16_tensor, int16_vector))
        )
Exemplo n.º 2
0
    def test_bitwise_xor(self):
        an_int_tensor = ht.array([[1, 2], [3, 4]])
        an_int_vector = ht.array([2, 2])
        another_int_vector = ht.array([2, 2, 2, 2])
        int_result = ht.array([[3, 0], [1, 6]])

        a_boolean_vector = ht.array([False, True, False, True])
        another_boolean_vector = ht.array([False, False, True, True])
        boolean_result = ht.array([False, True, True, False])

        self.assertTrue(
            ht.equal(ht.bitwise_xor(an_int_tensor, self.an_int_scalar),
                     int_result))
        self.assertTrue(
            ht.equal(ht.bitwise_xor(an_int_tensor, an_int_vector), int_result))
        self.assertTrue(
            ht.equal(ht.bitwise_xor(a_boolean_vector, another_boolean_vector),
                     boolean_result))
        self.assertTrue(
            ht.equal(
                ht.bitwise_xor(an_int_tensor.copy().resplit_(0),
                               an_int_vector), int_result))

        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.a_tensor, self.another_tensor)
        with self.assertRaises(ValueError):
            ht.bitwise_xor(an_int_vector, another_int_vector)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.a_tensor, self.erroneous_type)
        with self.assertRaises(TypeError):
            ht.bitwise_xor("T", "s")
        with self.assertRaises(TypeError):
            ht.bitwise_xor(an_int_tensor, "s")
        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.an_int_scalar, "s")
        with self.assertRaises(TypeError):
            ht.bitwise_xor("s", self.an_int_scalar)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.an_int_scalar, self.a_scalar)
Exemplo n.º 3
0
    def test_bitwise_xor(self):
        an_int_tensor = ht.array([[1, 2], [3, 4]], device=ht_device)
        an_int_vector = ht.array([2, 2], device=ht_device)
        another_int_vector = ht.array([2, 2, 2, 2], device=ht_device)

        int_result = ht.array([[3, 0], [1, 6]], device=ht_device)

        int16_result = ht.array([[0, 2], [2, 0]],
                                dtype=ht.int16,
                                device=ht_device)

        a_boolean_vector = ht.array([False, True, False, True],
                                    device=ht_device)
        another_boolean_vector = ht.array([False, False, True, True],
                                          device=ht_device)
        boolean_result = ht.array([False, True, True, False], device=ht_device)

        self.assertTrue(
            ht.equal(ht.bitwise_xor(an_int_tensor, self.an_int_scalar),
                     int_result))
        self.assertTrue(
            ht.equal(ht.bitwise_xor(an_int_tensor, an_int_vector), int_result))
        self.assertTrue(
            ht.equal(ht.bitwise_xor(a_boolean_vector, another_boolean_vector),
                     boolean_result))

        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.a_tensor, self.another_tensor)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(another_int_vector, a_boolean_vector)
        with self.assertRaises(ValueError):
            ht.bitwise_xor(an_int_vector, another_int_vector)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.a_tensor, self.errorneous_type)
        with self.assertRaises(TypeError):
            ht.bitwise_xor("T", "s")
        with self.assertRaises(TypeError):
            ht.bitwise_xor(an_int_tensor, "s")
        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.an_int_scalar, "s")
        with self.assertRaises(TypeError):
            ht.bitwise_xor("s", self.an_int_scalar)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(self.an_int_scalar, self.a_scalar)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(int_result, int16_result)
        with self.assertRaises(NotImplementedError):
            ht.bitwise_xor([1], 2)
        with self.assertRaises(TypeError):
            ht.bitwise_xor(1, [2])