Skip to content

Commit 7b3a57d

Browse files
authored
Merge pull request #165 from SwayamInSync/finfo
2 parents 2134a7d + e2d4778 commit 7b3a57d

File tree

14 files changed

+394
-125
lines changed

14 files changed

+394
-125
lines changed

.github/workflows/big_endian.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
- [
3232
"s390x (IBM Z Big Endian)",
3333
"s390x-linux-gnu",
34-
"s390x/ubuntu:22.04",
34+
"s390x/ubuntu:24.04",
3535
"s390x",
3636
]
3737
- [
3838
"s390x - baseline(Z13)",
3939
"s390x-linux-gnu",
40-
"s390x/ubuntu:22.04",
40+
"s390x/ubuntu:24.04",
4141
"s390x",
4242
]
4343
env:
@@ -107,10 +107,12 @@ jobs:
107107
# Configure git for workspace access
108108
git config --global --add safe.directory /workspace &&
109109
110-
# Install Python build dependencies
111-
python -m pip install --upgrade pip &&
112-
python -m pip install meson>=1.3.2 meson-python wheel numpy &&
113-
python -m pip install pytest pytest-run-parallel pytest-timeout &&
110+
# Install Python build dependencies (using --break-system-packages for Ubuntu 24.04)
111+
python -m pip install --break-system-packages meson>=1.3.2 meson-python wheel ninja cython &&
112+
echo \"Building NumPy from source (main branch)...\" &&
113+
python -m pip install --break-system-packages git+https://github.com/numpy/numpy.git@main &&
114+
python -c \"import numpy; print('NumPy version:', numpy.__version__)\" &&
115+
python -m pip install --break-system-packages pytest pytest-run-parallel pytest-timeout &&
114116
115117
# Install system dependencies for quaddtype (SLEEF dependencies)
116118
apt install -y libssl-dev libfftw3-dev pkg-config
@@ -134,8 +136,11 @@ jobs:
134136
# Set OpenMP linking for cross-compilation
135137
export LDFLAGS=\"-fopenmp\" &&
136138
137-
# Install quaddtype with test dependencies
138-
python -m pip install .[test] -v --no-build-isolation --force-reinstall
139+
# Install quaddtype without dependencies (NumPy already installed from source)
140+
python -m pip install --break-system-packages --no-deps . -v --no-build-isolation --force-reinstall &&
141+
142+
# Install test dependencies separately
143+
python -m pip install --break-system-packages pytest pytest-run-parallel pytest-timeout &&
139144
140145
cd ..
141146
python -m pytest -vvv --color=yes --timeout=600 --tb=short quaddtype/tests/

.github/workflows/build_wheels.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ jobs:
3232

3333
- name: Build wheels
3434
env:
35-
CIBW_BUILD: "cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64 cp313t-manylinux_x86_64 cp314-manylinux_x86_64 cp314t-manylinux_x86_64"
35+
CIBW_BUILD: "cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64 cp313t-manylinux_x86_64 cp314-manylinux_x86_64 cp314t-manylinux_x86_64"
3636
CIBW_ENABLE: cpython-prerelease cpython-freethreading
3737
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
3838
CIBW_BUILD_VERBOSITY: "3"
3939
CIBW_BEFORE_ALL: |
4040
yum update -y
4141
yum install -y cmake gcc gcc-c++ make git pkgconfig
42+
CIBW_BEFORE_BUILD: |
43+
pip install meson>=1.3.2 meson-python>=0.18.0 wheel ninja
44+
pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
45+
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
4246
CIBW_ENVIRONMENT: >
4347
LDFLAGS="-fopenmp"
4448
CIBW_REPAIR_WHEEL_COMMAND: |
4549
auditwheel repair -w {dest_dir} --plat manylinux_2_28_x86_64 {wheel}
4650
CIBW_TEST_COMMAND: |
47-
pip install {package}[test]
51+
pip install --pre --upgrade --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
52+
pip install --no-deps {wheel}
53+
pip install pytest pytest-run-parallel
4854
if python -c "import sys; exit(0 if hasattr(sys, '_is_gil_enabled') and not sys._is_gil_enabled() else 1)"; then
4955
pytest --parallel-threads=10 --iterations=10 {project}/tests
5056
else
@@ -93,16 +99,22 @@ jobs:
9399
94100
- name: Build wheels
95101
env:
96-
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
102+
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
97103
CIBW_ENABLE: cpython-prerelease cpython-freethreading
98104
# CIBW_ARCHS_MACOS: ${{ matrix.os == 'macos-13' && 'x86_64' || 'arm64' }}
99105
CIBW_BUILD_VERBOSITY: "3"
106+
CIBW_BEFORE_BUILD: |
107+
pip install meson>=1.3.2 meson-python>=0.18.0 wheel ninja
108+
pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
109+
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
100110
CIBW_ENVIRONMENT: >
101111
MACOSX_DEPLOYMENT_TARGET="${{ matrix.os == 'macos-14' && '14.0' || '15.0' }}"
102112
CIBW_REPAIR_WHEEL_COMMAND: >
103113
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
104114
CIBW_TEST_COMMAND: |
105-
pip install {package}[test]
115+
pip install --pre --upgrade --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
116+
pip install --no-deps {wheel}
117+
pip install pytest pytest-run-parallel
106118
if python -c "import sys; exit(0 if hasattr(sys, '_is_gil_enabled') and not sys._is_gil_enabled() else 1)"; then
107119
pytest --parallel-threads=10 --iterations=10 {project}/tests
108120
else
@@ -151,20 +163,22 @@ jobs:
151163
152164
- name: Build wheels
153165
env:
154-
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
166+
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
155167
CIBW_ENABLE: cpython-prerelease cpython-freethreading
156-
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-*"
168+
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-* cp310-*"
157169
CIBW_ARCHS_WINDOWS: ${{ matrix.architecture == 'x86' && 'x86' || 'AMD64' }}
158170
CIBW_BUILD_VERBOSITY: "3"
159171
DISTUTILS_USE_SDK: "1"
160172
MSSdk: "1"
161-
CIBW_BEFORE_BUILD: |
162-
pip install meson meson-python ninja numpy
173+
CIBW_BEFORE_BUILD: >-
174+
pip install meson meson-python ninja wheel &&
175+
pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
176+
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
163177
CIBW_ENVIRONMENT: >
164178
CFLAGS="/DDISABLE_QUADBLAS $CFLAGS"
165179
CXXFLAGS="/DDISABLE_QUADBLAS $CXXFLAGS"
166180
CIBW_REPAIR_WHEEL_COMMAND: 'delvewheel repair -w {dest_dir} {wheel} --add-path C:\sleef\bin'
167-
CIBW_TEST_COMMAND_WINDOWS: pip install {package}[test] && pytest -s {project}/tests
181+
CIBW_TEST_COMMAND_WINDOWS: pip install --pre --upgrade --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy && pip install --no-deps {wheel} && pip install pytest pytest-run-parallel && pytest -s {project}/tests
168182
CIBW_TEST_EXTRAS: test
169183
shell: pwsh
170184
run: |
@@ -196,14 +210,15 @@ jobs:
196210
- name: Install build dependencies
197211
run: |
198212
python -m pip install --upgrade pip
199-
python -m pip install build pytest
213+
python -m pip install build pytest meson meson-python wheel ninja
214+
python -m pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
200215
201216
- name: Build SDist & test sdist
202217
env:
203218
LDFLAGS: "-fopenmp"
204219
run: |
205-
python -m build --sdist --outdir dist/
206-
pip install dist/*.tar.gz -v
220+
python -m build --sdist --no-isolation --outdir dist/
221+
pip install --no-build-isolation dist/*.tar.gz -v
207222
pytest -s tests
208223
working-directory: ./quaddtype
209224

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ jobs:
1616
- name: Setup Python
1717
uses: actions/setup-python@v3
1818
with:
19-
python-version: "3.10"
19+
python-version: "3.11"
2020
- name: Install build and test dependencies
2121
run: |
22-
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf pandas numpy
22+
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf pandas
23+
python -m pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
2324
- name: Install asciidtype
2425
working-directory: asciidtype
2526
run: |
@@ -64,7 +65,7 @@ jobs:
6465
working-directory: quaddtype
6566
run: |
6667
export LDFLAGS="-fopenmp"
67-
python -m pip install . -v
68+
python -m pip install . -v --no-build-isolation
6869
6970
- name: Run quaddtype tests
7071
working-directory: quaddtype

.github/workflows/typecheck.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ jobs:
2525
- uses: astral-sh/[email protected]
2626
with:
2727
activate-environment: true
28-
python-version: "3.10"
28+
python-version: "3.11"
2929

3030
- name: install
3131
working-directory: quaddtype
32-
run: uv pip install mypy pyright .
32+
run: |
33+
uv pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
34+
uv pip install meson>=1.3.2 meson-python wheel ninja
35+
uv pip install mypy pyright . --no-build-isolation
3336
3437
- name: pyright
3538
working-directory: quaddtype

quaddtype/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ incdir_numpy = run_command(py,
2424
check : true
2525
).stdout().strip()
2626

27+
# print numpy version used
28+
numpy_version = run_command(py,
29+
['-c', 'import numpy; print(numpy.__version__)'],
30+
check : true
31+
).stdout().strip()
32+
message('Using NumPy version: @0@'.format(numpy_version))
33+
2734
npymath_path = incdir_numpy / '..' / 'lib'
2835
npymath_lib = c.find_library('npymath', dirs: npymath_path)
2936

@@ -117,6 +124,7 @@ srcs = [
117124
'numpy_quaddtype/src/umath/promoters.hpp',
118125
'numpy_quaddtype/src/umath/matmul.h',
119126
'numpy_quaddtype/src/umath/matmul.cpp',
127+
'numpy_quaddtype/src/constants.hpp',
120128
]
121129

122130
py.install_sources(

quaddtype/numpy_quaddtype/_quaddtype_main.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ class QuadPrecision: # NOTE: It doesn't inherit from `np.generic` which is type
8181

8282
# Binary operators
8383
def __add__(self, other: _CastsQuad, /) -> Self: ...
84-
def __radd__(self, other: _CastsQuad, /) -> Self: ... # type: ignore[misc]
84+
def __radd__(self, other: _CastsQuad, /) -> Self: ...
8585
def __sub__(self, other: _CastsQuad, /) -> Self: ...
8686
def __rsub__(self, other: _CastsQuad, /) -> Self: ...
8787
def __mul__(self, other: _CastsQuad, /) -> Self: ...
88-
def __rmul__(self, other: _CastsQuad, /) -> Self: ... # type: ignore[misc]
88+
def __rmul__(self, other: _CastsQuad, /) -> Self: ...
8989
def __pow__(self, other: _CastsQuad, mod: None = None, /) -> Self: ...
9090
def __rpow__(self, other: _CastsQuad, mod: None = None, /) -> Self: ...
9191
def __truediv__(self, other: _CastsQuad, /) -> Self: ...
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#ifndef QUAD_CONSTANTS_HPP
2+
#define QUAD_CONSTANTS_HPP
3+
4+
#include <sleef.h>
5+
#include <sleefquad.h>
6+
#include <stdint.h>
7+
#include <string.h>
8+
9+
// Quad precision constants using sleef_q macro
10+
#define QUAD_PRECISION_ZERO sleef_q(+0x0000000000000LL, 0x0000000000000000ULL, -16383)
11+
#define QUAD_PRECISION_ONE sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 0)
12+
#define QUAD_PRECISION_INF sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 16384)
13+
#define QUAD_PRECISION_NINF sleef_q(-0x1000000000000LL, 0x0000000000000000ULL, 16384)
14+
#define QUAD_PRECISION_NAN sleef_q(+0x1ffffffffffffLL, 0xffffffffffffffffULL, 16384)
15+
16+
// Additional constants
17+
#define QUAD_PRECISION_MAX_FINITE SLEEF_QUAD_MAX
18+
#define QUAD_PRECISION_MIN_FINITE Sleef_negq1(SLEEF_QUAD_MAX)
19+
#define QUAD_PRECISION_RADIX sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 1) // 2.0
20+
21+
#ifdef SLEEF_QUAD_C
22+
static const Sleef_quad SMALLEST_SUBNORMAL_VALUE = SLEEF_QUAD_DENORM_MIN;
23+
#else
24+
static const union {
25+
struct {
26+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
27+
uint64_t h, l;
28+
#else
29+
uint64_t l, h;
30+
#endif
31+
} parts;
32+
Sleef_quad value;
33+
} smallest_subnormal_const = {.parts = {
34+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
35+
.h = 0x0000000000000000ULL, .l = 0x0000000000000001ULL
36+
#else
37+
.l = 0x0000000000000001ULL, .h = 0x0000000000000000ULL
38+
#endif
39+
}};
40+
#define SMALLEST_SUBNORMAL_VALUE (smallest_subnormal_const.value)
41+
#endif
42+
43+
// Integer constants for finfo
44+
#define QUAD_NMANT 112 // mantissa bits (excluding implicit bit)
45+
#define QUAD_MIN_EXP -16382 // minimum exponent for normalized numbers
46+
#define QUAD_MAX_EXP 16384 // maximum exponent
47+
#define QUAD_DECIMAL_DIGITS 33 // decimal digits of precision
48+
49+
typedef enum ConstantResultType {
50+
CONSTANT_QUAD, // Sleef_quad value
51+
CONSTANT_INT64, // int64_t value
52+
CONSTANT_ERROR // Error occurred
53+
} ConstantResultType;
54+
55+
typedef struct ConstantResult {
56+
ConstantResultType type;
57+
union {
58+
Sleef_quad quad_value;
59+
int64_t int_value;
60+
} data;
61+
} ConstantResult;
62+
63+
64+
static inline ConstantResult get_sleef_constant_by_name(const char* constant_name) {
65+
ConstantResult result;
66+
67+
if (strcmp(constant_name, "pi") == 0) {
68+
result.type = CONSTANT_QUAD;
69+
result.data.quad_value = SLEEF_M_PIq;
70+
}
71+
else if (strcmp(constant_name, "e") == 0) {
72+
result.type = CONSTANT_QUAD;
73+
result.data.quad_value = SLEEF_M_Eq;
74+
}
75+
else if (strcmp(constant_name, "log2e") == 0) {
76+
result.type = CONSTANT_QUAD;
77+
result.data.quad_value = SLEEF_M_LOG2Eq;
78+
}
79+
else if (strcmp(constant_name, "log10e") == 0) {
80+
result.type = CONSTANT_QUAD;
81+
result.data.quad_value = SLEEF_M_LOG10Eq;
82+
}
83+
else if (strcmp(constant_name, "ln2") == 0) {
84+
result.type = CONSTANT_QUAD;
85+
result.data.quad_value = SLEEF_M_LN2q;
86+
}
87+
else if (strcmp(constant_name, "ln10") == 0) {
88+
result.type = CONSTANT_QUAD;
89+
result.data.quad_value = SLEEF_M_LN10q;
90+
}
91+
else if (strcmp(constant_name, "max_value") == 0) {
92+
result.type = CONSTANT_QUAD;
93+
result.data.quad_value = SLEEF_QUAD_MAX;
94+
}
95+
else if (strcmp(constant_name, "epsilon") == 0) {
96+
result.type = CONSTANT_QUAD;
97+
result.data.quad_value = SLEEF_QUAD_EPSILON;
98+
}
99+
else if (strcmp(constant_name, "smallest_normal") == 0) {
100+
result.type = CONSTANT_QUAD;
101+
result.data.quad_value = SLEEF_QUAD_MIN;
102+
}
103+
else if (strcmp(constant_name, "smallest_subnormal") == 0) {
104+
result.type = CONSTANT_QUAD;
105+
result.data.quad_value = SMALLEST_SUBNORMAL_VALUE;
106+
}
107+
else if (strcmp(constant_name, "bits") == 0) {
108+
result.type = CONSTANT_INT64;
109+
result.data.int_value = sizeof(Sleef_quad) * 8;
110+
}
111+
else if (strcmp(constant_name, "precision") == 0) {
112+
result.type = CONSTANT_INT64;
113+
// precision = int(-log10(epsilon))
114+
result.data.int_value =
115+
Sleef_cast_to_int64q1(Sleef_negq1(Sleef_log10q1_u10(SLEEF_QUAD_EPSILON)));
116+
}
117+
else if (strcmp(constant_name, "resolution") == 0) {
118+
result.type = CONSTANT_QUAD;
119+
// precision = int(-log10(epsilon))
120+
int64_t precision =
121+
Sleef_cast_to_int64q1(Sleef_negq1(Sleef_log10q1_u10(SLEEF_QUAD_EPSILON)));
122+
// resolution = 10 ** (-precision)
123+
result.data.quad_value =
124+
Sleef_powq1_u10(Sleef_cast_from_int64q1(10), Sleef_cast_from_int64q1(-precision));
125+
}
126+
else {
127+
result.type = CONSTANT_ERROR;
128+
}
129+
130+
return result;
131+
}
132+
133+
#endif // QUAD_CONSTANTS_HPP

0 commit comments

Comments
 (0)