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)
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)
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)
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)
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)
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)
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)
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)
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]))
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)
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)
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)
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)
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]))
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)
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]))
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]))
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]))
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]))
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]))
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]))
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]))