Helper function to count the number of elements in a VTK or NumPy array, supporting counting across MPI nodes.
(array, axis, controller)
| 505 | return numpy.int64(numpy.shape(array)[0]) |
| 506 | |
| 507 | def array_count(array, axis, controller) -> Union[numpy.int64, numpy.ndarray]: |
| 508 | """Helper function to count the number of elements in a VTK or NumPy array, |
| 509 | supporting counting across MPI nodes.""" |
| 510 | if array is dsa.NoneArray: |
| 511 | size = numpy.int64(0) |
| 512 | elif axis is None: |
| 513 | size = numpy.int64(array.size) |
| 514 | else: |
| 515 | size = numpy.int64(numpy.shape(array)[0]) |
| 516 | |
| 517 | if controller is None and vtkMultiProcessController is not None: |
| 518 | controller = vtkMultiProcessController.GetGlobalController() |
| 519 | |
| 520 | if controller and controller.IsA("vtkMPIController"): |
| 521 | from mpi4py import MPI |
| 522 | comm = vtkMPI4PyCommunicator.ConvertToPython(controller.GetCommunicator()) |
| 523 | |
| 524 | total_size = numpy.array(size, dtype=numpy.int64) |
| 525 | mpitype = _lookup_mpi_type(numpy.int64) |
| 526 | comm.Allreduce([size, mpitype], [total_size, mpitype], MPI.SUM) |
| 527 | size = total_size |
| 528 | |
| 529 | return size |
| 530 | |
| 531 | @deprecated(version="9.6", message="Use np.mean() instead of algs.mean().") |
| 532 | def mean(array, axis=None, controller=None, size=None): |
no test coverage detected