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

Function array_count

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

Helper function to count the number of elements in a VTK or NumPy array, supporting counting across MPI nodes.

(array, axis, controller)

Source from the content-addressed store, hash-verified

505 return numpy.int64(numpy.shape(array)[0])
506
507def 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().")
532def mean(array, axis=None, controller=None, size=None):

Callers 2

meanFunction · 0.85
varFunction · 0.85

Calls 7

_lookup_mpi_typeFunction · 0.85
GetGlobalControllerMethod · 0.80
IsAMethod · 0.80
ConvertToPythonMethod · 0.80
arrayMethod · 0.80
shapeMethod · 0.45
GetCommunicatorMethod · 0.45

Tested by

no test coverage detected