Ejemplo n.º 1
0
 def test_complex64_2d(self):
     a = Array(
         np.array([[1 + 5j, 2 + 6j, 3 + 7j, 4 + 8j], [9 + 13j, 10 + 14j, 11 + 15j, 12 + 16j]]).astype(np.complex64),
         khiva_type=dtype.c32)
     expected = np.array([[1 + 5j, 2 + 6j, 3 + 7j, 4 + 8j], [9 + 13j, 10 + 14j, 11 + 15j, 12 + 16j]]).astype(
         np.complex64)
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 2
0
 def test_complex64_3d(self):
     a = Array(
         np.array([[[1 + 1j, 5 + 5j], [2 + 2j, 6 + 6j]], [[3 + 3j, 7 + 7j], [4 + 4j, 8 + 8j]]]).astype(np.complex64),
         khiva_type=dtype.c32)
     expected = np.array([[[1 + 1j, 5 + 5j], [2 + 2j, 6 + 6j]], [[3 + 3j, 7 + 7j], [4 + 4j, 8 + 8j]]]).astype(
         np.complex64)
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 3
0
 def test_complex128_1d(self):
     a = Array(np.array([1 + 5j, 2 + 6j, 3 + 7j,
                         4 + 8j]).astype(np.complex128),
               khiva_type=dtype.c64)
     expected = np.array([1 + 5j, 2 + 6j, 3 + 7j,
                          4 + 8j]).astype(np.complex128)
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 4
0
 def test_decimal_scaling_norm_in_place(self):
     tss = Array([[0, 1, -2, 3], [40, 50, 60, -70]])
     decimal_scaling_norm_in_place(tss)
     tss = tss.to_numpy()
     expected = np.array([[0.0, 0.1, -0.2, 0.3], [0.4, 0.5, 0.6, -0.7]])
     np.testing.assert_array_almost_equal(tss,
                                          expected,
                                          decimal=self.DECIMAL)
Ejemplo n.º 5
0
 def test_mean_norm_in_place(self):
     a = Array([[0, 1, 2, 3], [4, 5, 6, 7]])
     mean_norm_in_place(a)
     expected = np.array([[-0.5, -0.166666667, 0.166666667, 0.5],
                          [-0.5, -0.166666667, 0.166666667, 0.5]])
     np.testing.assert_array_almost_equal(a.to_numpy(),
                                          expected,
                                          decimal=self.DECIMAL)
Ejemplo n.º 6
0
 def test_max_min_norm_in_place(self):
     tss = Array([[0, 1, 2, 3], [4, 5, 6, 7]])
     max_min_norm_in_place(tss, 2.0, 1.0)
     tss = tss.to_numpy()
     expected = np.array([[1.0, 1.3333333333333, 1.66666667, 2.0],
                          [1.0, 1.3333333333333, 1.66666667, 2.0]])
     np.testing.assert_array_almost_equal(tss,
                                          expected,
                                          decimal=self.DECIMAL)
Ejemplo n.º 7
0
 def test_complex64_4d(self):
     a = Array(
         np.array([[[[1 + 1j, 9 + 9j], [2 + 2j, 10 + 10j]], [[3 + 3j, 11 + 11j], [4 + 4j, 12 + 12j]]],
                   [[[5 + 5j, 13 + 13j], [6 + 6j, 14 + 14j]], [[7 + 7j, 15 + 15j], [8 + 8j, 16 + 16j]]]])
             .astype(np.complex64),
         khiva_type=dtype.c32)
     expected = np.array([[[[1 + 1j, 9 + 9j], [2 + 2j, 10 + 10j]], [[3 + 3j, 11 + 11j], [4 + 4j, 12 + 12j]]],
                          [[[5 + 5j, 13 + 13j], [6 + 6j, 14 + 14j]],
                           [[7 + 7j, 15 + 15j], [8 + 8j, 16 + 16j]]]]).astype(
         np.complex64)
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 8
0
    def test_znorm_in_place(self):
        tss = Array(data=[[0, 1, 2, 3], [4, 5, 6, 7]])
        znorm_in_place(tss)
        tss = tss.to_numpy()
        self.assertAlmostEqual(tss[0][0], -1.341640786499870, delta=self.DELTA)
        self.assertAlmostEqual(tss[0][1], -0.447213595499958, delta=self.DELTA)
        self.assertAlmostEqual(tss[0][2], 0.447213595499958, delta=self.DELTA)
        self.assertAlmostEqual(tss[0][3], 1.341640786499870, delta=self.DELTA)

        self.assertAlmostEqual(tss[1][0], -1.341640786499870, delta=self.DELTA)
        self.assertAlmostEqual(tss[1][1], -0.447213595499958, delta=self.DELTA)
        self.assertAlmostEqual(tss[1][2], 0.447213595499958, delta=self.DELTA)
        self.assertAlmostEqual(tss[1][3], 1.341640786499870, delta=self.DELTA)
Ejemplo n.º 9
0
 def testIOr(self):
     a = Array([1, 1, 1, 1], khiva_type=dtype.b8)
     b = Array([1, 0, 1, 0], khiva_type=dtype.b8)
     a |= b
     np.testing.assert_array_equal(a.to_numpy(), np.array([1, 1, 1, 1]))
Ejemplo n.º 10
0
 def test_real_4d(self):
     a = Array([[[[1, 9], [2, 10]], [[3, 11], [4, 12]]], [[[5, 13], [6, 14]], [[7, 15], [8, 16]]]])
     expected = np.array([[[[1, 9], [2, 10]], [[3, 11], [4, 12]]], [[[5, 13], [6, 14]], [[7, 15], [8, 16]]]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 11
0
 def testCopy(self):
     a = Array([1, 2, 3, 4], khiva_type=dtype.s32)
     b = a.copy()
     np.testing.assert_array_equal(a.to_numpy(), b.to_numpy())
     self.assertEqual(b.khiva_type, b.khiva_type)
Ejemplo n.º 12
0
 def test_real_3d(self):
     a = Array([[[1, 5], [2, 6]], [[3, 7], [4, 8]]])
     expected = np.array([[[1, 5], [2, 6]], [[3, 7], [4, 8]]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 13
0
 def test_real_3d_large_column(self):
     a = Array([[[1, 5, 3], [2, 6, 9]], [[3, 7, 4], [4, 8, 1]]])
     expected = np.array([[[1, 5, 3], [2, 6, 9]], [[3, 7, 4], [4, 8, 1]]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 14
0
 def testBitsra(self):
     a = Array([2, 4, 6, 8], dtype.s32)
     a <<= 1
     np.testing.assert_array_equal(a.to_numpy(), np.array([4, 8, 12, 16]))
Ejemplo n.º 15
0
 def test_real_2d(self):
     a = Array([[1, 2, 3, 4], [5, 6, 7, 8]])
     expected = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
     np.testing.assert_array_equal(a.to_numpy(), expected)
Ejemplo n.º 16
0
 def testXor(self):
     a = Array([True, True, True, True], dtype.b8)
     b = Array([True, False, True, False], dtype.b8)
     a ^= b
     np.testing.assert_array_equal(a.to_numpy(), np.array([False, True, False, True]))
Ejemplo n.º 17
0
 def testBitshift(self):
     a = Array([2, 4, 6, 8], dtype.s32)
     a >>= 1
     np.testing.assert_array_equal(a.to_numpy(), np.array([1, 2, 3, 4]))
Ejemplo n.º 18
0
 def testIadd(self):
     a = Array([1, 2, 3, 4])
     b = Array([1, 2, 3, 4])
     a += b
     np.testing.assert_array_equal(a.to_numpy(), np.array([2, 4, 6, 8]))
Ejemplo n.º 19
0
 def testIPow(self):
     a = Array([1, 2, 3, 4])
     b = Array([2, 2, 2, 2])
     a **= b
     np.testing.assert_array_equal(a.to_numpy(), np.array([1, 4, 9, 16]))
Ejemplo n.º 20
0
 def testMod(self):
     a = Array([1, 2, 3, 4])
     b = Array([1, 2, 3, 4])
     a %= b
     np.testing.assert_array_equal(a.to_numpy(), np.array([0, 0, 0, 0]))
Ejemplo n.º 21
0
 def testITrueDiv(self):
     a = Array([1, 2, 3, 4])
     b = Array([1, 2, 3, 4])
     a /= b
     np.testing.assert_array_equal(a.to_numpy(), np.array([1, 1, 1, 1]))
Ejemplo n.º 22
0
 def testIaddSelfArray(self):
     a = Array([1, 2, 3, 4, 5])
     a += a
     np.testing.assert_array_equal(a.to_numpy(), np.array([2, 4, 6, 8, 10]))