Example #1
0
    def run(self):
        """
        Run the algorithm, which computes and returns the grid in C_CONTIGUOUS order partitioned by ranks.
        """
        from nbodykit import measurestats

        if self.comm.rank == 0:
            self.logger.info('importing done')
            self.logger.info('Resolution Nmesh : %d' % self.paintNmesh)
            self.logger.info('paintbrush : %s' % self.painter.paintbrush)

        # setup the particle mesh object, taking BoxSize from the painters
        pmpaint = ParticleMesh(BoxSize=self.datasource.BoxSize, Nmesh=[self.paintNmesh] * 3, dtype='f4', comm=self.comm)
        pm = ParticleMesh(BoxSize=self.datasource.BoxSize, Nmesh=[self.Nmesh] * 3, dtype='f4', comm=self.comm)

        real, stats = self.painter.paint(pmpaint, self.datasource)

        if self.writeFourier:
            result = ComplexField(pm)
        else:
            result = RealField(pm)
        real.resample(result)

        # reuses the memory
        result.sort(out=result)
        result = result.ravel()

        # return all the necessary results
        return result, stats
Example #2
0
    def run(self):
        """
        Run the algorithm, which computes and returns the grid in C_CONTIGUOUS order partitioned by ranks.
        """
        from nbodykit import measurestats

        if self.comm.rank == 0:
            self.logger.info("importing done")
            self.logger.info("Resolution Nmesh : %d" % self.paintNmesh)
            self.logger.info("paintbrush : %s" % self.painter.paintbrush)

        # setup the particle mesh object, taking BoxSize from the painters
        pmpaint = ParticleMesh(BoxSize=self.datasource.BoxSize, Nmesh=[self.paintNmesh] * 3, dtype="f4", comm=self.comm)
        pm = ParticleMesh(BoxSize=self.datasource.BoxSize, Nmesh=[self.Nmesh] * 3, dtype="f4", comm=self.comm)

        real, stats = self.painter.paint(pmpaint, self.datasource)

        if self.writeFourier:
            result = ComplexField(pm)
        else:
            result = RealField(pm)
        real.resample(result)

        # reuses the memory
        result.sort(out=result)
        result = result.ravel()

        # return all the necessary results
        return result, stats
Example #3
0
def test_sort(comm):
    pm = ParticleMesh(BoxSize=8.0, Nmesh=[8, 6], comm=comm, dtype='f8')
    real = RealField(pm)
    truth = numpy.arange(8 * 6)
    real[...] = truth.reshape(8, 6)[real.slices]
    unsorted = real.copy()
    real.sort(out=Ellipsis)
    conjecture = numpy.concatenate(comm.allgather(real.value.ravel()))
    assert_array_equal(conjecture, truth)

    real.unravel(real)
    assert_array_equal(real, unsorted)

    complex = ComplexField(pm)
    truth = numpy.arange(8 * 4)
    complex[...] = truth.reshape(8, 4)[complex.slices]
    complex.ravel(out=Ellipsis)
    conjecture = numpy.concatenate(comm.allgather(complex.value.ravel()))
    assert_array_equal(conjecture, truth)
Example #4
0
def test_sort(comm):
    pm = ParticleMesh(BoxSize=8.0, Nmesh=[8, 6], comm=comm, dtype='f8')
    real = RealField(pm)
    truth = numpy.arange(8 * 6)
    real[...] = truth.reshape(8, 6)[real.slices]
    unsorted = real.copy()
    real.sort(out=Ellipsis)
    conjecture = numpy.concatenate(comm.allgather(real.value.ravel()))
    assert_array_equal(conjecture, truth)

    real.unravel(real)
    assert_array_equal(real, unsorted)

    complex = ComplexField(pm)
    truth = numpy.arange(8 * 4)
    complex[...] = truth.reshape(8, 4)[complex.slices]
    complex.ravel(out=Ellipsis)
    conjecture = numpy.concatenate(comm.allgather(complex.value.ravel()))
    assert_array_equal(conjecture, truth)