Example #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]))
Example #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]]))
Example #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]))
Example #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]))
Example #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]))
Example #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]))
Example #7
0
 def test_single_value_creation(self):
     a = Array([1])
     np.testing.assert_array_equal(a.dims, np.array([1, 1, 1, 1]))
Example #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]))
Example #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]])))
Example #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)
Example #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]]))
Example #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]))
Example #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]))
Example #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]))
Example #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]))
Example #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]])))
Example #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]))
Example #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)
Example #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]))
Example #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)
Example #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]))
Example #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)
Example #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]))
Example #24
0
 def testLength(self):
     a = Array([1, 2, 3, 4])
     self.assertEqual(len(a), 4)
Example #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]))
Example #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]))
Example #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)
Example #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]))
Example #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))
Example #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]))