Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .github/workflows/big_endian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ jobs:
- [
"s390x (IBM Z Big Endian)",
"s390x-linux-gnu",
"s390x/ubuntu:22.04",
"s390x/ubuntu:24.04",
"s390x",
]
- [
"s390x - baseline(Z13)",
"s390x-linux-gnu",
"s390x/ubuntu:22.04",
"s390x/ubuntu:24.04",
"s390x",
]
env:
Expand Down Expand Up @@ -107,10 +107,12 @@ jobs:
# Configure git for workspace access
git config --global --add safe.directory /workspace &&

# Install Python build dependencies
python -m pip install --upgrade pip &&
python -m pip install meson>=1.3.2 meson-python wheel numpy &&
python -m pip install pytest pytest-run-parallel pytest-timeout &&
# Install Python build dependencies (using --break-system-packages for Ubuntu 24.04)
python -m pip install --break-system-packages meson>=1.3.2 meson-python wheel ninja cython &&
echo \"Building NumPy from source (main branch)...\" &&
python -m pip install --break-system-packages git+https://github.com/numpy/numpy.git@main &&
python -c \"import numpy; print('NumPy version:', numpy.__version__)\" &&
python -m pip install --break-system-packages pytest pytest-run-parallel pytest-timeout &&

# Install system dependencies for quaddtype (SLEEF dependencies)
apt install -y libssl-dev libfftw3-dev pkg-config
Expand All @@ -134,8 +136,11 @@ jobs:
# Set OpenMP linking for cross-compilation
export LDFLAGS=\"-fopenmp\" &&

# Install quaddtype with test dependencies
python -m pip install .[test] -v --no-build-isolation --force-reinstall
# Install quaddtype without dependencies (NumPy already installed from source)
python -m pip install --break-system-packages --no-deps . -v --no-build-isolation --force-reinstall &&

# Install test dependencies separately
python -m pip install --break-system-packages pytest pytest-run-parallel pytest-timeout &&

cd ..
python -m pytest -vvv --color=yes --timeout=600 --tb=short quaddtype/tests/
Expand Down
39 changes: 27 additions & 12 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ jobs:

- name: Build wheels
env:
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"
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"
CIBW_ENABLE: cpython-prerelease cpython-freethreading
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
CIBW_BUILD_VERBOSITY: "3"
CIBW_BEFORE_ALL: |
yum update -y
yum install -y cmake gcc gcc-c++ make git pkgconfig
CIBW_BEFORE_BUILD: |
pip install meson>=1.3.2 meson-python>=0.18.0 wheel ninja
pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_ENVIRONMENT: >
LDFLAGS="-fopenmp"
CIBW_REPAIR_WHEEL_COMMAND: |
auditwheel repair -w {dest_dir} --plat manylinux_2_28_x86_64 {wheel}
CIBW_TEST_COMMAND: |
pip install {package}[test]
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
if python -c "import sys; exit(0 if hasattr(sys, '_is_gil_enabled') and not sys._is_gil_enabled() else 1)"; then
pytest --parallel-threads=10 --iterations=10 {project}/tests
else
Expand Down Expand Up @@ -93,16 +99,22 @@ jobs:

- name: Build wheels
env:
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
CIBW_ENABLE: cpython-prerelease cpython-freethreading
# CIBW_ARCHS_MACOS: ${{ matrix.os == 'macos-13' && 'x86_64' || 'arm64' }}
CIBW_BUILD_VERBOSITY: "3"
CIBW_BEFORE_BUILD: |
pip install meson>=1.3.2 meson-python>=0.18.0 wheel ninja
pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_ENVIRONMENT: >
MACOSX_DEPLOYMENT_TARGET="${{ matrix.os == 'macos-14' && '14.0' || '15.0' }}"
CIBW_REPAIR_WHEEL_COMMAND: >
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
CIBW_TEST_COMMAND: |
pip install {package}[test]
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
if python -c "import sys; exit(0 if hasattr(sys, '_is_gil_enabled') and not sys._is_gil_enabled() else 1)"; then
pytest --parallel-threads=10 --iterations=10 {project}/tests
else
Expand Down Expand Up @@ -151,20 +163,22 @@ jobs:

- name: Build wheels
env:
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
CIBW_BUILD: "cp311-* cp312-* cp313-* cp314-* cp313t-* cp314t-*"
CIBW_ENABLE: cpython-prerelease cpython-freethreading
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-*"
CIBW_SKIP: "pp* cp36-* cp37-* cp38-* cp39-* cp310-*"
CIBW_ARCHS_WINDOWS: ${{ matrix.architecture == 'x86' && 'x86' || 'AMD64' }}
CIBW_BUILD_VERBOSITY: "3"
DISTUTILS_USE_SDK: "1"
MSSdk: "1"
CIBW_BEFORE_BUILD: |
pip install meson meson-python ninja numpy
CIBW_BEFORE_BUILD: >-
pip install meson meson-python ninja wheel &&
pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_ENVIRONMENT: >
CFLAGS="/DDISABLE_QUADBLAS $CFLAGS"
CXXFLAGS="/DDISABLE_QUADBLAS $CXXFLAGS"
CIBW_REPAIR_WHEEL_COMMAND: 'delvewheel repair -w {dest_dir} {wheel} --add-path C:\sleef\bin'
CIBW_TEST_COMMAND_WINDOWS: pip install {package}[test] && pytest -s {project}/tests
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
CIBW_TEST_EXTRAS: test
shell: pwsh
run: |
Expand Down Expand Up @@ -196,14 +210,15 @@ jobs:
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build pytest
python -m pip install build pytest meson meson-python wheel ninja
python -m pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy

- name: Build SDist & test sdist
env:
LDFLAGS: "-fopenmp"
run: |
python -m build --sdist --outdir dist/
pip install dist/*.tar.gz -v
python -m build --sdist --no-isolation --outdir dist/
pip install --no-build-isolation dist/*.tar.gz -v
pytest -s tests
working-directory: ./quaddtype

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: "3.11"
- name: Install build and test dependencies
run: |
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf pandas numpy
python -m pip install -U pip build pytest unyt wheel meson ninja meson-python patchelf pandas
python -m pip install --pre --upgrade --timeout=60 --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
- name: Install asciidtype
working-directory: asciidtype
run: |
Expand Down Expand Up @@ -64,7 +65,7 @@ jobs:
working-directory: quaddtype
run: |
export LDFLAGS="-fopenmp"
python -m pip install . -v
python -m pip install . -v --no-build-isolation

- name: Run quaddtype tests
working-directory: quaddtype
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ jobs:
- uses: astral-sh/[email protected]
with:
activate-environment: true
python-version: "3.10"
python-version: "3.11"

- name: install
working-directory: quaddtype
run: uv pip install mypy pyright .
run: |
uv pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
uv pip install meson>=1.3.2 meson-python wheel ninja
uv pip install mypy pyright . --no-build-isolation
- name: pyright
working-directory: quaddtype
Expand Down
8 changes: 8 additions & 0 deletions quaddtype/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ incdir_numpy = run_command(py,
check : true
).stdout().strip()

# print numpy version used
numpy_version = run_command(py,
['-c', 'import numpy; print(numpy.__version__)'],
check : true
).stdout().strip()
message('Using NumPy version: @0@'.format(numpy_version))

npymath_path = incdir_numpy / '..' / 'lib'
npymath_lib = c.find_library('npymath', dirs: npymath_path)

Expand Down Expand Up @@ -117,6 +124,7 @@ srcs = [
'numpy_quaddtype/src/umath/promoters.hpp',
'numpy_quaddtype/src/umath/matmul.h',
'numpy_quaddtype/src/umath/matmul.cpp',
'numpy_quaddtype/src/constants.hpp',
]

py.install_sources(
Expand Down
4 changes: 2 additions & 2 deletions quaddtype/numpy_quaddtype/_quaddtype_main.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class QuadPrecision: # NOTE: It doesn't inherit from `np.generic` which is type

# Binary operators
def __add__(self, other: _CastsQuad, /) -> Self: ...
def __radd__(self, other: _CastsQuad, /) -> Self: ... # type: ignore[misc]
def __radd__(self, other: _CastsQuad, /) -> Self: ...
def __sub__(self, other: _CastsQuad, /) -> Self: ...
def __rsub__(self, other: _CastsQuad, /) -> Self: ...
def __mul__(self, other: _CastsQuad, /) -> Self: ...
def __rmul__(self, other: _CastsQuad, /) -> Self: ... # type: ignore[misc]
def __rmul__(self, other: _CastsQuad, /) -> Self: ...
def __pow__(self, other: _CastsQuad, mod: None = None, /) -> Self: ...
def __rpow__(self, other: _CastsQuad, mod: None = None, /) -> Self: ...
def __truediv__(self, other: _CastsQuad, /) -> Self: ...
Expand Down
133 changes: 133 additions & 0 deletions quaddtype/numpy_quaddtype/src/constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#ifndef QUAD_CONSTANTS_HPP
#define QUAD_CONSTANTS_HPP

#include <sleef.h>
#include <sleefquad.h>
#include <stdint.h>
#include <string.h>

// Quad precision constants using sleef_q macro
#define QUAD_PRECISION_ZERO sleef_q(+0x0000000000000LL, 0x0000000000000000ULL, -16383)
#define QUAD_PRECISION_ONE sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 0)
#define QUAD_PRECISION_INF sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 16384)
#define QUAD_PRECISION_NINF sleef_q(-0x1000000000000LL, 0x0000000000000000ULL, 16384)
#define QUAD_PRECISION_NAN sleef_q(+0x1ffffffffffffLL, 0xffffffffffffffffULL, 16384)

// Additional constants
#define QUAD_PRECISION_MAX_FINITE SLEEF_QUAD_MAX
#define QUAD_PRECISION_MIN_FINITE Sleef_negq1(SLEEF_QUAD_MAX)
#define QUAD_PRECISION_RADIX sleef_q(+0x1000000000000LL, 0x0000000000000000ULL, 1) // 2.0

#ifdef SLEEF_QUAD_C
static const Sleef_quad SMALLEST_SUBNORMAL_VALUE = SLEEF_QUAD_DENORM_MIN;
#else
static const union {
struct {
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
uint64_t h, l;
#else
uint64_t l, h;
#endif
} parts;
Sleef_quad value;
} smallest_subnormal_const = {.parts = {
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
.h = 0x0000000000000000ULL, .l = 0x0000000000000001ULL
#else
.l = 0x0000000000000001ULL, .h = 0x0000000000000000ULL
#endif
}};
#define SMALLEST_SUBNORMAL_VALUE (smallest_subnormal_const.value)
#endif

// Integer constants for finfo
#define QUAD_NMANT 112 // mantissa bits (excluding implicit bit)
#define QUAD_MIN_EXP -16382 // minimum exponent for normalized numbers
#define QUAD_MAX_EXP 16384 // maximum exponent
#define QUAD_DECIMAL_DIGITS 33 // decimal digits of precision

typedef enum ConstantResultType {
CONSTANT_QUAD, // Sleef_quad value
CONSTANT_INT64, // int64_t value
CONSTANT_ERROR // Error occurred
} ConstantResultType;

typedef struct ConstantResult {
ConstantResultType type;
union {
Sleef_quad quad_value;
int64_t int_value;
} data;
} ConstantResult;


static inline ConstantResult get_sleef_constant_by_name(const char* constant_name) {
ConstantResult result;

if (strcmp(constant_name, "pi") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_M_PIq;
}
else if (strcmp(constant_name, "e") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_M_Eq;
}
else if (strcmp(constant_name, "log2e") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_M_LOG2Eq;
}
else if (strcmp(constant_name, "log10e") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_M_LOG10Eq;
}
else if (strcmp(constant_name, "ln2") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_M_LN2q;
}
else if (strcmp(constant_name, "ln10") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_M_LN10q;
}
else if (strcmp(constant_name, "max_value") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_QUAD_MAX;
}
else if (strcmp(constant_name, "epsilon") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_QUAD_EPSILON;
}
else if (strcmp(constant_name, "smallest_normal") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SLEEF_QUAD_MIN;
}
else if (strcmp(constant_name, "smallest_subnormal") == 0) {
result.type = CONSTANT_QUAD;
result.data.quad_value = SMALLEST_SUBNORMAL_VALUE;
}
else if (strcmp(constant_name, "bits") == 0) {
result.type = CONSTANT_INT64;
result.data.int_value = sizeof(Sleef_quad) * 8;
}
else if (strcmp(constant_name, "precision") == 0) {
result.type = CONSTANT_INT64;
// precision = int(-log10(epsilon))
result.data.int_value =
Sleef_cast_to_int64q1(Sleef_negq1(Sleef_log10q1_u10(SLEEF_QUAD_EPSILON)));
}
else if (strcmp(constant_name, "resolution") == 0) {
result.type = CONSTANT_QUAD;
// precision = int(-log10(epsilon))
int64_t precision =
Sleef_cast_to_int64q1(Sleef_negq1(Sleef_log10q1_u10(SLEEF_QUAD_EPSILON)));
// resolution = 10 ** (-precision)
result.data.quad_value =
Sleef_powq1_u10(Sleef_cast_from_int64q1(10), Sleef_cast_from_int64q1(-precision));
}
else {
result.type = CONSTANT_ERROR;
}

return result;
}

#endif // QUAD_CONSTANTS_HPP
Loading
Loading