def test_align(self, backend): check_import(backend) self.setup() # Given pa = self.pa pa.add_property('force', stride=3) h = DeviceHelper(pa, backend=backend) # When pa.set_device_helper(h) n = 5 h.resize(n) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) h.force.set(np.arange(n * 3, dtype=h.force.dtype)) indices = array.arange(4, -1, -1, dtype=np.int32, backend=backend) h.align(indices) # Then assert np.all(h.x.get() == np.array([6., 5., 4., 3., 2.])) x = np.arange(n * 3) x.shape = (n, 3) expect = x[::-1, :].ravel() assert np.all(h.force.get() == expect)
def test_align(self, backend): check_import(backend) self.setup() # Given pa = self.pa h = DeviceHelper(pa, backend=backend) # When pa.set_device_helper(h) h.resize(5) h.x.set(np.array([2.0, 3.0, 4.0, 5.0, 6.0], h.x.dtype)) indices = array.arange(4, -1, -1, dtype=np.int32, backend=backend) h.align(indices) # Then assert np.all(h.x.get() == np.array([6., 5., 4., 3., 2.]))