Skip to content

Commit

Permalink
Merge pull request #537 from rainwoodman/sum-to-float
Browse files Browse the repository at this point in the history
when summing integers, use numpy.sum.
  • Loading branch information
rainwoodman committed Dec 10, 2018
2 parents 1222dd5 + f6f2dbe commit bf140a0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions nbodykit/algorithms/fof.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def _assign_labels(minid, comm, thresh):
# we need to work in sorted fofid
data['fofid'] = minid
data['origind'] = numpy.arange(len(data), dtype='u4')
data['origind'] += sum(comm.allgather(len(data))[:comm.rank]) \
data['origind'] += numpy.sum(comm.allgather(len(data))[:comm.rank], dtype='intp') \

data = DistributedArray(data, comm)

Expand Down Expand Up @@ -284,7 +284,7 @@ def _fof_local(layout, pos, boxsize, ll, comm):
del fof

PID = numpy.arange(N, dtype='intp')
PID += sum(comm.allgather(N)[:comm.rank])
PID += numpy.sum(comm.allgather(N)[:comm.rank], dtype='intp')

PID = layout.exchange(PID)
# initialize global labels
Expand Down Expand Up @@ -696,7 +696,7 @@ def unique_labels(self):
else:
Nunique = len(junk)

label += sum(self.comm.allgather(Nunique)[:self.comm.rank])
label += numpy.sum(self.comm.allgather(Nunique)[:self.comm.rank], dtype='intp')
return DistributedArray(label, self.comm)

def bincount(self, local=False):
Expand Down
2 changes: 1 addition & 1 deletion nbodykit/base/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ def Index(self):
Note that slicing changes this index value.
"""
offset = sum(self.comm.allgather(self.size)[:self.comm.rank])
offset = numpy.sum(self.comm.allgather(self.size)[:self.comm.rank], dtype='intp')
# do not use u8, because many numpy casting rules case u8 to f8 automatically.
# it is ridiculous.
return da.arange(offset, offset + self.size, dtype='i8',
Expand Down
2 changes: 1 addition & 1 deletion nbodykit/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def __init__(self, path, names, blocksize=32*1024*1024, dtype={},

# make the partitions
self.partitions, self._sizes = make_partitions(path, blocksize, self.pandas_config)
self.size = sum(self._sizes)
self.size = numpy.sum(self._sizes, dtype='intp')

def read(self, columns, start, stop, step=1):
"""
Expand Down
4 changes: 2 additions & 2 deletions nbodykit/source/mesh/bigfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def to_real_field(self):
if self.comm.rank == 0:
self.logger.info("reading real field from %s" % self.path)
real2 = RealField(pmread)
start = sum(self.comm.allgather(real2.size)[:self.comm.rank])
start = numpy.sum(self.comm.allgather(real2.size)[:self.comm.rank], dtype='intp')
end = start + real2.size
real2.unsort(ds[start:end])

Expand Down Expand Up @@ -129,7 +129,7 @@ def to_complex_field(self):
with BigFileMPI(comm=self.comm, filename=self.path)[self.dataset] as ds:
complex2 = ComplexField(pmread)
assert self.comm.allreduce(complex2.size) == ds.size
start = sum(self.comm.allgather(complex2.size)[:self.comm.rank])
start = numpy.sum(self.comm.allgather(complex2.size)[:self.comm.rank], dtype='intp')
end = start + complex2.size
complex2.unsort(ds[start:end])

Expand Down
2 changes: 1 addition & 1 deletion nbodykit/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def ConcatenateSources(*sources, **kwargs):
raise ValueError(("cannot concatenate sources: columns are missing "
"from some sources"))
# the total size
size = sum(src.size for src in sources)
size = numpy.sum([src.size for src in sources], dtype='intp')

data = {}
for col in columns:
Expand Down

0 comments on commit bf140a0

Please sign in to comment.