Esempio n. 1
0
 def push(self, *args):
     if len(args) == 0:
         args = self._data.keys()
     for arg in args:
         dev_arr = array.to_device(self._get_array(
             self._get_prop_or_const(arg)),
                                   backend=self.backend)
         self._data[arg].set_data(dev_arr)
         setattr(self, arg, self._data[arg])
Esempio n. 2
0
    def test_remove_particles(self, backend):
        check_import(backend)
        self.setup()
        # Given
        pa = self.pa
        h = DeviceHelper(pa, backend=backend)

        # When
        pa.set_device_helper(h)
        h.resize(4)
        h.x.set(np.array([2.0, 3.0, 4.0, 5.0], h.x.dtype))

        indices = np.array([1, 2], dtype=np.uint32)
        indices = array.to_device(indices, backend=backend)

        h.remove_particles(indices)

        # Then
        assert np.all(np.sort(h.x.get()) == np.array([2., 5.]))
Esempio n. 3
0
    def test_extract_particles(self, backend):
        check_import(backend)
        self.setup()
        # Given
        pa = get_particle_array(name='f',
                                x=[0.0, 1.0, 2.0, 3.0],
                                m=1.0,
                                rho=2.0)
        h = DeviceHelper(pa, backend=backend)
        pa.set_device_helper(h)

        # When
        indices = np.array([1, 2], dtype=np.uint32)
        indices = array.to_device(indices, backend=backend)

        result_pa = h.empty_clone()
        h.extract_particles(indices, result_pa)

        # Then
        assert result_pa.gpu.get_number_of_particles() == 2