numpy-quaddtype 1.0.0__cp314-cp314t-macosx_15_0_arm64.whl
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.
- numpy_quaddtype/.dylibs/libomp.dylib +0 -0
- numpy_quaddtype/__init__.py +61 -0
- numpy_quaddtype/__init__.pyi +64 -0
- numpy_quaddtype/_quaddtype_main.cpython-314t-darwin.so +0 -0
- numpy_quaddtype/_quaddtype_main.pyi +197 -0
- numpy_quaddtype/py.typed +0 -0
- numpy_quaddtype-1.0.0.dist-info/METADATA +293 -0
- numpy_quaddtype-1.0.0.dist-info/RECORD +10 -0
- numpy_quaddtype-1.0.0.dist-info/WHEEL +6 -0
- numpy_quaddtype-1.0.0.dist-info/licenses/LICENSE +30 -0
|
Binary file
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import enum
|
|
2
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
3
|
+
|
|
4
|
+
from ._quaddtype_main import (
|
|
5
|
+
QuadPrecision,
|
|
6
|
+
QuadPrecDType,
|
|
7
|
+
is_longdouble_128,
|
|
8
|
+
get_sleef_constant,
|
|
9
|
+
set_num_threads,
|
|
10
|
+
get_num_threads,
|
|
11
|
+
get_quadblas_version
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
__version__ = version("numpy_quaddtype")
|
|
16
|
+
except PackageNotFoundError:
|
|
17
|
+
__version__ = "unknown"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class QuadBackend(enum.IntEnum):
|
|
21
|
+
"""Backend type for QuadPrecision computations."""
|
|
22
|
+
SLEEF = 0
|
|
23
|
+
LONGDOUBLE = 1
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
'QuadPrecision', 'QuadPrecDType', 'QuadBackend',
|
|
28
|
+
'SleefQuadPrecision', 'LongDoubleQuadPrecision',
|
|
29
|
+
'SleefQuadPrecDType', 'LongDoubleQuadPrecDType', 'is_longdouble_128',
|
|
30
|
+
# Constants
|
|
31
|
+
'pi', 'e', 'log2e', 'log10e', 'ln2', 'ln10', 'max_value', 'epsilon',
|
|
32
|
+
'smallest_normal', 'smallest_subnormal', 'bits', 'precision', 'resolution',
|
|
33
|
+
# QuadBLAS related functions
|
|
34
|
+
'set_num_threads', 'get_num_threads', 'get_quadblas_version'
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
def SleefQuadPrecision(value):
|
|
38
|
+
return QuadPrecision(value, backend='sleef')
|
|
39
|
+
|
|
40
|
+
def LongDoubleQuadPrecision(value):
|
|
41
|
+
return QuadPrecision(value, backend='longdouble')
|
|
42
|
+
|
|
43
|
+
def SleefQuadPrecDType():
|
|
44
|
+
return QuadPrecDType(backend='sleef')
|
|
45
|
+
|
|
46
|
+
def LongDoubleQuadPrecDType():
|
|
47
|
+
return QuadPrecDType(backend='longdouble')
|
|
48
|
+
|
|
49
|
+
pi = get_sleef_constant("pi")
|
|
50
|
+
e = get_sleef_constant("e")
|
|
51
|
+
log2e = get_sleef_constant("log2e")
|
|
52
|
+
log10e = get_sleef_constant("log10e")
|
|
53
|
+
ln2 = get_sleef_constant("ln2")
|
|
54
|
+
ln10 = get_sleef_constant("ln10")
|
|
55
|
+
max_value = get_sleef_constant("max_value")
|
|
56
|
+
epsilon = get_sleef_constant("epsilon")
|
|
57
|
+
smallest_normal = get_sleef_constant("smallest_normal")
|
|
58
|
+
smallest_subnormal = get_sleef_constant("smallest_subnormal")
|
|
59
|
+
bits = get_sleef_constant("bits")
|
|
60
|
+
precision = get_sleef_constant("precision")
|
|
61
|
+
resolution = get_sleef_constant("resolution")
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
import enum
|
|
3
|
+
|
|
4
|
+
from ._quaddtype_main import (
|
|
5
|
+
QuadPrecDType,
|
|
6
|
+
QuadPrecision,
|
|
7
|
+
_IntoQuad, # type-check only # pyright: ignore[reportPrivateUsage]
|
|
8
|
+
get_num_threads,
|
|
9
|
+
get_quadblas_version,
|
|
10
|
+
is_longdouble_128,
|
|
11
|
+
set_num_threads,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
class QuadBackend(enum.IntEnum):
|
|
15
|
+
SLEEF = 0
|
|
16
|
+
LONGDOUBLE = 1
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"QuadPrecision",
|
|
20
|
+
"QuadPrecDType",
|
|
21
|
+
"QuadBackend",
|
|
22
|
+
"SleefQuadPrecision",
|
|
23
|
+
"LongDoubleQuadPrecision",
|
|
24
|
+
"SleefQuadPrecDType",
|
|
25
|
+
"LongDoubleQuadPrecDType",
|
|
26
|
+
"is_longdouble_128",
|
|
27
|
+
"pi",
|
|
28
|
+
"e",
|
|
29
|
+
"log2e",
|
|
30
|
+
"log10e",
|
|
31
|
+
"ln2",
|
|
32
|
+
"ln10",
|
|
33
|
+
"max_value",
|
|
34
|
+
"epsilon",
|
|
35
|
+
"smallest_normal",
|
|
36
|
+
"smallest_subnormal",
|
|
37
|
+
"bits",
|
|
38
|
+
"precision",
|
|
39
|
+
"resolution",
|
|
40
|
+
"set_num_threads",
|
|
41
|
+
"get_num_threads",
|
|
42
|
+
"get_quadblas_version",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
__version__: Final[str] = ...
|
|
46
|
+
|
|
47
|
+
def SleefQuadPrecision(value: _IntoQuad) -> QuadPrecision: ...
|
|
48
|
+
def LongDoubleQuadPrecision(value: _IntoQuad) -> QuadPrecision: ...
|
|
49
|
+
def SleefQuadPrecDType() -> QuadPrecDType: ...
|
|
50
|
+
def LongDoubleQuadPrecDType() -> QuadPrecDType: ...
|
|
51
|
+
|
|
52
|
+
pi: Final[QuadPrecision] = ...
|
|
53
|
+
e: Final[QuadPrecision] = ...
|
|
54
|
+
log2e: Final[QuadPrecision] = ...
|
|
55
|
+
log10e: Final[QuadPrecision] = ...
|
|
56
|
+
ln2: Final[QuadPrecision] = ...
|
|
57
|
+
ln10: Final[QuadPrecision] = ...
|
|
58
|
+
max_value: Final[QuadPrecision] = ...
|
|
59
|
+
epsilon: Final[QuadPrecision] = ...
|
|
60
|
+
smallest_normal: Final[QuadPrecision] = ...
|
|
61
|
+
smallest_subnormal: Final[QuadPrecision] = ...
|
|
62
|
+
resolution: Final[QuadPrecision] = ...
|
|
63
|
+
bits: Final = 128
|
|
64
|
+
precision: Final = 33
|
|
Binary file
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
from typing import Any, Literal, TypeAlias, final, overload
|
|
2
|
+
import builtins
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy._typing import _128Bit # pyright: ignore[reportPrivateUsage]
|
|
5
|
+
from typing_extensions import Never, Self, override
|
|
6
|
+
|
|
7
|
+
from numpy_quaddtype import QuadBackend
|
|
8
|
+
|
|
9
|
+
_Backend: TypeAlias = Literal["sleef", "longdouble"]
|
|
10
|
+
_IntoQuad: TypeAlias = (
|
|
11
|
+
QuadPrecision
|
|
12
|
+
| float
|
|
13
|
+
| str
|
|
14
|
+
| bytes
|
|
15
|
+
| np.floating[Any]
|
|
16
|
+
| np.integer[Any]
|
|
17
|
+
| np.bool_
|
|
18
|
+
) # fmt: skip
|
|
19
|
+
_ScalarItemArg: TypeAlias = Literal[0, -1] | tuple[Literal[0, -1]] | tuple[()]
|
|
20
|
+
|
|
21
|
+
@final
|
|
22
|
+
class QuadPrecDType(np.dtype[QuadPrecision]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
|
|
23
|
+
def __new__(cls, /, backend: _Backend = "sleef") -> Self: ...
|
|
24
|
+
|
|
25
|
+
# QuadPrecDType specific attributes
|
|
26
|
+
@property
|
|
27
|
+
def backend(self) -> QuadBackend: ...
|
|
28
|
+
|
|
29
|
+
# `numpy.dtype` overrides
|
|
30
|
+
names: None # pyright: ignore[reportIncompatibleVariableOverride]
|
|
31
|
+
@property
|
|
32
|
+
@override
|
|
33
|
+
def alignment(self) -> Literal[16]: ...
|
|
34
|
+
@property
|
|
35
|
+
@override
|
|
36
|
+
def itemsize(self) -> Literal[16]: ...
|
|
37
|
+
@property
|
|
38
|
+
@override
|
|
39
|
+
def name(self) -> Literal["QuadPrecDType128"]: ...
|
|
40
|
+
@property
|
|
41
|
+
@override
|
|
42
|
+
def byteorder(self) -> Literal["|"]: ...
|
|
43
|
+
@property
|
|
44
|
+
@override
|
|
45
|
+
def char(self) -> Literal["\x00"]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
46
|
+
@property
|
|
47
|
+
@override
|
|
48
|
+
def kind(self) -> Literal["\x00"]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
49
|
+
@property
|
|
50
|
+
@override
|
|
51
|
+
def num(self) -> Literal[-1]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
52
|
+
@property
|
|
53
|
+
@override
|
|
54
|
+
def shape(self) -> tuple[()]: ...
|
|
55
|
+
@property
|
|
56
|
+
@override
|
|
57
|
+
def ndim(self) -> Literal[0]: ...
|
|
58
|
+
@property
|
|
59
|
+
@override
|
|
60
|
+
def fields(self) -> None: ...
|
|
61
|
+
@property
|
|
62
|
+
@override
|
|
63
|
+
def base(self) -> Self: ...
|
|
64
|
+
@property
|
|
65
|
+
@override
|
|
66
|
+
def subdtype(self) -> None: ...
|
|
67
|
+
@property
|
|
68
|
+
@override
|
|
69
|
+
def hasobject(self) -> Literal[False]: ...
|
|
70
|
+
@property
|
|
71
|
+
@override
|
|
72
|
+
def isbuiltin(self) -> Literal[0]: ...
|
|
73
|
+
@property
|
|
74
|
+
@override
|
|
75
|
+
def isnative(self) -> Literal[True]: ...
|
|
76
|
+
@property
|
|
77
|
+
@override
|
|
78
|
+
def isalignedstruct(self) -> Literal[False]: ...
|
|
79
|
+
@override
|
|
80
|
+
def __getitem__(self, key: Never, /) -> Self: ... # type: ignore[override]
|
|
81
|
+
|
|
82
|
+
@final
|
|
83
|
+
class QuadPrecision(np.floating[_128Bit]):
|
|
84
|
+
# NOTE: At runtime this constructor also accepts array-likes, for which it returns
|
|
85
|
+
# `np.ndarray` instances with `dtype=QuadPrecDType()`.
|
|
86
|
+
# But because of mypy limitations, it is currently impossible to annotate
|
|
87
|
+
# constructors that do not return instances of their class (or a subclass thereof).
|
|
88
|
+
# See https://github.com/python/mypy/issues/18343#issuecomment-2571784915
|
|
89
|
+
@override
|
|
90
|
+
def __new__(cls, /, value: _IntoQuad, backend: _Backend = "sleef") -> Self: ...
|
|
91
|
+
|
|
92
|
+
# numpy.floating property overrides
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
@override
|
|
96
|
+
def dtype(self) -> QuadPrecDType: ...
|
|
97
|
+
@property
|
|
98
|
+
@override
|
|
99
|
+
def real(self) -> Self: ...
|
|
100
|
+
@property
|
|
101
|
+
@override
|
|
102
|
+
def imag(self) -> Self: ...
|
|
103
|
+
|
|
104
|
+
# numpy.floating method overrides
|
|
105
|
+
|
|
106
|
+
@override
|
|
107
|
+
def item(self, arg0: _ScalarItemArg = ..., /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
108
|
+
@override
|
|
109
|
+
def tolist(self, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
110
|
+
|
|
111
|
+
# Equality operators
|
|
112
|
+
@override
|
|
113
|
+
def __eq__(self, other: object, /) -> bool: ...
|
|
114
|
+
@override
|
|
115
|
+
def __ne__(self, other: object, /) -> bool: ...
|
|
116
|
+
|
|
117
|
+
# Rich comparison operators
|
|
118
|
+
# NOTE: Unlike other numpy scalars, these return `builtins.bool`, not `np.bool`.
|
|
119
|
+
@override
|
|
120
|
+
def __lt__(self, other: _IntoQuad, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
121
|
+
@override
|
|
122
|
+
def __le__(self, other: _IntoQuad, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
123
|
+
@override
|
|
124
|
+
def __gt__(self, other: _IntoQuad, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
125
|
+
@override
|
|
126
|
+
def __ge__(self, other: _IntoQuad, /) -> bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
127
|
+
|
|
128
|
+
# Binary arithmetic operators
|
|
129
|
+
@override
|
|
130
|
+
def __add__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
131
|
+
@override
|
|
132
|
+
def __radd__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override, misc] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
133
|
+
@override
|
|
134
|
+
def __sub__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
135
|
+
@override
|
|
136
|
+
def __rsub__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
137
|
+
@override
|
|
138
|
+
def __mul__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
139
|
+
@override
|
|
140
|
+
def __rmul__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
141
|
+
@override
|
|
142
|
+
def __pow__(self, other: _IntoQuad, mod: None = None, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
143
|
+
@override
|
|
144
|
+
def __rpow__(self, other: _IntoQuad, mod: None = None, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
145
|
+
@override
|
|
146
|
+
def __truediv__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
147
|
+
@override
|
|
148
|
+
def __rtruediv__(self, other: _IntoQuad, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
|
|
149
|
+
|
|
150
|
+
# Binary modulo operators
|
|
151
|
+
@override
|
|
152
|
+
def __floordiv__(self, other: _IntoQuad, /) -> Self: ...
|
|
153
|
+
@override
|
|
154
|
+
def __rfloordiv__(self, other: _IntoQuad, /) -> Self: ...
|
|
155
|
+
@override
|
|
156
|
+
def __mod__(self, other: _IntoQuad, /) -> Self: ...
|
|
157
|
+
@override
|
|
158
|
+
def __rmod__(self, other: _IntoQuad, /) -> Self: ...
|
|
159
|
+
@override
|
|
160
|
+
def __divmod__(self, other: _IntoQuad, /) -> tuple[Self, Self]: ...
|
|
161
|
+
@override
|
|
162
|
+
def __rdivmod__(self, other: _IntoQuad, /) -> tuple[Self, Self]: ...
|
|
163
|
+
|
|
164
|
+
# NOTE: is_integer() and as_integer_ratio() are defined on numpy.floating in the
|
|
165
|
+
# stubs, but don't exist at runtime. And because QuadPrecision does not implement
|
|
166
|
+
# them, we use this hacky workaround to emulate their absence.
|
|
167
|
+
@override
|
|
168
|
+
def is_integer(self, /) -> builtins.bool: ...
|
|
169
|
+
@override
|
|
170
|
+
def as_integer_ratio(self, /) -> tuple[int, int]: ...
|
|
171
|
+
|
|
172
|
+
#
|
|
173
|
+
def is_longdouble_128() -> bool: ...
|
|
174
|
+
|
|
175
|
+
@overload
|
|
176
|
+
def get_sleef_constant(constant_name: Literal["bits", "precision"], /) -> int: ...
|
|
177
|
+
@overload
|
|
178
|
+
def get_sleef_constant(
|
|
179
|
+
constant_name: Literal[
|
|
180
|
+
"pi",
|
|
181
|
+
"e",
|
|
182
|
+
"log2e",
|
|
183
|
+
"log10e",
|
|
184
|
+
"ln2",
|
|
185
|
+
"ln10",
|
|
186
|
+
"max_value",
|
|
187
|
+
"epsilon",
|
|
188
|
+
"smallest_normal",
|
|
189
|
+
"smallest_subnormal",
|
|
190
|
+
"resolution",
|
|
191
|
+
],
|
|
192
|
+
/,
|
|
193
|
+
) -> QuadPrecision: ...
|
|
194
|
+
|
|
195
|
+
def set_num_threads(num_threads: int, /) -> None: ...
|
|
196
|
+
def get_num_threads() -> int: ...
|
|
197
|
+
def get_quadblas_version() -> str: ...
|
numpy_quaddtype/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: numpy_quaddtype
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Quad (128-bit) float dtype for numpy
|
|
5
|
+
Author-Email: Swayam Singh <singhswayam008@gmail.com>
|
|
6
|
+
Maintainer-Email: NumPy Developers <numpy-discussion@python.org>
|
|
7
|
+
License-Expression: BSD-3-Clause
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: Free Threading
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Project-URL: Repository, https://github.com/numpy/numpy-quaddtype
|
|
18
|
+
Project-URL: Documentation, https://numpy.org/numpy-quaddtype/
|
|
19
|
+
Project-URL: Issues, https://github.com/numpy/numpy-quaddtype/issues
|
|
20
|
+
Requires-Python: >=3.11.0
|
|
21
|
+
Requires-Dist: numpy>=2.4
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest; extra == "test"
|
|
24
|
+
Requires-Dist: mpmath; extra == "test"
|
|
25
|
+
Requires-Dist: pytest-run-parallel; extra == "test"
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
28
|
+
Requires-Dist: pydata-sphinx-theme; extra == "docs"
|
|
29
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
30
|
+
Requires-Dist: sphinx-design; extra == "docs"
|
|
31
|
+
Requires-Dist: sphinx-copybutton; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinxcontrib-katex; extra == "docs"
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# NumPy-QuadDType
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/numpy-quaddtype/)
|
|
38
|
+
[](https://pepy.tech/project/numpy-quaddtype)
|
|
39
|
+
[](https://anaconda.org/conda-forge/numpy_quaddtype)
|
|
40
|
+
[](https://numpy.org/numpy-quaddtype/)
|
|
41
|
+
[](https://numfocus.org)
|
|
42
|
+
|
|
43
|
+
A cross-platform Quad (128-bit) float Data-Type for NumPy.
|
|
44
|
+
|
|
45
|
+
**[📖 Read the full documentation](https://numpy.org/numpy-quaddtype/)**
|
|
46
|
+
|
|
47
|
+
## Table of Contents
|
|
48
|
+
|
|
49
|
+
- [NumPy-QuadDType](#numpy-quaddtype)
|
|
50
|
+
- [Table of Contents](#table-of-contents)
|
|
51
|
+
- [Installation](#installation)
|
|
52
|
+
- [Usage](#usage)
|
|
53
|
+
- [Installation from source](#installation-from-source)
|
|
54
|
+
- [Linux/Unix/macOS](#linuxunixmacos)
|
|
55
|
+
- [Windows](#windows)
|
|
56
|
+
- [Build Options](#build-options)
|
|
57
|
+
- [Disabling FMA (Fused Multiply-Add)](#disabling-fma-fused-multiply-add)
|
|
58
|
+
- [Building with ThreadSanitizer (TSan)](#building-with-threadsanitizer-tsan)
|
|
59
|
+
- [Building the documentation](#building-the-documentation)
|
|
60
|
+
- [Serving the documentation](#serving-the-documentation)
|
|
61
|
+
- [Development Tips](#development-tips)
|
|
62
|
+
- [Cleaning the Build Directory](#cleaning-the-build-directory)
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install "numpy>=2.4"
|
|
68
|
+
pip install numpy-quaddtype
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Or with conda-forge:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
conda install numpy_quaddtype
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Or with mamba:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
mamba install numpy_quaddtype
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Or grab the development version with
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install git+https://github.com/numpy/numpy-quaddtype.git
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import numpy as np
|
|
93
|
+
from numpy_quaddtype import QuadPrecDType, QuadPrecision
|
|
94
|
+
|
|
95
|
+
# using sleef backend (default)
|
|
96
|
+
np.array([1,2,3], dtype=QuadPrecDType())
|
|
97
|
+
np.array([1,2,3], dtype=QuadPrecDType("sleef"))
|
|
98
|
+
|
|
99
|
+
# using longdouble backend
|
|
100
|
+
np.array([1,2,3], dtype=QuadPrecDType("longdouble"))
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Installation from source
|
|
104
|
+
|
|
105
|
+
### Linux/Unix/macOS
|
|
106
|
+
|
|
107
|
+
**Prerequisites:** gcc/clang, CMake (≥3.15), Python 3.11+, Git, NumPy ≥ 2.4
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# setup the virtual env
|
|
111
|
+
python3 -m venv temp
|
|
112
|
+
source temp/bin/activate
|
|
113
|
+
|
|
114
|
+
# Install build and test dependencies
|
|
115
|
+
pip install pytest meson meson-python "numpy>=2.4"
|
|
116
|
+
|
|
117
|
+
# To build without QBLAS (default for MSVC)
|
|
118
|
+
# export CFLAGS="-DDISABLE_QUADBLAS"
|
|
119
|
+
# export CXXFLAGS="-DDISABLE_QUADBLAS"
|
|
120
|
+
|
|
121
|
+
python -m pip install ".[test]" -v
|
|
122
|
+
|
|
123
|
+
# Run the tests
|
|
124
|
+
python -m pytest tests
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Windows
|
|
128
|
+
|
|
129
|
+
**Prerequisites:** Visual Studio 2017+ (with MSVC), CMake (≥3.15), Python 3.11+, Git
|
|
130
|
+
|
|
131
|
+
1. **Setup Development Environment**
|
|
132
|
+
|
|
133
|
+
Open a **Developer Command Prompt for VS** or **Developer PowerShell for VS** to ensure MSVC is properly configured.
|
|
134
|
+
|
|
135
|
+
2. **Setup Python Environment**
|
|
136
|
+
|
|
137
|
+
```powershell
|
|
138
|
+
# Create and activate virtual environment
|
|
139
|
+
python -m venv numpy_quad_env
|
|
140
|
+
.\numpy_quad_env\Scripts\Activate.ps1
|
|
141
|
+
|
|
142
|
+
# Install build dependencies
|
|
143
|
+
pip install -U pip
|
|
144
|
+
pip install numpy pytest ninja meson
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. **Set Environment Variables**
|
|
148
|
+
|
|
149
|
+
```powershell
|
|
150
|
+
# Note: QBLAS is disabled on Windows due to MSVC compatibility issues
|
|
151
|
+
$env:CFLAGS = "/DDISABLE_QUADBLAS"
|
|
152
|
+
$env:CXXFLAGS = "/DDISABLE_QUADBLAS"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
4. **Build and Install numpy-quaddtype**
|
|
156
|
+
|
|
157
|
+
```powershell
|
|
158
|
+
# Build and install the package
|
|
159
|
+
python -m pip install ".[test]" -v
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
5. **Test Installation**
|
|
163
|
+
|
|
164
|
+
```powershell
|
|
165
|
+
# Run tests
|
|
166
|
+
pytest -s tests
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
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.
|
|
170
|
+
|
|
171
|
+
7. **Visual Studio Version**: The instructions assume Visual Studio 2022. For other versions, adjust the generator string:
|
|
172
|
+
- VS 2019: `"Visual Studio 16 2019"`
|
|
173
|
+
- VS 2017: `"Visual Studio 15 2017"`
|
|
174
|
+
|
|
175
|
+
8. **Architecture**: The instructions are for x64. For x86 builds, change `-A x64` to `-A Win32`.
|
|
176
|
+
|
|
177
|
+
## Build Options
|
|
178
|
+
|
|
179
|
+
### Disabling FMA (Fused Multiply-Add)
|
|
180
|
+
|
|
181
|
+
On older x86-64 CPUs without FMA support (e.g., Sandy Bridge / x86_64-v2), the SLEEF's `PURECFMA` scalar code path will cause illegal instruction errors. By default, FMA support is auto-detected at build time, but you can explicitly disable it:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
pip install . -Csetup-args=-Ddisable_fma=true
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
This is a workaround for a [SLEEF issue](https://github.com/shibatch/sleef/issues/707) where `PURECFMA` scalar functions are unconditionally compiled with FMA instructions even on systems that don't support them.
|
|
188
|
+
|
|
189
|
+
**When to use this option:**
|
|
190
|
+
- Building on or for x86_64-v2 (Sandy Bridge era) CPUs
|
|
191
|
+
- Cross-compiling for older x86_64 targets
|
|
192
|
+
- Running in emulators/VMs that don't expose FMA capability
|
|
193
|
+
|
|
194
|
+
## Building with ThreadSanitizer (TSan)
|
|
195
|
+
|
|
196
|
+
This is a development feature to help detect threading issues. To build `numpy-quaddtype` with TSan enabled, follow these steps:
|
|
197
|
+
|
|
198
|
+
> Use of clang is recommended with machine NOT supporting `libquadmath` (like ARM64). Set the compiler to clang/clang++ before proceeding.
|
|
199
|
+
>
|
|
200
|
+
> ```bash
|
|
201
|
+
> export CC=clang
|
|
202
|
+
> export CXX=clang++
|
|
203
|
+
> ```
|
|
204
|
+
|
|
205
|
+
1. Compile free-threaded CPython with TSan support. Follow the [Python Free-Threading Guide](https://py-free-threading.github.io/thread_sanitizer/#compile-free-threaded-cpython-with-tsan) for detailed instructions.
|
|
206
|
+
2. Create and activate a virtual environment using the TSan-enabled Python build.
|
|
207
|
+
3. Installing dependencies:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
python -m pip install meson meson-python wheel ninja
|
|
211
|
+
# Need NumPy built with TSan as well
|
|
212
|
+
python -m pip install "numpy @ git+https://github.com/numpy/numpy" -C'setup-args=-Db_sanitize=thread'
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
4. Building SLEEF with TSan:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
# clone the repository
|
|
219
|
+
git clone https://github.com/shibatch/sleef.git
|
|
220
|
+
cd sleef
|
|
221
|
+
git checkout 43a0252ba9331adc7fb10755021f802863678c38
|
|
222
|
+
|
|
223
|
+
# Build SLEEF with TSan
|
|
224
|
+
cmake \
|
|
225
|
+
-DCMAKE_C_COMPILER=clang \
|
|
226
|
+
-DCMAKE_CXX_COMPILER=clang++ \
|
|
227
|
+
-DCMAKE_C_FLAGS="-fsanitize=thread -g -O1" \
|
|
228
|
+
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g -O1" \
|
|
229
|
+
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread" \
|
|
230
|
+
-DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=thread" \
|
|
231
|
+
-DSLEEF_BUILD_QUAD=ON \
|
|
232
|
+
-DSLEEF_BUILD_TESTS=OFF \
|
|
233
|
+
-DCMAKE_INSTALL_PREFIX=/usr/local
|
|
234
|
+
-S . -B build
|
|
235
|
+
|
|
236
|
+
cmake --build build -j --clean-first
|
|
237
|
+
cmake --install build
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
5. Build and install `numpy-quaddtype` with TSan:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# SLEEF is already installed with TSan, we need to provide proper flags to numpy-quaddtype's meson file
|
|
244
|
+
# So that it does not build SLEEF again and use the installed one.
|
|
245
|
+
|
|
246
|
+
export CFLAGS="-fsanitize=thread -g -O0"
|
|
247
|
+
export CXXFLAGS="-fsanitize=thread -g -O0"
|
|
248
|
+
export LDFLAGS="-fsanitize=thread"
|
|
249
|
+
python -m pip install . -vv -Csetup-args=-Db_sanitize=thread
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Building the documentation
|
|
253
|
+
|
|
254
|
+
The documentation for the `numpy-quaddtype` package is built using Sphinx. To build the documentation, follow these steps:
|
|
255
|
+
|
|
256
|
+
1. Install the required dependencies:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
pip install ."[docs]"
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
2. Navigate to the `docs` directory and build the documentation:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
cd docs/
|
|
266
|
+
make html
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
3. The generated HTML documentation can be found in the `_build/html` directory within the `docs` folder. Open the `index.html` file in a web browser to view the documentation, or use a local server to serve the files:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
python3 -m http.server --directory _build/html
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Serving the documentation
|
|
276
|
+
|
|
277
|
+
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:
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
https://numpy.org/numpy-quaddtype/
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Check the `.github/workflows/build_docs.yml` file for details.
|
|
284
|
+
|
|
285
|
+
## Development Tips
|
|
286
|
+
|
|
287
|
+
### Cleaning the Build Directory
|
|
288
|
+
|
|
289
|
+
The subproject folders (`subprojects/sleef`, `subprojects/qblas`) are cloned as git repositories. To fully clean them, use double force:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
git clean -ffxd
|
|
293
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
numpy_quaddtype/_quaddtype_main.cpython-314t-darwin.so,sha256=hvzbu3bLbfsu3JLomu_r-g_MHkLbvaHdKK5MCUzGMGM,1076000
|
|
2
|
+
numpy_quaddtype/__init__.pyi,sha256=yiVUoVNMvUh41UVKsPPJy4jCy3rcxAjU99u_GXj3WcQ,1528
|
|
3
|
+
numpy_quaddtype/__init__.py,sha256=F0jXK4SmI9_THAqa1CBi2_57hzFVxTRixKIi83IQ1jY,1799
|
|
4
|
+
numpy_quaddtype/_quaddtype_main.pyi,sha256=TTddOAJtCZl19SohaGcMqEUqnKz_7QfYpnUar7ebfzk,7377
|
|
5
|
+
numpy_quaddtype/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
numpy_quaddtype/.dylibs/libomp.dylib,sha256=kf00qtEcVwyqr-UCkqao-HdIfpW0xskc93tohUJ0HS0,743200
|
|
7
|
+
numpy_quaddtype-1.0.0.dist-info/RECORD,,
|
|
8
|
+
numpy_quaddtype-1.0.0.dist-info/WHEEL,sha256=gWtW3fuEzXgMJhpOAm-oHttlk20PAeGIikqksd28VwI,123
|
|
9
|
+
numpy_quaddtype-1.0.0.dist-info/METADATA,sha256=1tdiWtNDQLklFqF0WoZj_L3Uiqrk87oKWGWpQuvxMCU,9445
|
|
10
|
+
numpy_quaddtype-1.0.0.dist-info/licenses/LICENSE,sha256=R89YvpdHKGUqld_OR6jHwcDC34rEF7bEHy8FHu6wX7E,1538
|
|
@@ -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.
|