MCPcopy Create free account
hub / github.com/Kitware/VTK / sum

Function sum

Wrapping/Python/vtkmodules/numpy_interface/numpy_algorithms.py:149–188  ·  view source on GitHub ↗

Returns the sum of all values along a particular axis (dimension). Given an array of m tuples and n components: * Default is to return the sum of all values in an array. * axis=0: Sum values of all components and return a one tuple, n-component array. * axis=1: Sum values of al

(array, axis=None, controller=None)

Source from the content-addressed store, hash-verified

147
148@dsa._override_numpy(numpy.sum)
149def sum(array, axis=None, controller=None):
150 """Returns the sum of all values along a particular axis (dimension).
151 Given an array of m tuples and n components:
152 * Default is to return the sum of all values in an array.
153 * axis=0: Sum values of all components and return a one tuple,
154 n-component array.
155 * axis=1: Sum values of all components of each tuple and return an
156 m-tuple, 1-component array.
157
158 When called in parallel, this function will sum across processes
159 when a controller argument is passed or the global controller is
160 defined. To disable parallel summing when running in parallel, pass
161 a dummy controller as follows:
162
163 sum(array, controller=vtkmodules.vtkParallelCore.vtkDummyController()).
164 """
165 from .algorithms import global_func
166 class SumImpl:
167 def op(self):
168 return algs.sum
169
170 def mpi_op(self):
171 from mpi4py import MPI
172 return MPI.SUM
173
174 def serial_composite(self, array, axis):
175 res = None
176 arrays = array.Arrays
177 for a in arrays:
178 if a is not dsa.NoneArray:
179 if res is None:
180 res = algs.sum(a, axis).astype(numpy.float64)
181 else:
182 res += algs.sum(a, axis)
183 return res
184
185 def default(self):
186 return numpy.float64(0)
187
188 return global_func(SumImpl(), array, axis, controller)
189
190@dsa._override_numpy(numpy.max)
191def max(array, axis=None, controller=None):

Callers 2

meanFunction · 0.70
varFunction · 0.70

Calls 2

global_funcFunction · 0.85
SumImplClass · 0.70

Tested by

no test coverage detected