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

Function _reduce_dims

Wrapping/Python/vtkmodules/numpy_interface/algorithms.py:38–62  ·  view source on GitHub ↗
(array, comm)

Source from the content-addressed store, hash-verified

36 return MPI._typedict[typecode]
37
38def _reduce_dims(array, comm):
39 from mpi4py import MPI
40 dims = numpy.array([0, 0], dtype=numpy.int32)
41 if array is not dsa.NoneArray:
42 shp = numpy.shape(array)
43 if len(shp) == 0:
44 dims = numpy.array([1, 0], dtype=numpy.int32)
45 elif len(shp) == 1:
46 dims = numpy.array([shp[0], 0], dtype=numpy.int32)
47 else:
48 dims = numpy.array(shp, dtype=numpy.int32)
49 max_dims = numpy.array(dims, dtype=numpy.int32)
50 mpitype = _lookup_mpi_type(numpy.int32)
51 comm.Allreduce([dims, mpitype], [max_dims, mpitype], MPI.MAX)
52
53 if max_dims[1] == 0:
54 max_dims = numpy.array((max_dims[0],))
55 size = max_dims[0]
56 else:
57 size = max_dims[0]*max_dims[1]
58
59 if max_dims[0] == 1:
60 max_dims = 1
61
62 return (max_dims, size)
63
64def global_func(impl, array, axis, controller) -> Union[numpy.ndarray, dsa.VTKNoneArray, dsa.VTKCompositeDataArray]:
65 """Helper function for reduction-like operation (e.g., sum, min, max) to the given array,

Callers 2

global_funcFunction · 0.85
_global_per_blockFunction · 0.85

Calls 3

_lookup_mpi_typeFunction · 0.85
arrayMethod · 0.80
shapeMethod · 0.45

Tested by

no test coverage detected