def test_sort_by_keys(backend): check_import(backend) # Given dev_array = make_dev_array(backend) # When out_array = array.sort_by_keys([dev_array])[0] # Then assert np.all(out_array.get() == np.sort(dev_array.get()))
def build(self): self.reset_arrays() self.fill_keys(self.x, self.y, self.h, self.qmax, self.indices, self.keys) self.sorted_keys, self.sorted_indices = carr.sort_by_keys( [self.keys, self.indices], key_bits=self.max_bits, backend=self.backend) self.scan_keys(keys=self.sorted_keys, start_indices=self.start_indices) self.fill_bin_counts(self.sorted_keys, self.start_indices, self.bin_counts, self.num_particles)
def test_sort_by_keys_with_output(backend): check_import(backend) # Given nparr1 = np.random.randint(0, 100, 16, dtype=np.int32) nparr2 = np.random.randint(0, 100, 16, dtype=np.int32) dev_array1, dev_array2 = array.wrap(nparr1, nparr2, backend=backend) out_arrays = [array.zeros_like(dev_array1), array.zeros_like(dev_array2)] # When array.sort_by_keys([dev_array1, dev_array2], out_list=out_arrays, use_radix_sort=False) # Then order = np.argsort(nparr1) act_result1 = np.take(nparr1, order) act_result2 = np.take(nparr2, order) assert np.all(out_arrays[0].get() == act_result1) assert np.all(out_arrays[1].get() == act_result2)
def test_sort_by_keys(backend): check_import(backend) # Given nparr1 = np.random.randint(0, 100, 16, dtype=np.int32) nparr2 = np.random.randint(0, 100, 16, dtype=np.int32) dev_array1, dev_array2 = array.wrap(nparr1, nparr2, backend=backend) # When out_array1, out_array2 = array.sort_by_keys([dev_array1, dev_array2]) # Then order = np.argsort(nparr1) act_result1 = np.take(nparr1, order) act_result2 = np.take(nparr2, order) assert np.all(out_array1.get() == act_result1) assert np.all(out_array2.get() == act_result2)
def test_radix_sort_by_keys(): backend = 'cython' for use_openmp in [True, False]: get_config().use_openmp = use_openmp # Given nparr1 = np.random.randint(0, 100, 16, dtype=np.int32) nparr2 = np.random.randint(0, 100, 16, dtype=np.int32) dev_array1, dev_array2 = array.wrap(nparr1, nparr2, backend=backend) # When out_array1, out_array2 = array.sort_by_keys([dev_array1, dev_array2], use_radix_sort=True) # Then order = np.argsort(nparr1) act_result1 = np.take(nparr1, order) act_result2 = np.take(nparr2, order) assert np.all(out_array1.get() == act_result1) assert np.all(out_array2.get() == act_result2) get_config().use_openmp = False