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. Partial whole-array reductions process elements in logical row-major order. Full reductions of compact arrays may use physical storage order.
During CPU graph capture, or CUDA graph capture with
apic=True, non-empty calls require an explicitoutarray so replay can store the current result. Existing whole-array, explicit-count, composite-dtype, and positive-stride axis reductions are recorded. Non-empty whole-array reductions that require a contiguous copy are unsupported during API Capture (APIC) recording; make inputs contiguous before capture or specify an axis for strided reductions. Negative strides raiseNotImplementedErrorduring 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
float32orfloat64.out (array | None) – Output array to store results. If
None, a new array is created.value_count (int | None) – Number of elements to process. Must not exceed the input size, or the selected axis length when
axisis specified. IfNone, processes the entire reduction.axis (int | None) – Axis along which to compute sum. Negative values count from the last dimension. If
None, computes sum of all elements.
- Returns:
The sum result. Returns a float if
axisisNoneandoutisNone, otherwise returns theoutarray.- Raises:
IndexError – If
axisis outside the valid range forvalues.RuntimeError – If
value_countexceeds the reduction size, output array storage device or data type is incompatible with input array, or 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, or a non-empty whole-array reduction requires a contiguous copy during APIC recording.
- Return type: