Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
paths:
- .github/workflows/typecheck.yml
- quaddtype/numpy_quaddtype/**
- quaddtype/src/numpy_quaddtype/**
- quaddtype/meson.build
- quaddtype/pyproject.toml
workflow_dispatch:
Expand Down
143 changes: 80 additions & 63 deletions quaddtype/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
# NumPy-QuadDType

[![PyPI](https://img.shields.io/pypi/v/numpy-quaddtype.svg)](https://pypi.org/project/numpy-quaddtype/)
[![PyPI Downloads](https://static.pepy.tech/badge/numpy-quaddtype/month)](https://pepy.tech/project/numpy-quaddtype)
[![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/numpy_quaddtype.svg?label=Conda%20downloads)](https://anaconda.org/conda-forge/numpy_quaddtype)
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://numpy.org/numpy-user-dtypes/quaddtype/)
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org)

A cross-platform Quad (128-bit) float Data-Type for NumPy.

**[📖 Read the full documentation](https://numpy.org/numpy-user-dtypes/quaddtype/)**

## Table of Contents

- [NumPy-QuadDType](#numpy-quaddtype)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Installation from source](#installation-from-source)
- [Linux/Unix/macOS](#linuxunixmacos)
- [Windows](#windows)
- [Building with ThreadSanitizer (TSan)](#building-with-threadsanitizer-tsan)
- [Building the documentation](#building-the-documentation)
- [Serving the documentation](#serving-the-documentation)
- [Development Tips](#development-tips)
- [Cleaning the Build Directory](#cleaning-the-build-directory)

## Installation

```bash
pip install numpy
pip install "numpy>=2.4"
pip install numpy-quaddtype
```

Expand All @@ -25,50 +48,31 @@ np.array([1,2,3], dtype=QuadPrecDType("longdouble"))

## Installation from source

### Prerequisites

- **gcc/clang**
- **CMake** (≥3.15)
- **Python 3.10+**
- **Git**
- **NumPy >= 2.4** (build from source)

### Linux/Unix/macOS

Building the `numpy-quaddtype` package:
**Prerequisites:** gcc/clang, CMake (≥3.15), Python 3.11+, Git, NumPy ≥ 2.4

```bash
# setup the virtual env
python3 -m venv temp
source temp/bin/activate

# Install NumPy from source
pip install "numpy @ git+https://github.com/numpy/numpy.git"

# Install build and test dependencies
pip install pytest meson meson-python
pip install pytest meson meson-python "numpy>=2.4"

# To build without QBLAS (default for MSVC)
# export CFLAGS="-DDISABLE_QUADBLAS"
# export CXXFLAGS="-DDISABLE_QUADBLAS"

python -m pip install . -v --no-build-isolation
python -m pip install ".[test]" -v

# Run the tests
cd ..
python -m pytest/quaddtype/tests/
python -m pytest tests
```

### Windows

#### Prerequisites

- **Visual Studio 2017 or later** (with MSVC compiler)
- **CMake** (≥3.15)
- **Python 3.10+**
- **Git**

#### Step-by-Step Installation
**Prerequisites:** Visual Studio 2017+ (with MSVC), CMake (≥3.15), Python 3.11+, Git

1. **Setup Development Environment**

Expand Down Expand Up @@ -98,14 +102,14 @@ python -m pytest/quaddtype/tests/

```powershell
# Build and install the package
python -m pip install . -v --no-build-isolation
python -m pip install ".[test]" -v
```

5. **Test Installation**

```powershell
# Run tests
pytest -s ..\quaddtype\tests\
pytest -s tests
```

6. **QBLAS Disabled**: QuadBLAS optimization is automatically disabled on Windows builds due to MSVC compatibility issues. This is handled by the `-DDISABLE_QUADBLAS` compiler flag.
Expand All @@ -122,6 +126,7 @@ python -m pytest/quaddtype/tests/
This is a development feature to help detect threading issues. To build `numpy-quaddtype` with TSan enabled, follow these steps:

> Use of clang is recommended with machine NOT supporting `libquadmath` (like ARM64). Set the compiler to clang/clang++ before proceeding.
>
> ```bash
> export CC=clang
> export CXX=clang++
Expand All @@ -131,46 +136,48 @@ This is a development feature to help detect threading issues. To build `numpy-q
2. Create and activate a virtual environment using the TSan-enabled Python build.
3. Installing dependencies:

```bash
python -m pip install meson meson-python wheel ninja
# Need NumPy built with TSan as well
python -m pip install "numpy @ git+https://github.com/numpy/numpy" -C'setup-args=-Db_sanitize=thread'
```
```bash
python -m pip install meson meson-python wheel ninja
# Need NumPy built with TSan as well
python -m pip install "numpy @ git+https://github.com/numpy/numpy" -C'setup-args=-Db_sanitize=thread'
```

4. Building SLEEF with TSan:

```bash
# clone the repository
git clone -b 3.8 https://github.com/shibatch/sleef.git
cd sleef

# Build SLEEF with TSan
cmake \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_FLAGS="-fsanitize=thread -g -O1" \
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g -O1" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=thread" \
-DSLEEF_BUILD_QUAD=ON \
-DSLEEF_BUILD_TESTS=OFF \
-S . -B build

cmake --build build -j

# Install the built library and headers into the system path (/usr/local)
sudo cmake --install build --prefix=/usr/local
```
```bash
# clone the repository
git clone https://github.com/shibatch/sleef.git
cd sleef
git checkout 43a0252ba9331adc7fb10755021f802863678c38

# Build SLEEF with TSan
cmake \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_FLAGS="-fsanitize=thread -g -O1" \
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g -O1" \
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=thread" \
-DSLEEF_BUILD_QUAD=ON \
-DSLEEF_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX=/usr/local
-S . -B build

cmake --build build -j --clean-first
cmake --install build
```

5. Build and install `numpy-quaddtype` with TSan:

```bash
# SLEEF is already installed with TSan, we need to provide proper flags to numpy-quaddtype's meson file
# So that it does not build SLEEF again and use the installed one.
```bash
# SLEEF is already installed with TSan, we need to provide proper flags to numpy-quaddtype's meson file
# So that it does not build SLEEF again and use the installed one.

export CFLAGS="-fsanitize=thread -g -O0"
export CXXFLAGS="-fsanitize=thread -g -O0"
export LDFLAGS="-fsanitize=thread"
python -m pip install . -vv --no-build-isolation -Csetup-args=-Db_sanitize=thread
```
export CFLAGS="-fsanitize=thread -g -O0"
export CXXFLAGS="-fsanitize=thread -g -O0"
export LDFLAGS="-fsanitize=thread"
python -m pip install . -vv -Csetup-args=-Db_sanitize=thread
```

## Building the documentation

Expand Down Expand Up @@ -200,7 +207,17 @@ The documentation for the `numpy-quaddtype` package is built using Sphinx. To bu
The documentation is automatically built and served using GitHub Pages. Every time changes are pushed to the `main` branch, the documentation is rebuilt and deployed to the `gh-pages` branch of the repository. You can access the documentation at:

```
https://numpy.github.io/numpy-user-dtypes/quaddtype/
https://numpy.org/numpy-user-dtypes/quaddtype/
```

Check the `.github/workflows/build_docs.yml` file for details.

## Development Tips

### Cleaning the Build Directory

The subproject folders (`subprojects/sleef`, `subprojects/qblas`) are cloned as git repositories. To fully clean them, use double force:

```bash
git clean -ffxd
```
76 changes: 38 additions & 38 deletions quaddtype/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -155,53 +155,53 @@ build_includes = include_directories('.') # compile time generated headers as pe
includes = include_directories(
[
incdir_numpy,
'numpy_quaddtype/src',
'src/csrc',
]
)
pythoncapi_includes = pythoncapi_compat_inc

srcs = [
'numpy_quaddtype/src/quad_common.h',
'numpy_quaddtype/src/casts.h',
'numpy_quaddtype/src/casts.cpp',
'numpy_quaddtype/src/scalar.h',
'numpy_quaddtype/src/scalar.c',
'numpy_quaddtype/src/dtype.h',
'numpy_quaddtype/src/dtype.c',
'numpy_quaddtype/src/quaddtype_main.c',
'numpy_quaddtype/src/scalar_ops.h',
'numpy_quaddtype/src/scalar_ops.cpp',
'numpy_quaddtype/src/ops.hpp',
'numpy_quaddtype/src/dragon4.h',
'numpy_quaddtype/src/dragon4.c',
'numpy_quaddtype/src/quadblas_interface.h',
'numpy_quaddtype/src/quadblas_interface.cpp',
'numpy_quaddtype/src/umath/umath.h',
'numpy_quaddtype/src/umath/umath.cpp',
'numpy_quaddtype/src/umath/binary_ops.h',
'numpy_quaddtype/src/umath/binary_ops.cpp',
'numpy_quaddtype/src/umath/unary_ops.h',
'numpy_quaddtype/src/umath/unary_ops.cpp',
'numpy_quaddtype/src/umath/unary_props.h',
'numpy_quaddtype/src/umath/unary_props.cpp',
'numpy_quaddtype/src/umath/comparison_ops.h',
'numpy_quaddtype/src/umath/comparison_ops.cpp',
'numpy_quaddtype/src/umath/promoters.hpp',
'numpy_quaddtype/src/umath/matmul.h',
'numpy_quaddtype/src/umath/matmul.cpp',
'numpy_quaddtype/src/constants.hpp',
'numpy_quaddtype/src/lock.h',
'numpy_quaddtype/src/lock.c',
'numpy_quaddtype/src/utilities.h',
'numpy_quaddtype/src/utilities.c',
'src/csrc/quad_common.h',
'src/csrc/casts.h',
'src/csrc/casts.cpp',
'src/csrc/scalar.h',
'src/csrc/scalar.c',
'src/csrc/dtype.h',
'src/csrc/dtype.c',
'src/csrc/quaddtype_main.c',
'src/csrc/scalar_ops.h',
'src/csrc/scalar_ops.cpp',
'src/csrc/ops.hpp',
'src/csrc/dragon4.h',
'src/csrc/dragon4.c',
'src/csrc/quadblas_interface.h',
'src/csrc/quadblas_interface.cpp',
'src/csrc/umath/umath.h',
'src/csrc/umath/umath.cpp',
'src/csrc/umath/binary_ops.h',
'src/csrc/umath/binary_ops.cpp',
'src/csrc/umath/unary_ops.h',
'src/csrc/umath/unary_ops.cpp',
'src/csrc/umath/unary_props.h',
'src/csrc/umath/unary_props.cpp',
'src/csrc/umath/comparison_ops.h',
'src/csrc/umath/comparison_ops.cpp',
'src/csrc/umath/promoters.hpp',
'src/csrc/umath/matmul.h',
'src/csrc/umath/matmul.cpp',
'src/csrc/constants.hpp',
'src/csrc/lock.h',
'src/csrc/lock.c',
'src/csrc/utilities.h',
'src/csrc/utilities.c',
]

py.install_sources(
[
'numpy_quaddtype/__init__.py',
'numpy_quaddtype/__init__.pyi',
'numpy_quaddtype/_quaddtype_main.pyi',
'numpy_quaddtype/py.typed',
'src/numpy_quaddtype/__init__.py',
'src/numpy_quaddtype/__init__.pyi',
'src/numpy_quaddtype/_quaddtype_main.pyi',
'src/numpy_quaddtype/py.typed',
],
subdir: 'numpy_quaddtype',
pure: false
Expand Down
6 changes: 3 additions & 3 deletions quaddtype/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-backend = "mesonpy"
[project]
name = "numpy_quaddtype"
description = "Quad (128-bit) float dtype for numpy"
version = "0.2.0"
version = "1.0.0"
readme = 'README.md'
license = "BSD-3-Clause"
license-files = ["LICENSE"]
Expand Down Expand Up @@ -50,7 +50,7 @@ Documentation = "https://github.com/numpy/numpy-user-dtypes/tree/main/quaddtype"
Issues = "https://github.com/numpy/numpy-user-dtypes/issues"

[tool.pyright]
include = ["numpy_quaddtype/*.pyi"]
include = ["src/numpy_quaddtype/*.pyi"]
typeCheckingMode = "strict"
enableTypeIgnoreComments = false
reportImplicitOverride = true
Expand All @@ -59,7 +59,7 @@ reportUnnecessaryTypeIgnoreComment = true
[tool.mypy]
strict = true
strict_equality_for_none = true
exclude = ["build", "numpy_quaddtype/src", "subprojects", "tests"]
exclude = ["build", "src/csrc", "subprojects", "tests"]
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = false

Expand Down
Loading