Ejemplo n.º 1
0
 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]))
Ejemplo n.º 2
0
 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]]))
Ejemplo n.º 3
0
 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]))
Ejemplo n.º 4
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.º 5
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.º 6
0
 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]))
Ejemplo n.º 7
0
 def test_single_value_creation(self):
     a = Array([1])
     np.testing.assert_array_equal(a.dims, np.array([1, 1, 1, 1]))
Ejemplo n.º 8
0
 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]))
Ejemplo n.º 9
0
 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]])))
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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]]))
Ejemplo n.º 12
0
 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]))
Ejemplo n.º 13
0
 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]))
Ejemplo n.º 14
0
 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]))
Ejemplo n.º 15
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]))
Ejemplo n.º 16
0
 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]])))
Ejemplo n.º 17
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.º 18
0
 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)
Ejemplo n.º 19
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.º 20
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.º 21
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.º 22
0
 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)
Ejemplo n.º 23
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.º 24
0
 def testLength(self):
     a = Array([1, 2, 3, 4])
     self.assertEqual(len(a), 4)
Ejemplo n.º 25
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.º 26
0
 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]))
Ejemplo n.º 27
0
 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)
Ejemplo n.º 28
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.º 29
0
 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))
Ejemplo n.º 30
0
 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]))