def testLt(self): a = Array([1, 2, 3, 4]) b = Array([2, 2, 2, 2]) c = a < b np.testing.assert_array_equal(c.to_numpy(), np.array([True, False, False, False]))
def testNeg(self): a = Array([[1, 2], [3, 4]]) b = -a np.testing.assert_array_equal(b.to_numpy(), np.array([[-1, -2], [-3, -4]]))
def testNot(self): a = Array([True, True, True, False], khiva_type=dtype.b8) b = ~a np.testing.assert_array_equal(b.to_numpy(), np.array([False, False, False, True]))
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 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 testDiv(self): a = Array([1, 2, 3, 4]) b = Array([1, 2, 3, 4]) c = a / b np.testing.assert_array_equal(c.to_numpy(), np.array([1, 1, 1, 1]))
def test_single_value_creation(self): a = Array([1]) np.testing.assert_array_equal(a.dims, np.array([1, 1, 1, 1]))
def testCol(self): a = Array([[1, 3], [2, 4]], dtype.s32) c = a.get_col(0) np.testing.assert_array_equal(c.to_numpy(), np.array([1, 3]))
def testCols(self): a = Array(np.transpose([[1, 2, 3], [4, 5, 6]]), dtype.s32) c = a.get_cols(0, 1) np.testing.assert_array_equal(c.to_numpy(), np.transpose(np.array([[1, 2], [4, 5]])))
def testCtranspose(self): a = Array([[0 - 1j, 4 + 2j], [2 + 1j, 0 - 2j]], khiva_type=dtype.c32) b = a.transpose(True) expected = [[0 + 1j, 2 - 1j], [4 - 2j, 0 + 2j]] np.testing.assert_array_equal(b.to_numpy(), expected)
def testTranspose(self): a = Array([[1, 3], [2, 4]], dtype.s32) c = a.transpose() np.testing.assert_array_equal(c.to_numpy(), np.array([[1, 2], [3, 4]]))
def testOr(self): a = Array([True, True, True, True], dtype.b8) b = Array([True, False, True, False], dtype.b8) c = a | b np.testing.assert_array_equal(c.to_numpy(), np.array([True, True, True, True]))
def testNeq(self): a = Array([1, 2, 3, 4]) b = Array([1, 2, 3, 5]) c = a != b np.testing.assert_array_equal(c.to_numpy(), np.array([False, False, False, True]))
def testGe(self): a = Array([1, 2, 3, 4]) b = Array([2, 2, 2, 2]) c = a >= b np.testing.assert_array_equal(c.to_numpy(), np.array([False, True, True, True]))
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]))
def testRows(self): a = Array(np.transpose([[1, 2], [3, 4], [5, 6]]), dtype.s32) c = a.get_rows(0, 1) np.testing.assert_array_equal(c.to_numpy(), np.transpose(np.array([[1, 2], [3, 4]])))
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 testAs(self): a = Array([1, 2, 3, 4], khiva_type=dtype.s32) b = a.as_type(dtype.u32) expected_data = [1, 2, 3, 4] np.testing.assert_array_equal(b.to_numpy(), expected_data) self.assertEqual(b.khiva_type, dtype.u32)
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 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 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 testFromPandas(self): df = pd.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8]]) df_array = Array(df, khiva_type=dtype.s32) np.testing.assert_array_equal(df.values, df_array.to_pandas().values)
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 testLength(self): a = Array([1, 2, 3, 4]) self.assertEqual(len(a), 4)
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_1d_creation(self): a = Array([1, 5, 3, 1]) np.testing.assert_array_equal(a.dims, np.array([4, 1, 1, 1]))
def test_real_1d(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 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 testStr(self): a = Array([2, 4, 6, 8], dtype.s32) self.assertTrue("khiva.Array()\nType: dtype.s32\nDims: [4 1 1 1]" == str(a))
def testPower(self): a = Array([1, 2, 3, 4]) b = Array([2, 2, 2, 2]) c = a ** b np.testing.assert_array_equal(c.to_numpy(), np.array([1, 4, 9, 16]))