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

Function global_func

Wrapping/Python/vtkmodules/numpy_interface/algorithms.py:64–107  ·  view source on GitHub ↗

Helper function for reduction-like operation (e.g., sum, min, max) to the given array, with support for parallel execution across different nodes.

(impl, array, axis, controller)

Source from the content-addressed store, hash-verified

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,
66 with support for parallel execution across different nodes."""
67 if type(array) == dsa.VTKCompositeDataArray:
68 if axis is None or axis == 0:
69 res = impl.serial_composite(array, axis)
70 else:
71 res = npalgs.apply_ufunc(impl.op(), array, (axis,))
72 else:
73 res = impl.op()(array, axis)
74 if res is not dsa.NoneArray:
75 res = res.astype(numpy.float64)
76
77 if axis is None or axis == 0:
78 if controller is None and vtkMultiProcessController is not None:
79 controller = vtkMultiProcessController.GetGlobalController()
80 if controller and controller.IsA("vtkMPIController") and controller.GetNumberOfProcesses() > 1:
81 try:
82 from mpi4py import MPI
83 except ImportError:
84 raise RuntimeError('MPI4Py is required to perform multi-rank operations')
85 comm = vtkMPI4PyCommunicator.ConvertToPython(controller.GetCommunicator())
86
87 max_dims, size = _reduce_dims(res, comm)
88
89 # All NoneArrays
90 if size == 0:
91 return dsa.NoneArray
92
93 if res is dsa.NoneArray:
94 if numpy.isscalar(max_dims):
95 # Weird trick to make the array look like a scalar
96 max_dims = ()
97 res = numpy.empty(max_dims)
98 res.fill(impl.default())
99
100 res_recv = numpy.array(res)
101 mpi_type = _lookup_mpi_type(res.dtype)
102 comm.Allreduce([res, mpi_type], [res_recv, mpi_type], impl.mpi_op())
103 if array is dsa.NoneArray:
104 return dsa.NoneArray
105 res = res_recv
106
107 return res
108
109@deprecated(version="9.6", message="Use np.bitwise_or() instead of algs.bitwise_or().")
110def bitwise_or(array1, array2):

Callers 4

sumFunction · 0.85
maxFunction · 0.85
minFunction · 0.85
allFunction · 0.85

Calls 15

RuntimeErrorClass · 0.85
_reduce_dimsFunction · 0.85
_lookup_mpi_typeFunction · 0.85
GetGlobalControllerMethod · 0.80
IsAMethod · 0.80
GetNumberOfProcessesMethod · 0.80
ConvertToPythonMethod · 0.80
arrayMethod · 0.80
typeEnum · 0.50
serial_compositeMethod · 0.45
opMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected