Skip to content

Commit

Permalink
fix: Windows and 32-bit Linux default to 32-bit integers in sums and …
Browse files Browse the repository at this point in the history
…prods UNLESS it's NumPy 2.0 (#3068)

* fix: determine Windows dtype from NumPy, because it depends on NumPy 1.x vs 2.0

* test NumPy 2.0 on all platforms

* fall back to second-guessing NumPy

* package name
  • Loading branch information
jpivarski authored Apr 1, 2024
1 parent 91a3c76 commit 567fe38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ jobs:
python-architecture: x64
runs-on: ubuntu-latest
dependencies-kind: numpy2
- python-version: '3.11'
python-architecture: x64
runs-on: macos-11
dependencies-kind: numpy2
- python-version: '3.11'
python-architecture: x64
runs-on: windows-latest
dependencies-kind: numpy2

runs-on: ${{ matrix.runs-on }}

Expand Down
6 changes: 4 additions & 2 deletions src/awkward/_reducers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def _dtype_for_kernel(cls, dtype: DTypeLike) -> DTypeLike:
else:
return dtype

_use32 = (ak._util.win or ak._util.bits32) and not ak._util.numpy2

@classmethod
def _promote_integer_rank(cls, given_dtype: DTypeLike) -> DTypeLike:
if given_dtype in (np.bool_, np.int8, np.int16, np.int32):
return np.int32 if ak._util.win or ak._util.bits32 else np.int64
return np.int32 if cls._use32 else np.int64

elif given_dtype in (np.uint8, np.uint16, np.uint32):
return np.uint32 if ak._util.win or ak._util.bits32 else np.uint64
return np.uint32 if cls._use32 else np.uint64

else:
return given_dtype
Expand Down
5 changes: 5 additions & 0 deletions src/awkward/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
import sys
from collections.abc import Collection

import numpy as np # noqa: TID251
import packaging.version

from awkward._typing import TypeVar

win = os.name == "nt"
bits32 = struct.calcsize("P") * 8 == 32
numpy2 = packaging.version.parse(np.__version__) >= packaging.version.Version("2.0.0b1")


# matches include/awkward/common.h
kMaxInt8 = 127 # 2**7 - 1
Expand Down

0 comments on commit 567fe38

Please sign in to comment.