Skip to content

Commit 4826030

Browse files
authored
Merge pull request #253 from SwayamInSync/src-shift
Restructuring quaddtype to use `src` layout
2 parents c182ddb + de12da4 commit 4826030

44 files changed

Lines changed: 149 additions & 257 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/typecheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66
paths:
77
- .github/workflows/typecheck.yml
8-
- quaddtype/numpy_quaddtype/**
8+
- quaddtype/src/numpy_quaddtype/**
99
- quaddtype/meson.build
1010
- quaddtype/pyproject.toml
1111
workflow_dispatch:

quaddtype/README.md

Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
# NumPy-QuadDType
22

3+
[![PyPI](https://img.shields.io/pypi/v/numpy-quaddtype.svg)](https://pypi.org/project/numpy-quaddtype/)
4+
[![PyPI Downloads](https://static.pepy.tech/badge/numpy-quaddtype/month)](https://pepy.tech/project/numpy-quaddtype)
5+
[![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/numpy_quaddtype.svg?label=Conda%20downloads)](https://anaconda.org/conda-forge/numpy_quaddtype)
6+
[![Documentation](https://img.shields.io/badge/docs-latest-blue.svg)](https://numpy.org/numpy-user-dtypes/quaddtype/)
7+
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org)
8+
39
A cross-platform Quad (128-bit) float Data-Type for NumPy.
410

11+
**[📖 Read the full documentation](https://numpy.org/numpy-user-dtypes/quaddtype/)**
12+
13+
## Table of Contents
14+
15+
- [NumPy-QuadDType](#numpy-quaddtype)
16+
- [Table of Contents](#table-of-contents)
17+
- [Installation](#installation)
18+
- [Usage](#usage)
19+
- [Installation from source](#installation-from-source)
20+
- [Linux/Unix/macOS](#linuxunixmacos)
21+
- [Windows](#windows)
22+
- [Building with ThreadSanitizer (TSan)](#building-with-threadsanitizer-tsan)
23+
- [Building the documentation](#building-the-documentation)
24+
- [Serving the documentation](#serving-the-documentation)
25+
- [Development Tips](#development-tips)
26+
- [Cleaning the Build Directory](#cleaning-the-build-directory)
27+
528
## Installation
629

730
```bash
8-
pip install numpy
31+
pip install "numpy>=2.4"
932
pip install numpy-quaddtype
1033
```
1134

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

2649
## Installation from source
2750

28-
### Prerequisites
29-
30-
- **gcc/clang**
31-
- **CMake** (≥3.15)
32-
- **Python 3.10+**
33-
- **Git**
34-
- **NumPy >= 2.4** (build from source)
35-
3651
### Linux/Unix/macOS
3752

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

4055
```bash
4156
# setup the virtual env
4257
python3 -m venv temp
4358
source temp/bin/activate
4459

45-
# Install NumPy from source
46-
pip install "numpy @ git+https://github.com/numpy/numpy.git"
47-
4860
# Install build and test dependencies
49-
pip install pytest meson meson-python
61+
pip install pytest meson meson-python "numpy>=2.4"
5062

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

55-
python -m pip install . -v --no-build-isolation
67+
python -m pip install ".[test]" -v
5668

5769
# Run the tests
58-
cd ..
59-
python -m pytest/quaddtype/tests/
70+
python -m pytest tests
6071
```
6172

6273
### Windows
6374

64-
#### Prerequisites
65-
66-
- **Visual Studio 2017 or later** (with MSVC compiler)
67-
- **CMake** (≥3.15)
68-
- **Python 3.10+**
69-
- **Git**
70-
71-
#### Step-by-Step Installation
75+
**Prerequisites:** Visual Studio 2017+ (with MSVC), CMake (≥3.15), Python 3.11+, Git
7276

7377
1. **Setup Development Environment**
7478

@@ -98,14 +102,14 @@ python -m pytest/quaddtype/tests/
98102

99103
```powershell
100104
# Build and install the package
101-
python -m pip install . -v --no-build-isolation
105+
python -m pip install ".[test]" -v
102106
```
103107

104108
5. **Test Installation**
105109

106110
```powershell
107111
# Run tests
108-
pytest -s ..\quaddtype\tests\
112+
pytest -s tests
109113
```
110114

111115
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.
@@ -122,6 +126,7 @@ python -m pytest/quaddtype/tests/
122126
This is a development feature to help detect threading issues. To build `numpy-quaddtype` with TSan enabled, follow these steps:
123127

124128
> Use of clang is recommended with machine NOT supporting `libquadmath` (like ARM64). Set the compiler to clang/clang++ before proceeding.
129+
>
125130
> ```bash
126131
> export CC=clang
127132
> export CXX=clang++
@@ -131,46 +136,48 @@ This is a development feature to help detect threading issues. To build `numpy-q
131136
2. Create and activate a virtual environment using the TSan-enabled Python build.
132137
3. Installing dependencies:
133138
134-
```bash
135-
python -m pip install meson meson-python wheel ninja
136-
# Need NumPy built with TSan as well
137-
python -m pip install "numpy @ git+https://github.com/numpy/numpy" -C'setup-args=-Db_sanitize=thread'
138-
```
139+
```bash
140+
python -m pip install meson meson-python wheel ninja
141+
# Need NumPy built with TSan as well
142+
python -m pip install "numpy @ git+https://github.com/numpy/numpy" -C'setup-args=-Db_sanitize=thread'
143+
```
144+
139145
4. Building SLEEF with TSan:
140146
141-
```bash
142-
# clone the repository
143-
git clone -b 3.8 https://github.com/shibatch/sleef.git
144-
cd sleef
145-
146-
# Build SLEEF with TSan
147-
cmake \
148-
-DCMAKE_C_COMPILER=clang \
149-
-DCMAKE_CXX_COMPILER=clang++ \
150-
-DCMAKE_C_FLAGS="-fsanitize=thread -g -O1" \
151-
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g -O1" \
152-
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \
153-
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=thread" \
154-
-DSLEEF_BUILD_QUAD=ON \
155-
-DSLEEF_BUILD_TESTS=OFF \
156-
-S . -B build
157-
158-
cmake --build build -j
159-
160-
# Install the built library and headers into the system path (/usr/local)
161-
sudo cmake --install build --prefix=/usr/local
162-
```
147+
```bash
148+
# clone the repository
149+
git clone https://github.com/shibatch/sleef.git
150+
cd sleef
151+
git checkout 43a0252ba9331adc7fb10755021f802863678c38
152+
153+
# Build SLEEF with TSan
154+
cmake \
155+
-DCMAKE_C_COMPILER=clang \
156+
-DCMAKE_CXX_COMPILER=clang++ \
157+
-DCMAKE_C_FLAGS="-fsanitize=thread -g -O1" \
158+
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g -O1" \
159+
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \
160+
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=thread" \
161+
-DSLEEF_BUILD_QUAD=ON \
162+
-DSLEEF_BUILD_TESTS=OFF \
163+
-DCMAKE_INSTALL_PREFIX=/usr/local
164+
-S . -B build
165+
166+
cmake --build build -j --clean-first
167+
cmake --install build
168+
```
169+
163170
5. Build and install `numpy-quaddtype` with TSan:
164171
165-
```bash
166-
# SLEEF is already installed with TSan, we need to provide proper flags to numpy-quaddtype's meson file
167-
# So that it does not build SLEEF again and use the installed one.
172+
```bash
173+
# SLEEF is already installed with TSan, we need to provide proper flags to numpy-quaddtype's meson file
174+
# So that it does not build SLEEF again and use the installed one.
168175
169-
export CFLAGS="-fsanitize=thread -g -O0"
170-
export CXXFLAGS="-fsanitize=thread -g -O0"
171-
export LDFLAGS="-fsanitize=thread"
172-
python -m pip install . -vv --no-build-isolation -Csetup-args=-Db_sanitize=thread
173-
```
176+
export CFLAGS="-fsanitize=thread -g -O0"
177+
export CXXFLAGS="-fsanitize=thread -g -O0"
178+
export LDFLAGS="-fsanitize=thread"
179+
python -m pip install . -vv -Csetup-args=-Db_sanitize=thread
180+
```
174181
175182
## Building the documentation
176183
@@ -200,7 +207,17 @@ The documentation for the `numpy-quaddtype` package is built using Sphinx. To bu
200207
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:
201208
202209
```
203-
https://numpy.github.io/numpy-user-dtypes/quaddtype/
210+
https://numpy.org/numpy-user-dtypes/quaddtype/
204211
```
205212
206213
Check the `.github/workflows/build_docs.yml` file for details.
214+
215+
## Development Tips
216+
217+
### Cleaning the Build Directory
218+
219+
The subproject folders (`subprojects/sleef`, `subprojects/qblas`) are cloned as git repositories. To fully clean them, use double force:
220+
221+
```bash
222+
git clean -ffxd
223+
```

quaddtype/meson.build

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -155,53 +155,35 @@ build_includes = include_directories('.') # compile time generated headers as pe
155155
includes = include_directories(
156156
[
157157
incdir_numpy,
158-
'numpy_quaddtype/src',
158+
'src/include',
159159
]
160160
)
161161
pythoncapi_includes = pythoncapi_compat_inc
162162

163163
srcs = [
164-
'numpy_quaddtype/src/quad_common.h',
165-
'numpy_quaddtype/src/casts.h',
166-
'numpy_quaddtype/src/casts.cpp',
167-
'numpy_quaddtype/src/scalar.h',
168-
'numpy_quaddtype/src/scalar.c',
169-
'numpy_quaddtype/src/dtype.h',
170-
'numpy_quaddtype/src/dtype.c',
171-
'numpy_quaddtype/src/quaddtype_main.c',
172-
'numpy_quaddtype/src/scalar_ops.h',
173-
'numpy_quaddtype/src/scalar_ops.cpp',
174-
'numpy_quaddtype/src/ops.hpp',
175-
'numpy_quaddtype/src/dragon4.h',
176-
'numpy_quaddtype/src/dragon4.c',
177-
'numpy_quaddtype/src/quadblas_interface.h',
178-
'numpy_quaddtype/src/quadblas_interface.cpp',
179-
'numpy_quaddtype/src/umath/umath.h',
180-
'numpy_quaddtype/src/umath/umath.cpp',
181-
'numpy_quaddtype/src/umath/binary_ops.h',
182-
'numpy_quaddtype/src/umath/binary_ops.cpp',
183-
'numpy_quaddtype/src/umath/unary_ops.h',
184-
'numpy_quaddtype/src/umath/unary_ops.cpp',
185-
'numpy_quaddtype/src/umath/unary_props.h',
186-
'numpy_quaddtype/src/umath/unary_props.cpp',
187-
'numpy_quaddtype/src/umath/comparison_ops.h',
188-
'numpy_quaddtype/src/umath/comparison_ops.cpp',
189-
'numpy_quaddtype/src/umath/promoters.hpp',
190-
'numpy_quaddtype/src/umath/matmul.h',
191-
'numpy_quaddtype/src/umath/matmul.cpp',
192-
'numpy_quaddtype/src/constants.hpp',
193-
'numpy_quaddtype/src/lock.h',
194-
'numpy_quaddtype/src/lock.c',
195-
'numpy_quaddtype/src/utilities.h',
196-
'numpy_quaddtype/src/utilities.c',
164+
'src/csrc/casts.cpp',
165+
'src/csrc/scalar.c',
166+
'src/csrc/dtype.c',
167+
'src/csrc/quaddtype_main.c',
168+
'src/csrc/scalar_ops.cpp',
169+
'src/csrc/dragon4.c',
170+
'src/csrc/quadblas_interface.cpp',
171+
'src/csrc/umath/umath.cpp',
172+
'src/csrc/umath/binary_ops.cpp',
173+
'src/csrc/umath/unary_ops.cpp',
174+
'src/csrc/umath/unary_props.cpp',
175+
'src/csrc/umath/comparison_ops.cpp',
176+
'src/csrc/umath/matmul.cpp',
177+
'src/csrc/lock.c',
178+
'src/csrc/utilities.c',
197179
]
198180

199181
py.install_sources(
200182
[
201-
'numpy_quaddtype/__init__.py',
202-
'numpy_quaddtype/__init__.pyi',
203-
'numpy_quaddtype/_quaddtype_main.pyi',
204-
'numpy_quaddtype/py.typed',
183+
'src/numpy_quaddtype/__init__.py',
184+
'src/numpy_quaddtype/__init__.pyi',
185+
'src/numpy_quaddtype/_quaddtype_main.pyi',
186+
'src/numpy_quaddtype/py.typed',
205187
],
206188
subdir: 'numpy_quaddtype',
207189
pure: false

quaddtype/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build-backend = "mesonpy"
1111
[project]
1212
name = "numpy_quaddtype"
1313
description = "Quad (128-bit) float dtype for numpy"
14-
version = "0.2.0"
14+
version = "1.0.0"
1515
readme = 'README.md'
1616
license = "BSD-3-Clause"
1717
license-files = ["LICENSE"]
@@ -50,7 +50,7 @@ Documentation = "https://github.com/numpy/numpy-user-dtypes/tree/main/quaddtype"
5050
Issues = "https://github.com/numpy/numpy-user-dtypes/issues"
5151

5252
[tool.pyright]
53-
include = ["numpy_quaddtype/*.pyi"]
53+
include = ["src/numpy_quaddtype/*.pyi"]
5454
typeCheckingMode = "strict"
5555
enableTypeIgnoreComments = false
5656
reportImplicitOverride = true
@@ -59,7 +59,7 @@ reportUnnecessaryTypeIgnoreComment = true
5959
[tool.mypy]
6060
strict = true
6161
strict_equality_for_none = true
62-
exclude = ["build", "numpy_quaddtype/src", "subprojects", "tests"]
62+
exclude = ["build", "src/csrc", "subprojects", "tests"]
6363
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
6464
warn_unreachable = false
6565

quaddtype/reinstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rm -rf subprojects/pythoncapi-compat
99
rm -rf .mesonpy-*
1010

1111
python -m pip uninstall -y numpy_quaddtype
12-
python -m pip install . -vv --no-build-isolation 2>&1 | tee build_log.txt
12+
python -m pip install . -vv 2>&1 | tee build_log.txt
1313

1414
# for debugging and TSAN builds, comment the above line and uncomment all below:
1515
# export CFLAGS="-fsanitize=thread -g -O0"

0 commit comments

Comments
 (0)