Skip to content

Commit

Permalink
replace _reduce with accumulation in _single_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
orbeckst committed Feb 19, 2020
1 parent f752932 commit cd5a1d1
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions package/MDAnalysis/analysis/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,11 @@ def _single_frame(self):
h, _ = np.histogramdd(self._atomgroup.positions,
bins=self._bins, range=self._arange,
normed=False)
# manually reduce (not yet part of AnalysisBase but exists in pmda.parallel.AnalysisBase)
self._reduce(self._grid, h)
# reduce (proposed change #2542 to match the parallel version in pmda.density)
# return self._reduce(self._grid, h)
#
# serial code can simply do
self._grid += h

def _conclude(self):
# average:
Expand All @@ -453,19 +456,21 @@ def _conclude(self):
density.make_density()
self.density = density

@staticmethod
def _reduce(res, result_single_frame):
"""'accumulate' action for a time series
If `res` is a numpy array, the `result_single_frame` is added to it
element-wise. If `res` and `result_single_frame` are lists then
`result_single_frame` is appended to `res`.
"""
if isinstance(res, list) and len(res) == 0:
res = result_single_frame
else:
res += result_single_frame
return res
# _reduce is not strictly necessary for the serial version but is necessary for
# pmda-style parallelism (see #2542)
# @staticmethod
# def _reduce(res, result_single_frame):
# """'accumulate' action for a time series
#
# If `res` is a numpy array, the `result_single_frame` is added to it
# element-wise. If `res` and `result_single_frame` are lists then
# `result_single_frame` is appended to `res`.
# """
# if isinstance(res, list) and len(res) == 0:
# res = result_single_frame
# else:
# res += result_single_frame
# return res


class Density(Grid):
Expand Down

0 comments on commit cd5a1d1

Please sign in to comment.