numpy-quaddtype 0.1.0__tar.gz → 0.2.1__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 (47) hide show
  1. numpy_quaddtype-0.2.1/LICENSE +30 -0
  2. numpy_quaddtype-0.2.1/PKG-INFO +157 -0
  3. numpy_quaddtype-0.2.1/README.md +114 -0
  4. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/meson.build +58 -9
  5. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/casts.cpp +126 -17
  6. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/dragon4.c +18 -0
  7. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/quadblas_interface.cpp +1 -1
  8. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/quaddtype_main.c +24 -1
  9. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/scalar.c +4 -1
  10. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/comparison_ops.cpp +6 -2
  11. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/matmul.cpp +0 -3
  12. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/pyproject.toml +2 -1
  13. numpy_quaddtype-0.2.1/reinstall.sh +14 -0
  14. numpy_quaddtype-0.2.1/sdist_test.sh +10 -0
  15. numpy_quaddtype-0.2.1/subprojects/packagefiles/qblas/meson.build +8 -0
  16. numpy_quaddtype-0.2.1/subprojects/packagefiles/sleef/meson.build +64 -0
  17. numpy_quaddtype-0.2.1/subprojects/qblas.wrap +8 -0
  18. numpy_quaddtype-0.2.1/subprojects/sleef.wrap +9 -0
  19. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/tests/test_quaddtype.py +47 -0
  20. numpy_quaddtype-0.1.0/PKG-INFO +0 -170
  21. numpy_quaddtype-0.1.0/README.md +0 -158
  22. numpy_quaddtype-0.1.0/reinstall.sh +0 -21
  23. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/__init__.py +0 -0
  24. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/casts.h +0 -0
  25. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/dragon4.h +0 -0
  26. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/dtype.c +0 -0
  27. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/dtype.h +0 -0
  28. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/ops.hpp +0 -0
  29. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/quad_common.h +0 -0
  30. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/quadblas_interface.h +0 -0
  31. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/scalar.h +0 -0
  32. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/scalar_ops.cpp +0 -0
  33. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/scalar_ops.h +0 -0
  34. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/binary_ops.cpp +0 -0
  35. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/binary_ops.h +0 -0
  36. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/comparison_ops.h +0 -0
  37. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/matmul.h +0 -0
  38. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/promoters.hpp +0 -0
  39. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/umath.cpp +0 -0
  40. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/umath.h +0 -0
  41. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/unary_ops.cpp +0 -0
  42. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/unary_ops.h +0 -0
  43. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/unary_props.cpp +0 -0
  44. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/numpy_quaddtype/src/umath/unary_props.h +0 -0
  45. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/release_tracker.md +0 -0
  46. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/tests/test_dot.py +0 -0
  47. {numpy_quaddtype-0.1.0 → numpy_quaddtype-0.2.1}/tests/utils.py +0 -0
@@ -0,0 +1,30 @@
1
+ Copyright (c) 2022, NumPy Developers.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ * Neither the name of the NumPy Developers nor the names of any
17
+ contributors may be used to endorse or promote products derived
18
+ from this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.1
2
+ Name: numpy_quaddtype
3
+ Version: 0.2.1
4
+ Summary: Quad (128-bit) float dtype for numpy
5
+ Author-Email: Swayam Singh <singhswayam008@gmail.com>
6
+ License: Copyright (c) 2022, NumPy Developers.
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are
11
+ met:
12
+
13
+ * Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ * Redistributions in binary form must reproduce the above
17
+ copyright notice, this list of conditions and the following
18
+ disclaimer in the documentation and/or other materials provided
19
+ with the distribution.
20
+
21
+ * Neither the name of the NumPy Developers nor the names of any
22
+ contributors may be used to endorse or promote products derived
23
+ from this software without specific prior written permission.
24
+
25
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
+
37
+ Requires-Python: >=3.10.0
38
+ Requires-Dist: numpy
39
+ Provides-Extra: test
40
+ Requires-Dist: pytest; extra == "test"
41
+ Requires-Dist: pytest-run-parallel; extra == "test"
42
+ Description-Content-Type: text/markdown
43
+
44
+ # Numpy-QuadDType
45
+
46
+ A cross-platform Quad (128-bit) float Data-Type for NumPy.
47
+
48
+ ## Installation
49
+
50
+ ```bash
51
+ pip install numpy
52
+ pip install numpy-quaddtype
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ ```python
58
+ import numpy as np
59
+ from numpy_quaddtype import QuadPrecDType, QuadPrecision
60
+
61
+ # using sleef backend (default)
62
+ np.array([1,2,3], dtype=QuadPrecDType())
63
+ np.array([1,2,3], dtype=QuadPrecDType("sleef"))
64
+
65
+ # using longdouble backend
66
+ np.array([1,2,3], dtype=QuadPrecDType("longdouble"))
67
+ ```
68
+
69
+ ## Installation from source
70
+
71
+ #### Prerequisites
72
+
73
+ - **gcc/clang**
74
+ - **CMake** (≥3.15)
75
+ - **Python 3.10+**
76
+ - **Git**
77
+
78
+ ### Linux/Unix/macOS
79
+
80
+ Building the `numpy-quaddtype` package:
81
+
82
+ ```bash
83
+ # setup the virtual env
84
+ python3 -m venv temp
85
+ source temp/bin/activate
86
+
87
+ # Install the package
88
+ pip install numpy pytest
89
+
90
+ # To build without QBLAS (default for MSVC)
91
+ # export CFLAGS="-DDISABLE_QUADBLAS"
92
+ # export CXXFLAGS="-DDISABLE_QUADBLAS"
93
+
94
+ python -m pip install . -v
95
+
96
+ # Run the tests
97
+ cd ..
98
+ python -m pytest
99
+ ```
100
+
101
+ ### Windows
102
+
103
+ #### Prerequisites
104
+
105
+ - **Visual Studio 2017 or later** (with MSVC compiler)
106
+ - **CMake** (≥3.15)
107
+ - **Python 3.10+**
108
+ - **Git**
109
+
110
+ #### Step-by-Step Installation
111
+
112
+ 1. **Setup Development Environment**
113
+
114
+ Open a **Developer Command Prompt for VS** or **Developer PowerShell for VS** to ensure MSVC is properly configured.
115
+
116
+ 2. **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 numpy pytest ninja meson
126
+ ```
127
+
128
+ 3. **Set Environment Variables**
129
+
130
+ ```powershell
131
+ # Note: QBLAS is disabled on Windows due to MSVC compatibility issues
132
+ $env:CFLAGS = "/DDISABLE_QUADBLAS"
133
+ $env:CXXFLAGS = "/DDISABLE_QUADBLAS"
134
+ ```
135
+
136
+ 4. **Build and Install numpy-quaddtype**
137
+
138
+ ```powershell
139
+ # Build and install the package
140
+ python -m pip install . -v
141
+ ```
142
+
143
+ 5. **Test Installation**
144
+
145
+ ```powershell
146
+ # Run tests
147
+ pytest -s tests/
148
+ ```
149
+
150
+ 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.
151
+
152
+ 7. **Visual Studio Version**: The instructions assume Visual Studio 2022. For other versions, adjust the generator string:
153
+
154
+ - VS 2019: `"Visual Studio 16 2019"`
155
+ - VS 2017: `"Visual Studio 15 2017"`
156
+
157
+ 8. **Architecture**: The instructions are for x64. For x86 builds, change `-A x64` to `-A Win32`.
@@ -0,0 +1,114 @@
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
+ #### Prerequisites
29
+
30
+ - **gcc/clang**
31
+ - **CMake** (≥3.15)
32
+ - **Python 3.10+**
33
+ - **Git**
34
+
35
+ ### Linux/Unix/macOS
36
+
37
+ Building the `numpy-quaddtype` package:
38
+
39
+ ```bash
40
+ # setup the virtual env
41
+ python3 -m venv temp
42
+ source temp/bin/activate
43
+
44
+ # Install the package
45
+ pip install numpy pytest
46
+
47
+ # To build without QBLAS (default for MSVC)
48
+ # export CFLAGS="-DDISABLE_QUADBLAS"
49
+ # export CXXFLAGS="-DDISABLE_QUADBLAS"
50
+
51
+ python -m pip install . -v
52
+
53
+ # Run the tests
54
+ cd ..
55
+ python -m pytest
56
+ ```
57
+
58
+ ### Windows
59
+
60
+ #### Prerequisites
61
+
62
+ - **Visual Studio 2017 or later** (with MSVC compiler)
63
+ - **CMake** (≥3.15)
64
+ - **Python 3.10+**
65
+ - **Git**
66
+
67
+ #### Step-by-Step Installation
68
+
69
+ 1. **Setup Development Environment**
70
+
71
+ Open a **Developer Command Prompt for VS** or **Developer PowerShell for VS** to ensure MSVC is properly configured.
72
+
73
+ 2. **Setup Python Environment**
74
+
75
+ ```powershell
76
+ # Create and activate virtual environment
77
+ python -m venv numpy_quad_env
78
+ .\numpy_quad_env\Scripts\Activate.ps1
79
+
80
+ # Install build dependencies
81
+ pip install -U pip
82
+ pip install numpy pytest ninja meson
83
+ ```
84
+
85
+ 3. **Set Environment Variables**
86
+
87
+ ```powershell
88
+ # Note: QBLAS is disabled on Windows due to MSVC compatibility issues
89
+ $env:CFLAGS = "/DDISABLE_QUADBLAS"
90
+ $env:CXXFLAGS = "/DDISABLE_QUADBLAS"
91
+ ```
92
+
93
+ 4. **Build and Install numpy-quaddtype**
94
+
95
+ ```powershell
96
+ # Build and install the package
97
+ python -m pip install . -v
98
+ ```
99
+
100
+ 5. **Test Installation**
101
+
102
+ ```powershell
103
+ # Run tests
104
+ pytest -s tests/
105
+ ```
106
+
107
+ 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.
108
+
109
+ 7. **Visual Studio Version**: The instructions assume Visual Studio 2022. For other versions, adjust the generator string:
110
+
111
+ - VS 2019: `"Visual Studio 16 2019"`
112
+ - VS 2017: `"Visual Studio 15 2017"`
113
+
114
+ 8. **Architecture**: The instructions are for x64. For x86 builds, change `-A x64` to `-A Win32`.
@@ -13,27 +13,77 @@ if is_windows
13
13
  add_project_arguments('-DWIN32', '-D_WINDOWS', language : ['c', 'cpp'])
14
14
  endif
15
15
 
16
- sleef_dep = [
17
- c.find_library('sleef', required : true),
18
- c.find_library('sleefquad', required : true)
19
- ]
16
+ qblas_dep = dependency('qblas', fallback: ['qblas', 'qblas_dep'])
17
+
18
+ sleef_subproj = subproject('sleef', required: true)
19
+ sleef_dep = sleef_subproj.get_variable('sleef_dep')
20
+ sleefquad_dep = sleef_subproj.get_variable('sleefquad_dep')
20
21
 
21
22
  incdir_numpy = run_command(py,
22
23
  ['-c', 'import numpy; print(numpy.get_include())'],
23
24
  check : true
24
25
  ).stdout().strip()
25
26
 
27
+ npymath_path = incdir_numpy / '..' / 'lib'
28
+ npymath_lib = c.find_library('npymath', dirs: npymath_path)
29
+
30
+ dependencies = [py_dep, qblas_dep, sleef_dep, sleefquad_dep, npymath_lib]
31
+
26
32
  # Add OpenMP dependency (optional, for threading)
27
- openmp_dep = dependency('openmp', required: false)
28
- dependencies = [sleef_dep, py_dep]
33
+ openmp_dep = dependency('openmp', required: false, static: false)
29
34
  if openmp_dep.found()
30
35
  dependencies += openmp_dep
31
36
  endif
32
37
 
38
+ # compiler flags for QBLAS compatibility
39
+ if not is_windows
40
+ # QBLAS requires extended numeric literals for Q suffix support
41
+ # if compiler supports (usually gcc)
42
+ if cpp.has_argument('-fext-numeric-literals')
43
+ add_project_arguments('-fext-numeric-literals', language: 'cpp')
44
+ endif
45
+ endif
46
+
47
+ # Thread-local storage detection (borrowed from NumPy)
48
+ optional_variable_attributes = [
49
+ ['thread_local', 'HAVE_THREAD_LOCAL'], # C23
50
+ ['_Thread_local', 'HAVE__THREAD_LOCAL'], # C11/C17
51
+ ['__thread', 'HAVE___THREAD'], # GCC/Clang
52
+ ['__declspec(thread)', 'HAVE___DECLSPEC_THREAD_'] # MSVC
53
+ ]
54
+
55
+ if not is_variable('cdata')
56
+ cdata = configuration_data()
57
+ endif
58
+
59
+ foreach optional_attr: optional_variable_attributes
60
+ attr = optional_attr[0]
61
+ code = '''
62
+ #pragma GCC diagnostic error "-Wattributes"
63
+ #pragma clang diagnostic error "-Wattributes"
64
+
65
+ int @0@ foo;
66
+
67
+ int main() {
68
+ return 0;
69
+ }
70
+ '''.format(attr)
71
+
72
+ if c.compiles(code, name: optional_attr[0])
73
+ cdata.set10(optional_attr[1], true)
74
+ message('Thread-local storage support found: @0@'.format(attr))
75
+ endif
76
+ endforeach
77
+
78
+ configure_file(
79
+ output: 'quaddtype_config.h',
80
+ configuration: cdata
81
+ )
82
+
83
+ build_includes = include_directories('.') # compile time generated headers as per system
33
84
  includes = include_directories(
34
85
  [
35
86
  incdir_numpy,
36
- 'numpy_quaddtype/QBLAS/include',
37
87
  'numpy_quaddtype/src',
38
88
  ]
39
89
  )
@@ -79,10 +129,9 @@ py.install_sources(
79
129
 
80
130
  py.extension_module('_quaddtype_main',
81
131
  srcs,
82
- link_args: is_windows ? ['/DEFAULTLIB:sleef', '/DEFAULTLIB:sleefquad'] : ['-lsleef', '-lsleefquad'],
83
132
  link_language: 'cpp',
84
133
  dependencies: dependencies,
85
134
  install: true,
86
135
  subdir: 'numpy_quaddtype',
87
- include_directories: includes
136
+ include_directories: [includes, build_includes],
88
137
  )
@@ -9,6 +9,7 @@ extern "C" {
9
9
  #include <Python.h>
10
10
 
11
11
  #include "numpy/arrayobject.h"
12
+ #include "numpy/halffloat.h"
12
13
  #include "numpy/ndarraytypes.h"
13
14
  #include "numpy/dtype_api.h"
14
15
  }
@@ -20,7 +21,7 @@ extern "C" {
20
21
  #include "casts.h"
21
22
  #include "dtype.h"
22
23
 
23
- #define NUM_CASTS 29 // 14 to_casts + 14 from_casts + 1 quad_to_quad
24
+ #define NUM_CASTS 34 // 16 to_casts + 16 from_casts + 1 quad_to_quad + 1 void_to_quad
24
25
 
25
26
  static NPY_CASTING
26
27
  quad_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self),
@@ -30,9 +31,6 @@ quad_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self),
30
31
  {
31
32
  NPY_CASTING casting = NPY_NO_CASTING;
32
33
 
33
- if (given_descrs[0]->backend != given_descrs[1]->backend)
34
- casting = NPY_UNSAFE_CASTING;
35
-
36
34
  Py_INCREF(given_descrs[0]);
37
35
  loop_descrs[0] = given_descrs[0];
38
36
 
@@ -43,6 +41,9 @@ quad_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self),
43
41
  else {
44
42
  Py_INCREF(given_descrs[1]);
45
43
  loop_descrs[1] = given_descrs[1];
44
+ if (given_descrs[0]->backend != given_descrs[1]->backend) {
45
+ casting = NPY_UNSAFE_CASTING;
46
+ }
46
47
  }
47
48
 
48
49
  *view_offset = 0;
@@ -150,15 +151,48 @@ quad_to_quad_strided_loop_aligned(PyArrayMethod_Context *context, char *const da
150
151
  return 0;
151
152
  }
152
153
 
154
+
155
+ static NPY_CASTING
156
+ void_to_quad_resolve_descriptors(PyObject *NPY_UNUSED(self), PyArray_DTypeMeta *dtypes[2],
157
+ PyArray_Descr *given_descrs[2], PyArray_Descr *loop_descrs[2],
158
+ npy_intp *view_offset)
159
+ {
160
+ PyErr_SetString(PyExc_TypeError,
161
+ "Void to QuadPrecision cast is not implemented");
162
+ return (NPY_CASTING)-1;
163
+ }
164
+
165
+ static int
166
+ void_to_quad_strided_loop(PyArrayMethod_Context *context, char *const data[],
167
+ npy_intp const dimensions[], npy_intp const strides[],
168
+ void *NPY_UNUSED(auxdata))
169
+ {
170
+ PyErr_SetString(PyExc_RuntimeError, "void_to_quad_strided_loop should not be called");
171
+ return -1;
172
+ }
173
+
174
+
175
+ // Tag dispatching to ensure npy_bool/npy_ubyte and npy_half/npy_ushort do not alias in templates
176
+ // see e.g. https://stackoverflow.com/q/32522279
177
+ struct spec_npy_bool {};
178
+ struct spec_npy_half {};
179
+
180
+ template<typename T>
181
+ struct NpyType { typedef T TYPE; };
182
+ template<>
183
+ struct NpyType<spec_npy_bool>{ typedef npy_bool TYPE; };
184
+ template<>
185
+ struct NpyType<spec_npy_half>{ typedef npy_half TYPE; };
186
+
153
187
  // Casting from other types to QuadDType
154
188
 
155
189
  template <typename T>
156
190
  static inline quad_value
157
- to_quad(T x, QuadBackendType backend);
191
+ to_quad(typename NpyType<T>::TYPE x, QuadBackendType backend);
158
192
 
159
193
  template <>
160
194
  inline quad_value
161
- to_quad<npy_bool>(npy_bool x, QuadBackendType backend)
195
+ to_quad<spec_npy_bool>(npy_bool x, QuadBackendType backend)
162
196
  {
163
197
  quad_value result;
164
198
  if (backend == BACKEND_SLEEF) {
@@ -184,6 +218,20 @@ to_quad<npy_byte>(npy_byte x, QuadBackendType backend)
184
218
  return result;
185
219
  }
186
220
 
221
+ template <>
222
+ inline quad_value
223
+ to_quad<npy_ubyte>(npy_ubyte x, QuadBackendType backend)
224
+ {
225
+ quad_value result;
226
+ if (backend == BACKEND_SLEEF) {
227
+ result.sleef_value = Sleef_cast_from_uint64q1(x);
228
+ }
229
+ else {
230
+ result.longdouble_value = (long double)x;
231
+ }
232
+ return result;
233
+ }
234
+
187
235
  template <>
188
236
  inline quad_value
189
237
  to_quad<npy_short>(npy_short x, QuadBackendType backend)
@@ -295,6 +343,21 @@ to_quad<npy_ulonglong>(npy_ulonglong x, QuadBackendType backend)
295
343
  }
296
344
  return result;
297
345
  }
346
+
347
+ template <>
348
+ inline quad_value
349
+ to_quad<spec_npy_half>(npy_half x, QuadBackendType backend)
350
+ {
351
+ quad_value result;
352
+ if (backend == BACKEND_SLEEF) {
353
+ result.sleef_value = Sleef_cast_from_doubleq1(npy_half_to_double(x));
354
+ }
355
+ else {
356
+ result.longdouble_value = (long double)npy_half_to_double(x);
357
+ }
358
+ return result;
359
+ }
360
+
298
361
  template <>
299
362
  inline quad_value
300
363
  to_quad<float>(float x, QuadBackendType backend)
@@ -374,10 +437,10 @@ numpy_to_quad_strided_loop_unaligned(PyArrayMethod_Context *context, char *const
374
437
  size_t elem_size = (backend == BACKEND_SLEEF) ? sizeof(Sleef_quad) : sizeof(long double);
375
438
 
376
439
  while (N--) {
377
- T in_val;
440
+ typename NpyType<T>::TYPE in_val;
378
441
  quad_value out_val;
379
442
 
380
- memcpy(&in_val, in_ptr, sizeof(T));
443
+ memcpy(&in_val, in_ptr, sizeof(typename NpyType<T>::TYPE));
381
444
  out_val = to_quad<T>(in_val, backend);
382
445
  memcpy(out_ptr, &out_val, elem_size);
383
446
 
@@ -401,7 +464,7 @@ numpy_to_quad_strided_loop_aligned(PyArrayMethod_Context *context, char *const d
401
464
  QuadBackendType backend = descr_out->backend;
402
465
 
403
466
  while (N--) {
404
- T in_val = *(T *)in_ptr;
467
+ typename NpyType<T>::TYPE in_val = *(typename NpyType<T>::TYPE *)in_ptr;
405
468
  quad_value out_val = to_quad<T>(in_val, backend);
406
469
 
407
470
  if (backend == BACKEND_SLEEF) {
@@ -420,12 +483,12 @@ numpy_to_quad_strided_loop_aligned(PyArrayMethod_Context *context, char *const d
420
483
  // Casting from QuadDType to other types
421
484
 
422
485
  template <typename T>
423
- static inline T
486
+ static inline typename NpyType<T>::TYPE
424
487
  from_quad(quad_value x, QuadBackendType backend);
425
488
 
426
489
  template <>
427
490
  inline npy_bool
428
- from_quad<npy_bool>(quad_value x, QuadBackendType backend)
491
+ from_quad<spec_npy_bool>(quad_value x, QuadBackendType backend)
429
492
  {
430
493
  if (backend == BACKEND_SLEEF) {
431
494
  return Sleef_cast_to_int64q1(x.sleef_value) != 0;
@@ -447,6 +510,18 @@ from_quad<npy_byte>(quad_value x, QuadBackendType backend)
447
510
  }
448
511
  }
449
512
 
513
+ template <>
514
+ inline npy_ubyte
515
+ from_quad<npy_ubyte>(quad_value x, QuadBackendType backend)
516
+ {
517
+ if (backend == BACKEND_SLEEF) {
518
+ return (npy_ubyte)Sleef_cast_to_uint64q1(x.sleef_value);
519
+ }
520
+ else {
521
+ return (npy_ubyte)x.longdouble_value;
522
+ }
523
+ }
524
+
450
525
  template <>
451
526
  inline npy_short
452
527
  from_quad<npy_short>(quad_value x, QuadBackendType backend)
@@ -543,6 +618,18 @@ from_quad<npy_ulonglong>(quad_value x, QuadBackendType backend)
543
618
  }
544
619
  }
545
620
 
621
+ template <>
622
+ inline npy_half
623
+ from_quad<spec_npy_half>(quad_value x, QuadBackendType backend)
624
+ {
625
+ if (backend == BACKEND_SLEEF) {
626
+ return npy_double_to_half(Sleef_cast_to_doubleq1(x.sleef_value));
627
+ }
628
+ else {
629
+ return npy_double_to_half((double)x.longdouble_value);
630
+ }
631
+ }
632
+
546
633
  template <>
547
634
  inline float
548
635
  from_quad<float>(quad_value x, QuadBackendType backend)
@@ -611,8 +698,8 @@ quad_to_numpy_strided_loop_unaligned(PyArrayMethod_Context *context, char *const
611
698
  quad_value in_val;
612
699
  memcpy(&in_val, in_ptr, elem_size);
613
700
 
614
- T out_val = from_quad<T>(in_val, backend);
615
- memcpy(out_ptr, &out_val, sizeof(T));
701
+ typename NpyType<T>::TYPE out_val = from_quad<T>(in_val, backend);
702
+ memcpy(out_ptr, &out_val, sizeof(typename NpyType<T>::TYPE));
616
703
 
617
704
  in_ptr += strides[0];
618
705
  out_ptr += strides[1];
@@ -642,8 +729,8 @@ quad_to_numpy_strided_loop_aligned(PyArrayMethod_Context *context, char *const d
642
729
  in_val.longdouble_value = *(long double *)in_ptr;
643
730
  }
644
731
 
645
- T out_val = from_quad<T>(in_val, backend);
646
- *(T *)(out_ptr) = out_val;
732
+ typename NpyType<T>::TYPE out_val = from_quad<T>(in_val, backend);
733
+ *(typename NpyType<T>::TYPE *)(out_ptr) = out_val;
647
734
 
648
735
  in_ptr += strides[0];
649
736
  out_ptr += strides[1];
@@ -739,8 +826,27 @@ init_casts_internal(void)
739
826
 
740
827
  add_spec(quad2quad_spec);
741
828
 
742
- add_cast_to<npy_bool>(&PyArray_BoolDType);
829
+ PyArray_DTypeMeta **void_dtypes = new PyArray_DTypeMeta *[2]{&PyArray_VoidDType, &QuadPrecDType};
830
+ PyType_Slot *void_slots = new PyType_Slot[]{
831
+ {NPY_METH_resolve_descriptors, (void *)&void_to_quad_resolve_descriptors},
832
+ {NPY_METH_strided_loop, (void *)&void_to_quad_strided_loop},
833
+ {NPY_METH_unaligned_strided_loop, (void *)&void_to_quad_strided_loop},
834
+ {0, nullptr}};
835
+
836
+ PyArrayMethod_Spec *void_spec = new PyArrayMethod_Spec{
837
+ .name = "cast_Void_to_QuadPrec_ERROR",
838
+ .nin = 1,
839
+ .nout = 1,
840
+ .casting = NPY_UNSAFE_CASTING,
841
+ .flags = NPY_METH_SUPPORTS_UNALIGNED,
842
+ .dtypes = void_dtypes,
843
+ .slots = void_slots,
844
+ };
845
+ add_spec(void_spec);
846
+
847
+ add_cast_to<spec_npy_bool>(&PyArray_BoolDType);
743
848
  add_cast_to<npy_byte>(&PyArray_ByteDType);
849
+ add_cast_to<npy_ubyte>(&PyArray_UByteDType);
744
850
  add_cast_to<npy_short>(&PyArray_ShortDType);
745
851
  add_cast_to<npy_ushort>(&PyArray_UShortDType);
746
852
  add_cast_to<npy_int>(&PyArray_IntDType);
@@ -749,12 +855,14 @@ init_casts_internal(void)
749
855
  add_cast_to<npy_ulong>(&PyArray_ULongDType);
750
856
  add_cast_to<npy_longlong>(&PyArray_LongLongDType);
751
857
  add_cast_to<npy_ulonglong>(&PyArray_ULongLongDType);
858
+ add_cast_to<spec_npy_half>(&PyArray_HalfDType);
752
859
  add_cast_to<float>(&PyArray_FloatDType);
753
860
  add_cast_to<double>(&PyArray_DoubleDType);
754
861
  add_cast_to<long double>(&PyArray_LongDoubleDType);
755
862
 
756
- add_cast_from<npy_bool>(&PyArray_BoolDType);
863
+ add_cast_from<spec_npy_bool>(&PyArray_BoolDType);
757
864
  add_cast_from<npy_byte>(&PyArray_ByteDType);
865
+ add_cast_from<npy_ubyte>(&PyArray_UByteDType);
758
866
  add_cast_from<npy_short>(&PyArray_ShortDType);
759
867
  add_cast_from<npy_ushort>(&PyArray_UShortDType);
760
868
  add_cast_from<npy_int>(&PyArray_IntDType);
@@ -763,6 +871,7 @@ init_casts_internal(void)
763
871
  add_cast_from<npy_ulong>(&PyArray_ULongDType);
764
872
  add_cast_from<npy_longlong>(&PyArray_LongLongDType);
765
873
  add_cast_from<npy_ulonglong>(&PyArray_ULongLongDType);
874
+ add_cast_from<spec_npy_half>(&PyArray_HalfDType);
766
875
  add_cast_from<float>(&PyArray_FloatDType);
767
876
  add_cast_from<double>(&PyArray_DoubleDType);
768
877
  add_cast_from<long double>(&PyArray_LongDoubleDType);
@@ -11,6 +11,9 @@ Modifications are specific to support the SLEEF_QUAD
11
11
  #include <sleef.h>
12
12
  #include <sleefquad.h>
13
13
 
14
+ #include "quaddtype_config.h"
15
+
16
+
14
17
  #define PY_ARRAY_UNIQUE_SYMBOL QuadPrecType_ARRAY_API
15
18
  #define PY_UFUNC_UNIQUE_SYMBOL QuadPrecType_UFUNC_API
16
19
  #define NPY_NO_DEPRECATED_API NPY_2_0_API_VERSION
@@ -22,6 +25,21 @@ Modifications are specific to support the SLEEF_QUAD
22
25
  #include "dtype.h"
23
26
  #include "scalar.h"
24
27
 
28
+
29
+ #ifdef __cplusplus
30
+ #define NPY_TLS thread_local
31
+ #elif defined(HAVE_THREAD_LOCAL)
32
+ #define NPY_TLS thread_local
33
+ #elif defined(HAVE__THREAD_LOCAL)
34
+ #define NPY_TLS _Thread_local
35
+ #elif defined(HAVE___THREAD)
36
+ #define NPY_TLS __thread
37
+ #elif defined(HAVE___DECLSPEC_THREAD_)
38
+ #define NPY_TLS __declspec(thread)
39
+ #else
40
+ #define NPY_TLS
41
+ #endif
42
+
25
43
  #if 0
26
44
  #define DEBUG_ASSERT(stmnt) assert(stmnt)
27
45
  #else