warp.utils.array_sum#

warp.utils.array_sum(values, out=None, value_count=None, axis=None)[source]#

Compute the sum of array elements.

This function computes the sum of array elements, optionally along a specified axis. The operation can be performed on the entire array or along a specific dimension.

During CPU graph capture, or CUDA graph capture with apic=True, non-empty calls require an explicit out array so replay can store the current result. Existing whole-array, explicit-count, composite-dtype, and positive-stride axis reductions are recorded. Negative strides raise NotImplementedError during API Capture (APIC) recording. Counts and reduction strides must fit signed 32-bit integers, and participating addresses and strides must be aligned to the scalar type.

Parameters:
  • values (array) – Input array to sum. Its scalar type must be float32 or float64.

  • out (array | None) – Output array to store results. If None, a new array is created.

  • value_count (int | None) – Number of elements to process. If None, processes entire array.

  • axis (int | None) – Axis along which to compute sum. If None, computes sum of all elements.

Returns:

The sum result. Returns a float if axis is None and out is None, otherwise returns the out array.

Raises:
  • RuntimeError – If output array storage device or data type is incompatible with input array, or if an APIC-recorded call uses an unsupported count or memory layout.

  • NotImplementedError – If a non-empty call during APIC recording omits out. Also raised if any input or output array has a negative stride during APIC recording, including for a zero-count call.

Return type:

array | float