numpy-quaddtype 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of numpy-quaddtype might be problematic. Click here for more details.

Files changed (38) hide show
  1. numpy_quaddtype-0.1.0/PKG-INFO +170 -0
  2. numpy_quaddtype-0.1.0/README.md +158 -0
  3. numpy_quaddtype-0.1.0/meson.build +88 -0
  4. numpy_quaddtype-0.1.0/numpy_quaddtype/__init__.py +45 -0
  5. numpy_quaddtype-0.1.0/numpy_quaddtype/src/casts.cpp +798 -0
  6. numpy_quaddtype-0.1.0/numpy_quaddtype/src/casts.h +21 -0
  7. numpy_quaddtype-0.1.0/numpy_quaddtype/src/dragon4.c +2024 -0
  8. numpy_quaddtype-0.1.0/numpy_quaddtype/src/dragon4.h +70 -0
  9. numpy_quaddtype-0.1.0/numpy_quaddtype/src/dtype.c +266 -0
  10. numpy_quaddtype-0.1.0/numpy_quaddtype/src/dtype.h +30 -0
  11. numpy_quaddtype-0.1.0/numpy_quaddtype/src/ops.hpp +759 -0
  12. numpy_quaddtype-0.1.0/numpy_quaddtype/src/quad_common.h +18 -0
  13. numpy_quaddtype-0.1.0/numpy_quaddtype/src/quadblas_interface.cpp +233 -0
  14. numpy_quaddtype-0.1.0/numpy_quaddtype/src/quadblas_interface.h +44 -0
  15. numpy_quaddtype-0.1.0/numpy_quaddtype/src/quaddtype_main.c +157 -0
  16. numpy_quaddtype-0.1.0/numpy_quaddtype/src/scalar.c +254 -0
  17. numpy_quaddtype-0.1.0/numpy_quaddtype/src/scalar.h +41 -0
  18. numpy_quaddtype-0.1.0/numpy_quaddtype/src/scalar_ops.cpp +243 -0
  19. numpy_quaddtype-0.1.0/numpy_quaddtype/src/scalar_ops.h +20 -0
  20. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/binary_ops.cpp +244 -0
  21. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/binary_ops.h +9 -0
  22. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/comparison_ops.cpp +240 -0
  23. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/comparison_ops.h +9 -0
  24. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/matmul.cpp +455 -0
  25. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/matmul.h +17 -0
  26. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/promoters.hpp +90 -0
  27. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/umath.cpp +122 -0
  28. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/umath.h +15 -0
  29. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/unary_ops.cpp +238 -0
  30. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/unary_ops.h +9 -0
  31. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/unary_props.cpp +152 -0
  32. numpy_quaddtype-0.1.0/numpy_quaddtype/src/umath/unary_props.h +9 -0
  33. numpy_quaddtype-0.1.0/pyproject.toml +25 -0
  34. numpy_quaddtype-0.1.0/reinstall.sh +21 -0
  35. numpy_quaddtype-0.1.0/release_tracker.md +110 -0
  36. numpy_quaddtype-0.1.0/tests/test_dot.py +692 -0
  37. numpy_quaddtype-0.1.0/tests/test_quaddtype.py +555 -0
  38. numpy_quaddtype-0.1.0/tests/utils.py +98 -0
@@ -0,0 +1,170 @@
1
+ Metadata-Version: 2.1
2
+ Name: numpy_quaddtype
3
+ Version: 0.1.0
4
+ Summary: Quad (128-bit) float dtype for numpy
5
+ Author-Email: Swayam Singh <singhswayam008@gmail.com>
6
+ Requires-Python: >=3.10.0
7
+ Requires-Dist: numpy
8
+ Provides-Extra: test
9
+ Requires-Dist: pytest; extra == "test"
10
+ Requires-Dist: pytest-run-parallel; extra == "test"
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Numpy-QuadDType
14
+
15
+ A cross-platform Quad (128-bit) float Data-Type for NumPy.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install numpy
21
+ pip install numpy-quaddtype
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```python
27
+ import numpy as np
28
+ from numpy_quaddtype import QuadPrecDType, QuadPrecision
29
+
30
+ # using sleef backend (default)
31
+ np.array([1,2,3], dtype=QuadPrecDType())
32
+ np.array([1,2,3], dtype=QuadPrecDType("sleef"))
33
+
34
+ # using longdouble backend
35
+ np.array([1,2,3], dtype=QuadPrecDType("longdouble"))
36
+ ```
37
+
38
+ ## Installation from source
39
+
40
+ The code needs the quad precision pieces of the sleef library, which is not available on most systems by default, so we have to generate that first. Choose the appropriate section below based on your operating system.
41
+
42
+ ### Linux/Unix/macOS
43
+
44
+ The below assumes one has the required pieces to build sleef (cmake and libmpfr-dev), and that one is in the package directory locally.
45
+
46
+ ```bash
47
+ git clone --branch 3.8 https://github.com/shibatch/sleef.git
48
+ cd sleef
49
+ cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
50
+ cmake --build build/ --clean-first -j
51
+ cd ..
52
+ ```
53
+
54
+ Building the `numpy-quaddtype` package from locally installed sleef:
55
+
56
+ ```bash
57
+ export SLEEF_DIR=$PWD/sleef/build
58
+ export LIBRARY_PATH=$SLEEF_DIR/lib
59
+ export C_INCLUDE_PATH=$SLEEF_DIR/include
60
+ export CPLUS_INCLUDE_PATH=$SLEEF_DIR/include
61
+
62
+ # setup the virtual env
63
+ python3 -m venv temp
64
+ source temp/bin/activate
65
+
66
+ # Install the package
67
+ pip install meson-python numpy pytest
68
+
69
+ export LDFLAGS="-Wl,-rpath,$SLEEF_DIR/lib -fopenmp -latomic -lpthread"
70
+ export CFLAGS="-fPIC"
71
+ export CXXFLAGS="-fPIC"
72
+
73
+ # To build without QBLAS (default for MSVC)
74
+ # export CFLAGS="-fPIC -DDISABLE_QUADBLAS"
75
+ # export CXXFLAGS="-fPIC -DDISABLE_QUADBLAS"
76
+
77
+ python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v'
78
+
79
+ # Run the tests
80
+ cd ..
81
+ python -m pytest
82
+ ```
83
+
84
+ ### Windows
85
+
86
+ #### Prerequisites
87
+
88
+ - **Visual Studio 2017 or later** (with MSVC compiler)
89
+ - **CMake** (≥3.15)
90
+ - **Python 3.10+**
91
+ - **Git**
92
+
93
+ #### Step-by-Step Installation
94
+
95
+ 1. **Setup Development Environment**
96
+
97
+ Open a **Developer Command Prompt for VS** or **Developer PowerShell for VS** to ensure MSVC is properly configured.
98
+
99
+ 2. **Clone and Build SLEEF**
100
+
101
+ ```powershell
102
+ # Clone SLEEF library
103
+ git clone --branch 3.8 https://github.com/shibatch/sleef.git
104
+ cd sleef
105
+
106
+ # Configure with CMake for Windows
107
+ cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
108
+
109
+ # Build and install SLEEF
110
+ cmake --build build --config Release
111
+ cmake --install build --prefix "C:/sleef" --config Release
112
+
113
+ cd ..
114
+ ```
115
+
116
+ 3. **Setup Python Environment**
117
+
118
+ ```powershell
119
+ # Create and activate virtual environment
120
+ python -m venv numpy_quad_env
121
+ .\numpy_quad_env\Scripts\Activate.ps1
122
+
123
+ # Install build dependencies
124
+ pip install -U pip
125
+ pip install meson-python numpy pytest ninja meson
126
+ ```
127
+
128
+ 4. **Set Environment Variables**
129
+
130
+ ```powershell
131
+ # Set up paths and compiler flags
132
+ $env:INCLUDE = "C:/sleef/include;$env:INCLUDE"
133
+ $env:LIB = "C:/sleef/lib;$env:LIB"
134
+ $env:PATH = "C:/sleef/bin;$env:PATH"
135
+
136
+ # Note: QBLAS is disabled on Windows due to MSVC compatibility issues
137
+ $env:CFLAGS = "/IC:/sleef/include /DDISABLE_QUADBLAS"
138
+ $env:CXXFLAGS = "/IC:/sleef/include /DDISABLE_QUADBLAS"
139
+ $env:LDFLAGS = "C:/sleef/lib/sleef.lib C:/sleef/lib/sleefquad.lib"
140
+ ```
141
+
142
+ 5. **Build and Install numpy-quaddtype**
143
+
144
+ ```powershell
145
+ # Ensure submodules are initialized
146
+ git submodule update --init --recursive
147
+
148
+ # Build and install the package
149
+ python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v'
150
+ ```
151
+
152
+ 6. **Test Installation**
153
+
154
+ ```powershell
155
+ # Run tests
156
+ pytest -s tests/
157
+ ```
158
+
159
+ 1. **QBLAS Disabled**: QuadBLAS optimization is automatically disabled on Windows builds due to MSVC compatibility issues. This is handled by the `-DDISABLE_QUADBLAS` compiler flag.
160
+
161
+ 2. **Visual Studio Version**: The instructions assume Visual Studio 2022. For other versions, adjust the generator string:
162
+ - VS 2019: `"Visual Studio 16 2019"`
163
+ - VS 2017: `"Visual Studio 15 2017"`
164
+
165
+ 3. **Architecture**: The instructions are for x64. For x86 builds, change `-A x64` to `-A Win32`.
166
+
167
+ 4. **Alternative SLEEF Location**: If you prefer to install SLEEF elsewhere, update all path references accordingly.
168
+
169
+ #### Windows Troubleshooting
170
+ - **Link errors**: Verify that `sleef.lib` and `sleefquad.lib` exist in `C:/sleef/lib/`
@@ -0,0 +1,158 @@
1
+ # Numpy-QuadDType
2
+
3
+ A cross-platform Quad (128-bit) float Data-Type for NumPy.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install numpy
9
+ pip install numpy-quaddtype
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```python
15
+ import numpy as np
16
+ from numpy_quaddtype import QuadPrecDType, QuadPrecision
17
+
18
+ # using sleef backend (default)
19
+ np.array([1,2,3], dtype=QuadPrecDType())
20
+ np.array([1,2,3], dtype=QuadPrecDType("sleef"))
21
+
22
+ # using longdouble backend
23
+ np.array([1,2,3], dtype=QuadPrecDType("longdouble"))
24
+ ```
25
+
26
+ ## Installation from source
27
+
28
+ The code needs the quad precision pieces of the sleef library, which is not available on most systems by default, so we have to generate that first. Choose the appropriate section below based on your operating system.
29
+
30
+ ### Linux/Unix/macOS
31
+
32
+ The below assumes one has the required pieces to build sleef (cmake and libmpfr-dev), and that one is in the package directory locally.
33
+
34
+ ```bash
35
+ git clone --branch 3.8 https://github.com/shibatch/sleef.git
36
+ cd sleef
37
+ cmake -S . -B build -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
38
+ cmake --build build/ --clean-first -j
39
+ cd ..
40
+ ```
41
+
42
+ Building the `numpy-quaddtype` package from locally installed sleef:
43
+
44
+ ```bash
45
+ export SLEEF_DIR=$PWD/sleef/build
46
+ export LIBRARY_PATH=$SLEEF_DIR/lib
47
+ export C_INCLUDE_PATH=$SLEEF_DIR/include
48
+ export CPLUS_INCLUDE_PATH=$SLEEF_DIR/include
49
+
50
+ # setup the virtual env
51
+ python3 -m venv temp
52
+ source temp/bin/activate
53
+
54
+ # Install the package
55
+ pip install meson-python numpy pytest
56
+
57
+ export LDFLAGS="-Wl,-rpath,$SLEEF_DIR/lib -fopenmp -latomic -lpthread"
58
+ export CFLAGS="-fPIC"
59
+ export CXXFLAGS="-fPIC"
60
+
61
+ # To build without QBLAS (default for MSVC)
62
+ # export CFLAGS="-fPIC -DDISABLE_QUADBLAS"
63
+ # export CXXFLAGS="-fPIC -DDISABLE_QUADBLAS"
64
+
65
+ python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v'
66
+
67
+ # Run the tests
68
+ cd ..
69
+ python -m pytest
70
+ ```
71
+
72
+ ### Windows
73
+
74
+ #### Prerequisites
75
+
76
+ - **Visual Studio 2017 or later** (with MSVC compiler)
77
+ - **CMake** (≥3.15)
78
+ - **Python 3.10+**
79
+ - **Git**
80
+
81
+ #### Step-by-Step Installation
82
+
83
+ 1. **Setup Development Environment**
84
+
85
+ Open a **Developer Command Prompt for VS** or **Developer PowerShell for VS** to ensure MSVC is properly configured.
86
+
87
+ 2. **Clone and Build SLEEF**
88
+
89
+ ```powershell
90
+ # Clone SLEEF library
91
+ git clone --branch 3.8 https://github.com/shibatch/sleef.git
92
+ cd sleef
93
+
94
+ # Configure with CMake for Windows
95
+ cmake -S . -B build -G "Visual Studio 17 2022" -A x64 -DSLEEF_BUILD_QUAD:BOOL=ON -DSLEEF_BUILD_SHARED_LIBS:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
96
+
97
+ # Build and install SLEEF
98
+ cmake --build build --config Release
99
+ cmake --install build --prefix "C:/sleef" --config Release
100
+
101
+ cd ..
102
+ ```
103
+
104
+ 3. **Setup Python Environment**
105
+
106
+ ```powershell
107
+ # Create and activate virtual environment
108
+ python -m venv numpy_quad_env
109
+ .\numpy_quad_env\Scripts\Activate.ps1
110
+
111
+ # Install build dependencies
112
+ pip install -U pip
113
+ pip install meson-python numpy pytest ninja meson
114
+ ```
115
+
116
+ 4. **Set Environment Variables**
117
+
118
+ ```powershell
119
+ # Set up paths and compiler flags
120
+ $env:INCLUDE = "C:/sleef/include;$env:INCLUDE"
121
+ $env:LIB = "C:/sleef/lib;$env:LIB"
122
+ $env:PATH = "C:/sleef/bin;$env:PATH"
123
+
124
+ # Note: QBLAS is disabled on Windows due to MSVC compatibility issues
125
+ $env:CFLAGS = "/IC:/sleef/include /DDISABLE_QUADBLAS"
126
+ $env:CXXFLAGS = "/IC:/sleef/include /DDISABLE_QUADBLAS"
127
+ $env:LDFLAGS = "C:/sleef/lib/sleef.lib C:/sleef/lib/sleefquad.lib"
128
+ ```
129
+
130
+ 5. **Build and Install numpy-quaddtype**
131
+
132
+ ```powershell
133
+ # Ensure submodules are initialized
134
+ git submodule update --init --recursive
135
+
136
+ # Build and install the package
137
+ python -m pip install . -v --no-build-isolation -Cbuilddir=build -C'compile-args=-v'
138
+ ```
139
+
140
+ 6. **Test Installation**
141
+
142
+ ```powershell
143
+ # Run tests
144
+ pytest -s tests/
145
+ ```
146
+
147
+ 1. **QBLAS Disabled**: QuadBLAS optimization is automatically disabled on Windows builds due to MSVC compatibility issues. This is handled by the `-DDISABLE_QUADBLAS` compiler flag.
148
+
149
+ 2. **Visual Studio Version**: The instructions assume Visual Studio 2022. For other versions, adjust the generator string:
150
+ - VS 2019: `"Visual Studio 16 2019"`
151
+ - VS 2017: `"Visual Studio 15 2017"`
152
+
153
+ 3. **Architecture**: The instructions are for x64. For x86 builds, change `-A x64` to `-A Win32`.
154
+
155
+ 4. **Alternative SLEEF Location**: If you prefer to install SLEEF elsewhere, update all path references accordingly.
156
+
157
+ #### Windows Troubleshooting
158
+ - **Link errors**: Verify that `sleef.lib` and `sleefquad.lib` exist in `C:/sleef/lib/`
@@ -0,0 +1,88 @@
1
+ project('numpy_quaddtype', 'c', 'cpp', default_options : ['cpp_std=c++20', 'b_pie=true'])
2
+
3
+ py_mod = import('python')
4
+ py = py_mod.find_installation()
5
+ py_dep = py.dependency()
6
+
7
+ c = meson.get_compiler('c')
8
+ cpp = meson.get_compiler('cpp')
9
+
10
+ is_windows = build_machine.system() == 'windows'
11
+
12
+ if is_windows
13
+ add_project_arguments('-DWIN32', '-D_WINDOWS', language : ['c', 'cpp'])
14
+ endif
15
+
16
+ sleef_dep = [
17
+ c.find_library('sleef', required : true),
18
+ c.find_library('sleefquad', required : true)
19
+ ]
20
+
21
+ incdir_numpy = run_command(py,
22
+ ['-c', 'import numpy; print(numpy.get_include())'],
23
+ check : true
24
+ ).stdout().strip()
25
+
26
+ # Add OpenMP dependency (optional, for threading)
27
+ openmp_dep = dependency('openmp', required: false)
28
+ dependencies = [sleef_dep, py_dep]
29
+ if openmp_dep.found()
30
+ dependencies += openmp_dep
31
+ endif
32
+
33
+ includes = include_directories(
34
+ [
35
+ incdir_numpy,
36
+ 'numpy_quaddtype/QBLAS/include',
37
+ 'numpy_quaddtype/src',
38
+ ]
39
+ )
40
+
41
+ srcs = [
42
+ 'numpy_quaddtype/src/quad_common.h',
43
+ 'numpy_quaddtype/src/casts.h',
44
+ 'numpy_quaddtype/src/casts.cpp',
45
+ 'numpy_quaddtype/src/scalar.h',
46
+ 'numpy_quaddtype/src/scalar.c',
47
+ 'numpy_quaddtype/src/dtype.h',
48
+ 'numpy_quaddtype/src/dtype.c',
49
+ 'numpy_quaddtype/src/quaddtype_main.c',
50
+ 'numpy_quaddtype/src/scalar_ops.h',
51
+ 'numpy_quaddtype/src/scalar_ops.cpp',
52
+ 'numpy_quaddtype/src/ops.hpp',
53
+ 'numpy_quaddtype/src/dragon4.h',
54
+ 'numpy_quaddtype/src/dragon4.c',
55
+ 'numpy_quaddtype/src/quadblas_interface.h',
56
+ 'numpy_quaddtype/src/quadblas_interface.cpp',
57
+ 'numpy_quaddtype/src/umath/umath.h',
58
+ 'numpy_quaddtype/src/umath/umath.cpp',
59
+ 'numpy_quaddtype/src/umath/binary_ops.h',
60
+ 'numpy_quaddtype/src/umath/binary_ops.cpp',
61
+ 'numpy_quaddtype/src/umath/unary_ops.h',
62
+ 'numpy_quaddtype/src/umath/unary_ops.cpp',
63
+ 'numpy_quaddtype/src/umath/unary_props.h',
64
+ 'numpy_quaddtype/src/umath/unary_props.cpp',
65
+ 'numpy_quaddtype/src/umath/comparison_ops.h',
66
+ 'numpy_quaddtype/src/umath/comparison_ops.cpp',
67
+ 'numpy_quaddtype/src/umath/promoters.hpp',
68
+ 'numpy_quaddtype/src/umath/matmul.h',
69
+ 'numpy_quaddtype/src/umath/matmul.cpp',
70
+ ]
71
+
72
+ py.install_sources(
73
+ [
74
+ 'numpy_quaddtype/__init__.py',
75
+ ],
76
+ subdir: 'numpy_quaddtype',
77
+ pure: false
78
+ )
79
+
80
+ py.extension_module('_quaddtype_main',
81
+ srcs,
82
+ link_args: is_windows ? ['/DEFAULTLIB:sleef', '/DEFAULTLIB:sleefquad'] : ['-lsleef', '-lsleefquad'],
83
+ link_language: 'cpp',
84
+ dependencies: dependencies,
85
+ install: true,
86
+ subdir: 'numpy_quaddtype',
87
+ include_directories: includes
88
+ )
@@ -0,0 +1,45 @@
1
+ from ._quaddtype_main import (
2
+ QuadPrecision,
3
+ QuadPrecDType,
4
+ is_longdouble_128,
5
+ get_sleef_constant,
6
+ set_num_threads,
7
+ get_num_threads,
8
+ get_quadblas_version
9
+ )
10
+
11
+ __all__ = [
12
+ 'QuadPrecision', 'QuadPrecDType', 'SleefQuadPrecision', 'LongDoubleQuadPrecision',
13
+ 'SleefQuadPrecDType', 'LongDoubleQuadPrecDType', 'is_longdouble_128',
14
+ # Constants
15
+ 'pi', 'e', 'log2e', 'log10e', 'ln2', 'ln10', 'max_value', 'epsilon',
16
+ 'smallest_normal', 'smallest_subnormal', 'bits', 'precision', 'resolution',
17
+ # QuadBLAS related functions
18
+ 'set_num_threads', 'get_num_threads', 'get_quadblas_version'
19
+ ]
20
+
21
+ def SleefQuadPrecision(value):
22
+ return QuadPrecision(value, backend='sleef')
23
+
24
+ def LongDoubleQuadPrecision(value):
25
+ return QuadPrecision(value, backend='longdouble')
26
+
27
+ def SleefQuadPrecDType():
28
+ return QuadPrecDType(backend='sleef')
29
+
30
+ def LongDoubleQuadPrecDType():
31
+ return QuadPrecDType(backend='longdouble')
32
+
33
+ pi = get_sleef_constant("pi")
34
+ e = get_sleef_constant("e")
35
+ log2e = get_sleef_constant("log2e")
36
+ log10e = get_sleef_constant("log10e")
37
+ ln2 = get_sleef_constant("ln2")
38
+ ln10 = get_sleef_constant("ln10")
39
+ max_value = get_sleef_constant("max_value")
40
+ epsilon = get_sleef_constant("epsilon")
41
+ smallest_normal = get_sleef_constant("smallest_normal")
42
+ smallest_subnormal = get_sleef_constant("smallest_subnormal")
43
+ bits = get_sleef_constant("bits")
44
+ precision = get_sleef_constant("precision")
45
+ resolution = get_sleef_constant("resolution")