reduce
triwarp.reduce
Global reductions on Warp arrays.
min
min(
array: Array1dInt32 | Array2dInt32, *, axis: None = ...
) -> int
min(
array: Array1dFloat | Array2dFloat, *, axis: None = ...
) -> float
min(
array: Array2dScalar, *, axis: Literal[0, 1]
) -> twt.Array1dScalar
min(
array: ScalarArray, *, axis: Literal[0, 1] | None = None
) -> float | int | twt.Array1dScalar
Minimum of array.
With axis=None (default), reduces every element to one Python scalar using
tiled kernels (wp.tile_load + wp.tile_min + wp.atomic_min).
With axis=0 or axis=1 on a rank-2 input, reduces along that axis to a
1D wp.array of the same dtype — one plain thread per output element when the
reduced extent is narrower than a tile, a tiled block reduction per output otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ScalarArray
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
float | int | array
|
Global scalar when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
max
max(
array: Array1dInt32 | Array2dInt32, *, axis: None = ...
) -> int
max(
array: Array1dFloat | Array2dFloat, *, axis: None = ...
) -> float
max(
array: Array2dScalar, *, axis: Literal[0, 1]
) -> twt.Array1dScalar
max(
array: ScalarArray, *, axis: Literal[0, 1] | None = None
) -> float | int | twt.Array1dScalar
Maximum of array.
With axis=None (default), reduces every element to one Python scalar using
tiled kernels (wp.tile_load + wp.tile_max + wp.atomic_max).
With axis=0 or axis=1 on a rank-2 input, reduces along that axis to a
1D wp.array of the same dtype — one plain thread per output element when the
reduced extent is narrower than a tile, a tiled block reduction per output otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ScalarArray
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
float | int | array
|
Global scalar when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
minmax
minmax(
array: Array1dInt32 | Array2dInt32, *, axis: None = ...
) -> tuple[int, int]
minmax(
array: Array1dFloat | Array2dFloat, *, axis: None = ...
) -> tuple[float, float]
minmax(
array: array[vec3], *, axis: None = ...
) -> tuple[wp.vec3, wp.vec3]
minmax(
array: Array2dScalar, *, axis: Literal[0, 1]
) -> tuple[twt.Array1dScalar, twt.Array1dScalar]
minmax(
array: ScalarArray | array[vec3],
*,
axis: Literal[0, 1] | None = None,
) -> (
tuple[float, float]
| tuple[int, int]
| tuple[wp.vec3, wp.vec3]
| tuple[twt.Array1dScalar, twt.Array1dScalar]
)
Minimum and maximum of array.
With axis=None (default), reduces every element to two Python scalars using
tiled kernels (wp.tile_load + wp.tile_min/tile_max +
wp.atomic_min/atomic_max). Either direction alone would be one launch, one
buffer and one readback too, so asking for both costs nothing extra.
A rank-1 wp.vec3 array reduces component-wise to a (wp.vec3, wp.vec3) corner
pair — one chunked kernel into a single six-slot buffer (the upper corner negated so
one inf fill seeds both ends) and one readback, which is what keeps
aabb host-latency-bound and nothing more.
With axis=0 or axis=1 on a rank-2 input, reduces along that axis to a
pair of 1D wp.array buffers (min, max) of the same dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ScalarArray | array[vec3]
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float] | tuple[int, int] | tuple[vec3, vec3] | tuple[array, array]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
aabb
The mesh-facing spelling of the wp.vec3 reduction, with the empty-input
(+inf, -inf) convention instead of a raise.
Source code in triwarp/reduce.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
any
any(
array: array[bool], *, axis: Literal[0, 1] | None = None
) -> wp.array[wp.bool] | bool
Reduce a boolean array with logical OR.
For rank-1 input, or rank-2 input with axis=None, reduce all elements
to one Python bool. For rank-2 input with an explicit axis, reduce along
that axis to a 1D wp.bool array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
array[bool]
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
bool | array[bool]
|
Python |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
sum
sum(array: array[vec3], *, axis: None = ...) -> wp.vec3
sum(
array: Array1dInt32 | Array2dInt32, *, axis: None = ...
) -> int
sum(
array: Array1dFloat | Array2dFloat, *, axis: None = ...
) -> float
sum(
array: Array2dScalar, *, axis: Literal[0, 1]
) -> twt.Array1dScalar
sum(array: array[bool], *, axis: None = ...) -> int
sum(
array: array[bool], *, axis: Literal[0, 1]
) -> twt.Array1dInt32
sum(
array: ScalarArray | array[bool] | array[vec3],
*,
axis: Literal[0, 1] | None = None,
) -> (
float
| int
| twt.Array1dScalar
| twt.Array1dInt32
| wp.vec3
)
Sum of array.
With axis=None (default), reduces every element to one Python scalar using
tiled kernels (wp.tile_load + wp.tile_sum + wp.atomic_add).
With axis=0 or axis=1 on a rank-2 input, reduces along that axis to a
1D wp.array of the same dtype — one plain thread per output element when the
reduced extent is narrower than a tile, a tiled block reduction per output otherwise.
For wp.bool input, counts True values and returns int (global) or
wp.int32 (per-axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ScalarArray | array[bool] | array[vec3]
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
float | int | array
|
Global scalar when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
mean
mean(array: array[vec3], *, axis: None = ...) -> wp.vec3
mean(
array: ScalarArray | array[bool], *, axis: None = ...
) -> float
mean(
array: Array2dScalar | array[bool],
*,
axis: Literal[0, 1],
) -> twt.Array1dFloat32
mean(
array: ScalarArray | array[bool] | array[vec3],
*,
axis: Literal[0, 1] | None = None,
) -> float | twt.Array1dFloat32 | wp.vec3
Arithmetic mean of array.
Delegates the reduction to the tiled sum, then divides by the
element count. With axis=None (default), returns one Python float. With
axis=0 or axis=1 on a rank-2 input, returns a 1D wp.float32 array.
The result is always floating point regardless of input dtype. For wp.bool
input, the mean is the fraction of True values. For a 1D wp.vec3 input
the mean is the component-wise average wp.vec3 (axis=None only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ScalarArray | array[bool] | array[vec3]
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
float | vec3 | array
|
Global |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
weighted_sum
weighted_sum(
values: Array1dFloat32, weights: Array1dFloat32
) -> float
weighted_sum(
values: array[vec3], weights: Array1dFloat32
) -> wp.vec3
weighted_sum(
values: Array1dFloat32 | array[vec3],
weights: Array1dFloat32,
) -> float | wp.vec3
Weighted sum sum_i weights[i] * values[i].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Array1dFloat32 | array[vec3]
|
Rank-1 |
required |
weights
|
Array1dFloat32
|
Rank-1 |
required |
Returns:
| Type | Description |
|---|---|
float | vec3
|
Scalar weighted sum on the host ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either array is not rank-1, either is empty, or their lengths differ. |
RuntimeError
|
If |
Source code in triwarp/reduce.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
all
all(
array: array[bool], *, axis: Literal[0, 1] | None = None
) -> wp.array[wp.bool] | bool
Reduce a boolean array with logical AND.
For rank-1 input, or rank-2 input with axis=None, reduce all elements
to one Python bool. For rank-2 input with an explicit axis, reduce along
that axis to a 1D wp.bool array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
array[bool]
|
Rank-1 |
required |
axis
|
Literal[0, 1] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
bool | array[bool]
|
Python |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
median
median(array: Array1dScalar) -> float
Median of a 1D scalar array (numpy.median).
Sorts a copy of the values on-device with warp.utils.radix_sort_pairs and reads the
middle element (odd length) or averages the two middle elements (even length). The result
is always a Python float, regardless of input dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array1dScalar
|
Rank-1 |
required |
Returns:
| Type | Description |
|---|---|
float
|
The median value on the host. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in triwarp/reduce.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |