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

Function _global_per_block

Wrapping/Python/vtkmodules/numpy_interface/algorithms.py:208–334  ·  view source on GitHub ↗
(impl, array, axis=None, controller=None)

Source from the content-addressed store, hash-verified

206 return npalgs.min(array, axis, controller)
207
208def _global_per_block(impl, array, axis=None, controller=None):
209 if axis is not None and axis > 0:
210 return impl.op()(array, axis=axis, controller=controller)
211 try:
212 dataset = array.DataSet
213 except AttributeError:
214 dataset = None
215 t = type(array)
216 if t == dsa.VTKArray or t == numpy.ndarray:
217 from ..vtkCommonDataModel import vtkMultiBlockDataSet
218 array = dsa.VTKCompositeDataArray([array])
219 ds = vtkMultiBlockDataSet()
220 ds.SetBlock(0, dataset.VTKObject)
221 dataset = ds
222 results = npalgs._apply_func2(impl.op2(), array, (axis,))
223 if controller is None and vtkMultiProcessController is not None:
224 controller = vtkMultiProcessController.GetGlobalController()
225 if controller and controller.IsA("vtkMPIController"):
226 from mpi4py import MPI
227 comm = vtkMPI4PyCommunicator.ConvertToPython(controller.GetCommunicator())
228
229 # First determine the number of components to use
230 # for reduction
231 res = dsa.NoneArray
232 for res in results:
233 if res is not dsa.NoneArray:
234 break
235
236 max_dims, size = _reduce_dims(res, comm)
237
238 # All NoneArrays
239 if size == 0:
240 return dsa.NoneArray
241
242 # Next determine the max id to use for reduction
243 # operations
244
245 # Get all ids from dataset, including empty ones.
246 ids = []
247 lmax_id = numpy.int32(0)
248 if dataset is not None:
249 it = dataset.NewIterator()
250 it.UnRegister(None)
251 it.SetSkipEmptyNodes(False)
252 while not it.IsDoneWithTraversal():
253 _id = it.GetCurrentFlatIndex()
254 lmax_id = numpy.max((lmax_id, _id)).astype(numpy.int32)
255 if it.GetCurrentDataObject() is not None:
256 ids.append(_id)
257 it.GoToNextItem()
258 max_id = numpy.array(0, dtype=numpy.int32)
259 mpitype = _lookup_mpi_type(numpy.int32)
260 comm.Allreduce([lmax_id, mpitype], [max_id, mpitype], MPI.MAX)
261
262 has_ids = numpy.zeros(max_id+1, dtype=numpy.int32)
263 for _id in ids:
264 has_ids[_id] = 1
265 id_count = numpy.array(has_ids)

Callers 4

sum_per_blockFunction · 0.85
count_per_blockFunction · 0.85
max_per_blockFunction · 0.85
min_per_blockFunction · 0.85

Calls 15

_reduce_dimsFunction · 0.85
_lookup_mpi_typeFunction · 0.85
SetBlockMethod · 0.80
GetGlobalControllerMethod · 0.80
IsAMethod · 0.80
ConvertToPythonMethod · 0.80
GetCurrentFlatIndexMethod · 0.80
arrayMethod · 0.80
typeEnum · 0.50
rangeClass · 0.50
opMethod · 0.45

Tested by

no test coverage detected