-
-
Notifications
You must be signed in to change notification settings - Fork 12
chore: bump version to 0.1.5 #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,21 +73,27 @@ def _reduce_sum_per_channel_float32(arr: ImageFloat32, axes: tuple[int, ...], *, | |
|
|
||
|
|
||
| def _reduce_sum_numpy( | ||
| arr: ImageType, | ||
| arr: np.ndarray, | ||
| axes: tuple[int, ...] | None, | ||
| *, | ||
| keepdims: bool, | ||
| ) -> np.uint64 | np.float64 | np.ndarray: | ||
| acc = np.uint64 if arr.dtype == np.uint8 else np.float64 | ||
| ) -> np.generic | np.ndarray: | ||
| if np.issubdtype(arr.dtype, np.unsignedinteger): | ||
| acc: type = np.uint64 | ||
| elif np.issubdtype(arr.dtype, np.floating): | ||
| acc = np.float64 | ||
| else: | ||
| # signed integers and bool | ||
| acc = np.int64 | ||
| return np.sum(arr, axis=axes, dtype=acc, keepdims=keepdims) | ||
|
Comment on lines
75
to
88
|
||
|
|
||
|
|
||
| def reduce_sum( | ||
| arr: ImageType, | ||
| arr: np.ndarray, | ||
| axis: AxisSpec = None, | ||
| *, | ||
| keepdims: bool = False, | ||
| ) -> np.uint64 | np.float64 | np.ndarray: | ||
| ) -> np.generic | np.ndarray: | ||
| r"""Sum over image tensor axes with benchmark-driven routing. | ||
|
|
||
| Routing: | ||
|
|
@@ -105,27 +111,28 @@ def reduce_sum( | |
| Alternative: ``mean`` / ``std`` / ``mean_std`` for normalised statistics. | ||
|
|
||
| Args: | ||
| arr: ``uint8`` or ``float32`` array with explicit channel dimension. | ||
| arr: Array with explicit channel dimension. Optimised paths for ``uint8`` and ``float32``; | ||
| other dtypes fall back to NumPy (float → float64 accumulator, integer/bool → int64). | ||
| axis: ``None`` / ``"global"`` → one scalar; ``"per_channel"`` → shape ``(C,)``; | ||
|
Comment on lines
113
to
116
|
||
| or explicit ``int`` / ``tuple[int, ...]`` (NumPy path). | ||
| keepdims: Same semantics as :func:`numpy.sum`. | ||
|
|
||
| Returns: | ||
| ``numpy.uint64`` or ``numpy.float64`` scalar for a full reduction, else an array. | ||
| Scalar (``uint64`` / ``int64`` / ``float64``) for a full reduction, else an array. | ||
| The accumulator dtype follows the input: unsigned → uint64, float → float64, | ||
| signed int / bool → int64. | ||
| """ | ||
| axes = _resolve_axes(arr, axis) | ||
| if axes is None: | ||
| if _is_uint8_image(arr): | ||
| return _reduce_sum_global_uint8(arr, keepdims=keepdims) | ||
| if _is_float32_image(arr): | ||
| return _reduce_sum_global_float32(arr, keepdims=keepdims) | ||
| raise ValueError(f"Unsupported dtype {arr.dtype} for reduce_sum; use uint8 or float32.") | ||
| if axes == _per_channel_spatial_axes(arr): | ||
| elif axes == _per_channel_spatial_axes(arr): | ||
| if _is_uint8_image(arr): | ||
| return _reduce_sum_per_channel_uint8(arr, keepdims=keepdims) | ||
| if _is_float32_image(arr): | ||
| return _reduce_sum_per_channel_float32(arr, axes, keepdims=keepdims) | ||
| raise ValueError(f"Unsupported dtype {arr.dtype} for reduce_sum; use uint8 or float32.") | ||
| return _reduce_sum_numpy(arr, axes, keepdims=keepdims) | ||
|
|
||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_reduce_sum_numpyselectsnp.int64as the accumulator for all non-uint8, non-floating dtypes. This includes unsigned integer arrays (e.g.uint16/uint32/uint64), where casting toint64can produce incorrect negative results for values > 2**63-1 and is generally inconsistent with unsigned semantics. Consider using anp.uint64accumulator fornp.unsignedintegerdtypes (and keepnp.int64for signed ints/bool), so sums remain correct across all integer dtypes.