Beispiel #1
0
    def test_delete_registered(self):
        """
        Tests the following:

        1. delete cmd doesn't delete registered objects and returns appropriate message
        2. delete cmd does delete non-registered objects and returns appropriate message
        3. delete cmd raises RuntimeError for unknown symbols
        """
        cleanup()
        a = ak.ones(3, dtype=ak.int64)
        b = ak.ones(3, dtype=ak.int64)

        # registered objects are not deleted from symbol table
        a.register('keep')
        self.assertEqual(ak.client.generic_msg(cmd='delete', args=a.name),
                         f'registered symbol, {a.name}, not deleted')
        self.assertTrue(a.name in ak.list_symbol_table())

        # non-registered objects are deleted from symbol table
        self.assertEqual(ak.client.generic_msg(cmd='delete', args=b.name),
                         'deleted ' + b.name)
        self.assertTrue(b.name not in ak.list_symbol_table())

        # RuntimeError when calling delete on an object not in the symbol table
        with self.assertRaises(RuntimeError):
            ak.client.generic_msg(cmd='delete', args='not_in_table')
Beispiel #2
0
    def testErrorHandling(self):
        # Test NotImplmentedError that prevents pddarray iteration
        with self.assertRaises(NotImplementedError):
            iter(ak.ones(100))

        # Test NotImplmentedError that prevents Strings iteration
        with self.assertRaises(NotImplementedError):
            iter(ak.array(['String {}'.format(i) for i in range(0, 10)]))

        # Test ak,histogram against unsupported dtype
        #with self.assertRaises(ValueError) as cm:
        #    ak.histogram((ak.randint(0, 1, 100, dtype=ak.bool)))
        #self.assertEqual('Error: histogramMsg: bool not implemented',
        #                 cm.exception.args[0])

        with self.assertRaises(RuntimeError) as cm:
            ak.concatenate([ak.array([True]), ak.array([True])]).is_sorted()
        self.assertEqual('Error: reductionMsg: is_sorted bool not implemented',
                         cm.exception.args[0])

        with self.assertRaises(TypeError):
            ak.ones(100).any([0])

        with self.assertRaises(TypeError) as cm:
            ak.unique(list(range(0, 10)))
        self.assertEqual('must be pdarray, Strings, or Categorical {}',
                         cm.exception.args[0])

        with self.assertRaises(RuntimeError) as cm:
            ak.concatenate([ak.ones(100), ak.array([True])])

        self.assertEqual(
            'Error: concatenateMsg: Incompatible arguments: ' +
            'Expected float64 dtype but got bool dtype', cm.exception.args[0])
Beispiel #3
0
 def test_error_handling(self):
     ones = ak.ones(100)
     short_ones = ak.ones(10)
     
     with self.assertRaises(ValueError):
         ak.coargsort([ones, short_ones])
         
     with self.assertRaises(ValueError):
         ak.coargsort([list(range(0,10)), [0]])       
Beispiel #4
0
 def testTo_ndarray(self):
     ones = ak.ones(10)
     n_ones = ones.to_ndarray()
     new_ones = ak.array(n_ones)
     self.assertTrue((ones.to_ndarray() == new_ones.to_ndarray()).all())
     
     empty_ones = ak.ones(0)
     n_empty_ones = empty_ones.to_ndarray()
     new_empty_ones = ak.array(n_empty_ones)
     self.assertTrue((empty_ones.to_ndarray() == new_empty_ones.to_ndarray()).all())
Beispiel #5
0
    def test_error_handling(self):
        ones = ak.ones(100)
        short_ones = ak.ones(10)

        for algo in ak.SortingAlgorithm:
            with self.assertRaises(ValueError):
                ak.coargsort([ones, short_ones], algo)

        for algo in ak.SortingAlgorithm:
            with self.assertRaises(TypeError):
                ak.coargsort([list(range(0, 10)), [0]], algo)
Beispiel #6
0
    def test_double_register(self):
        """
        Tests the case when two objects get registered using the same user_defined_name
        """
        a = ak.ones(3, dtype=ak.int64)
        b = ak.ones(3, dtype=ak.int64)
        b.fill(2)
        a.register("foo")

        with self.assertRaises(RegistrationError, msg="Should raise an Error"):
            b.register("foo")

        # Clean up the registry
        a.unregister()
Beispiel #7
0
    def test_clear(self): 
        '''
        Tests the following:
        
        1. clear() removes server-side pdarrays that are unregistered
        2. Registered pdarrays remain after ak.clear()
        3. All cleared pdarrays throw RuntimeError upon method invocation
        4. Method invocation on registered arrays succeeds after ak.clear()
        '''
        ar_array = self.a_array.register('test_int64_a')
        br_array = self.a_array.register('test_int64_b')
        twos_array = ak.ones(10,dtype=ak.int64).register('twos_array')
        twos_array.fill(2)
        
        g_twos_array = self.a_array + self.b_array
        self.assertTrue((twos_array.to_ndarray() == 
                                     g_twos_array.to_ndarray()).all())

        ak.clear()

        with self.assertRaises(RuntimeError):
            str(self.a_array)

        with self.assertRaises(RuntimeError):
            self.a_array + self.b_array

        g_twos_array = ar_array + br_array
        self.assertTrue((twos_array.to_ndarray() == 
                                       g_twos_array.to_ndarray()).all())
    def test_eros_like(self):
        intZeros = ak.zeros(5, dtype=ak.int64)
        intZerosLike = ak.zeros_like(intZeros)

        self.assertIsInstance(intZerosLike, ak.pdarray)
        self.assertEqual(ak.int64, intZerosLike.dtype)

        floatZeros = ak.ones(5, dtype=ak.float64)
        floatZerosLike = ak.ones_like(floatZeros)

        self.assertEqual(ak.float64, floatZerosLike.dtype)

        boolZeros = ak.ones(5, dtype=ak.bool)
        boolZerosLike = ak.ones_like(boolZeros)

        self.assertEqual(ak.bool, boolZerosLike.dtype)
Beispiel #9
0
 def test_compare_set_slice(self):
     # create np version
     a = np.ones(N)
     a[::2] = a[::2] * -1
     # create ak version
     b = ak.ones(N)
     b[::2] = b[::2] * -1
     self.assertEqual(a.all(), b.to_ndarray().all())
Beispiel #10
0
def check_ones(N):
    # create np version
    a = np.ones(N)
    # create ak version
    b = ak.ones(N)
    # print(a,b)
    c = a == b.to_ndarray()
    # print(type(c),c)
    return pass_fail(c.all())
Beispiel #11
0
    def testPdArrayDivideInt(self):
        aArray = ak.ones(100)
        dArray = aArray * 15 / 3
        self.assertIsInstance(dArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(5), dArray[0])

        dArray = 15 * aArray / 3
        self.assertIsInstance(dArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(5), dArray[0])
Beispiel #12
0
    def testPdArrayMultNumpyInt(self):
        aArray = ak.ones(100)
        mArray = aArray * np.int64(5)
        self.assertIsInstance(mArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(5), mArray[0])

        mArray = np.int64(5) * aArray
        self.assertIsInstance(mArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(5), mArray[0])
Beispiel #13
0
    def testPdArrayAddNumpyInt(self):
        aArray = ak.ones(100)
        addArray = aArray + np.int64(1)
        self.assertIsInstance(addArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(2), addArray[0])

        addArray = np.int64(1) + aArray
        self.assertIsInstance(addArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(2), addArray[0])
Beispiel #14
0
    def testPdArraySubtractNumpyInt(self):
        aArray = ak.ones(100)
        subArray = aArray - np.int64(2)
        self.assertIsInstance(subArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(-1), subArray[0])

        subArray = np.int64(2) - aArray
        self.assertIsInstance(subArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(1), subArray[0])
Beispiel #15
0
    def testPdArrayDivideNumpyInt(self):
        aArray = ak.ones(100)
        dArray = aArray * np.int64(15) / 3
        self.assertIsInstance(dArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(5), dArray[0])

        dArray = np.int64(15) * aArray / 3
        self.assertIsInstance(dArray, ak.pdarrayclass.pdarray)
        self.assertEqual(np.float64(5), dArray[0])
Beispiel #16
0
 def setUp(self):
     ArkoudaTest.setUp(self)
     self.N = 1000
     self.a1 = ak.ones(self.N, dtype=np.int64)
     self.a2 = ak.arange(0, self.N, 1)
     self.t1 = self.a1
     self.t2 = self.a1 * 10
     self.dt = 10
     ak.verbose = False
Beispiel #17
0
def check_set_slice(N):
    # create np version
    a = np.ones(N)
    a[::2] = a[::2] * -1
    # create ak version
    b = ak.ones(N)
    b[::2] = b[::2] * -1
    # print(a,b)
    c = a == b.to_ndarray()
    return pass_fail(c.all())
Beispiel #18
0
    def test_clear(self):
        '''
        Tests the following:
        
        1. clear() removes server-side pdarrays that are unregistered
        2. Registered pdarrays remain after ak.clear()
        3. All cleared pdarrays throw RuntimeError upon method invocation
        4. Method invocation on registered arrays succeeds after ak.clear()
        '''
        ar_array = self.a_array.register('test_int64_a')
        aar_array = self.a_array.register('test_int64_aa')

        self.assertTrue(
            ar_array is aar_array,
            msg="With inplace modification, these should be the same")
        self.assertEqual(
            ar_array.name,
            "test_int64_aa",
            msg="ar_array.name should be updated with inplace modification")

        twos_array = ak.ones(10, dtype=ak.int64).register('twos_array')
        twos_array.fill(2)

        g_twos_array = self.a_array + self.b_array
        self.assertTrue(
            (twos_array.to_ndarray() == g_twos_array.to_ndarray()).all())

        ak.clear()  # This should remove self.b_array and g_twos_array

        with self.assertRaises(
                RuntimeError,
                msg=
                "g_twos_array should have been cleared because it wasn't registered"
        ):
            str(g_twos_array)

        with self.assertRaises(
                RuntimeError,
                msg=
                "self.b_array should have been cleared because it wasn't registered"
        ):
            str(self.b_array)

        # Assert these exist by invoking them and not receiving an exception
        str(self.a_array)
        str(ar_array)

        with self.assertRaises(
                RuntimeError,
                msg="Should raise error because self.b_array was cleared"):
            self.a_array + self.b_array

        g_twos_array = ar_array + aar_array
        self.assertTrue(
            (twos_array.to_ndarray() == g_twos_array.to_ndarray()).all())
Beispiel #19
0
    def testErrorHandling(self):
        # Test NotImplmentedError that prevents pddarray iteration
        with self.assertRaises(NotImplementedError):
            iter(ak.ones(100))

        # Test NotImplmentedError that prevents Strings iteration
        with self.assertRaises(NotImplementedError):
            iter(ak.array(['String {}'.format(i) for i in range(0, 10)]))

        # Test ak,histogram against unsupported dtype
        with self.assertRaises(ValueError):
            ak.histogram((ak.randint(0, 1, 100, dtype=ak.bool)))

        with self.assertRaises(RuntimeError) as cm:
            ak.concatenate([ak.array([True]), ak.array([True])]).is_sorted()
        self.assertEqual('Error: reductionMsg: is_sorted bool not implemented',
                         cm.exception.args[0])

        with self.assertRaises(TypeError):
            ak.ones(100).any([0])
Beispiel #20
0
def check_bool(N):
    a = ak.arange(N)
    b = ak.ones(N)
    try:
        c = a and b
    except ValueError:
        correct = True
    except:
        correct = False
    d = ak.array([1])
    correct = correct and (d and 5)
    return pass_fail(correct)
Beispiel #21
0
 def test_attach_weak_binding(self):
     """
     Ultimately pdarrayclass issues delete calls to the server when a bound object goes out of scope, if you bind
     to a server object more than once and one of those goes out of scope it affects all other references to it.
     """
     cleanup()
     a = ak.ones(3, dtype=ak.int64).register("a_reg")
     self.assertTrue(str(a), "Expected to pass")
     b = ak.attach_pdarray("a_reg")
     b.unregister()
     b = None  # Force out of scope
     with self.assertRaises(RuntimeError):
         str(a)
Beispiel #22
0
    def test_is_registered(self):
        """
        Tests the pdarray.is_registered() function
        """
        cleanup()
        a = ak.ones(10, dtype=ak.int64)
        self.assertFalse(a.is_registered())

        a.register('keep')
        self.assertTrue(a.is_registered())

        a.unregister()
        self.assertFalse(a.is_registered())
        ak.clear()
    def test_fill(self):
        ones = ak.ones(100)

        ones.fill(2)
        self.assertTrue((2 == ones.to_ndarray()).all())

        ones.fill(np.int64(2))
        self.assertTrue((np.int64(2) == ones.to_ndarray()).all())

        ones.fill(np.float(2))
        self.assertTrue((float(2) == ones.to_ndarray()).all())

        ones.fill(np.float64(2))
        self.assertTrue((np.float64(2) == ones.to_ndarray()).all())
Beispiel #24
0
def run_test() -> int:
    a = ak.ones(SIZE, dtype=ak.float64)
    b = ak.ones(SIZE, dtype=ak.int64)
    d = ak.register_pda(a, 'test_float64')
    e = ak.register_pda(b, 'test_int64')
    ak.clear()

    # will get decremented to 0 if test is successful
    result = 2

    try:
        a + b
    except:
        result -= 1

    try:
        d + e
        result -= 1
    except:
        result = 100

    ak.unregister_pda(d)
    ak.unregister_pda(e)
    return result
Beispiel #25
0
    def test_error_handling(self):
        with self.assertRaises(RuntimeError) as cm:
            ak.concatenate([ak.ones(100), ak.array([True])])

        self.assertEqual(
            'Error: concatenateMsg: Incompatible arguments: ' +
            'Expected float64 dtype but got bool dtype', cm.exception.args[0])

        with self.assertRaises(TypeError):
            ak.union1d([-1, 0, 1], [-2, 0, 2])

        with self.assertRaises(RuntimeError) as cm:
            ak.cos(ak.randint(0, 1, 100, dtype=ak.bool))
        self.assertEqual('Error: efuncMsg: cos bool not implemented',
                         cm.exception.args[0])
Beispiel #26
0
 def test_get_mem_used(self):
     '''
     Tests the ak.client.get_mem_used method
     
     :return: None
     :raise: AssertionError if one or more ak.get_mem_used values are not as 
             expected or the call to ak.client.get_mem_used() fails 
     '''
     try:
         config = ak.client.get_config()
         a = ak.ones(1024 * 1024 * config['numLocales'])
         mem_used = ak.client.get_mem_used()
     except Exception as e:
         raise AssertionError(e)
     self.assertTrue(mem_used > 0)
Beispiel #27
0
    def test_list_registry(self):
        """
        Tests the generic ak.list_registry() function
        """
        cleanup()
        # Test list_registry when the symbol table is empty
        self.assertFalse(ak.list_registry(), "registry should be empty")

        a = ak.ones(10, dtype=ak.int64)
        # list_registry() should return an empty list which is implicitly False
        self.assertFalse(ak.list_registry())

        a.register('keep')
        self.assertTrue('keep' in ak.list_registry())
        cleanup()
Beispiel #28
0
    def test_in_place_info(self):
        """
        Tests the class level info method for pdarray, String, and Categorical
        """
        cleanup()
        my_pda = ak.ones(10, ak.int64)
        self.assertFalse(
            any([sym['registered'] for sym in json.loads(my_pda.info())]),
            msg=
            'no components of my_pda should be registered before register call'
        )
        my_pda.register('my_pda')
        self.assertTrue(
            all([sym['registered'] for sym in json.loads(my_pda.info())]),
            msg=
            'all components of my_pda should be registered after register call'
        )

        my_str = ak.random_strings_uniform(1,
                                           10,
                                           UNIQUE,
                                           characters='printable')
        self.assertFalse(
            any([sym['registered'] for sym in json.loads(my_str.info())]),
            msg=
            'no components of my_str should be registered before register call'
        )
        my_str.register('my_str')
        self.assertTrue(
            all([sym['registered'] for sym in json.loads(my_str.info())]),
            msg=
            'all components of my_str should be registered after register call'
        )

        my_cat = ak.Categorical(ak.array([f"my_cat {i}"
                                          for i in range(1, 11)]))
        self.assertFalse(
            any([sym['registered'] for sym in json.loads(my_cat.info())]),
            msg=
            'no components of my_cat should be registered before register call'
        )
        my_cat.register('my_cat')
        self.assertTrue(
            all([sym['registered'] for sym in json.loads(my_cat.info())]),
            msg=
            'all components of my_cat should be registered after register call'
        )
        cleanup()
Beispiel #29
0
    def testValueCounts(self):
        pda = ak.ones(100, dtype=ak.int64)
        result = ak.value_counts(pda)
        self.assertEqual(ak.array([1]), result[0])
        self.assertEqual(ak.array([100]), result[1])

        pda = ak.linspace(1, 10, 10)
        with self.assertRaises(RuntimeError) as cm:
            ak.value_counts(pda)
        self.assertEqual('Error: unique: float64 not implemented',
                         cm.exception.args[0])

        with self.assertRaises(TypeError) as cm:
            ak.value_counts([0])
        self.assertEqual(
            'type of argument "pda" must be arkouda.pdarrayclass.pdarray; got list instead',
            cm.exception.args[0])
Beispiel #30
0
    def testOnes(self):
        intOnes = ak.ones(5, dtype=ak.int64)
        self.assertIsInstance(intOnes, ak.pdarray)
        self.assertEqual(ak.int64, intOnes.dtype)

        floatOnes = ak.ones(5, dtype=ak.float64)
        self.assertEqual(ak.float64, floatOnes.dtype)

        boolOnes = ak.ones(5, dtype=ak.bool)
        self.assertEqual(ak.bool, boolOnes.dtype)

        ones = ak.ones('5')
        self.assertEqual(5, len(ones))

        with self.assertRaises(TypeError) as cm:
            ak.ones(5, dtype=ak.uint8)
        self.assertEqual('unsupported dtype uint8', cm.exception.args[0])

        with self.assertRaises(TypeError) as cm:
            ak.ones(5, dtype=str)
        self.assertEqual('unsupported dtype <U0', cm.exception.args[0])