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)
| 62 | return (max_dims, size) |
| 63 | |
| 64 | def 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().") |
| 110 | def bitwise_or(array1, array2): |
no test coverage detected