-
-
Notifications
You must be signed in to change notification settings - Fork 4
Add API docs #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
juntyr
wants to merge
4
commits into
numpy:main
Choose a base branch
from
juntyr:api-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+869
−9
Open
Add API docs #49
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Constants Reference | ||
|
|
||
| Pre-defined mathematical constants with quad precision accuracy. | ||
|
|
||
| ## Mathematical Constants | ||
|
|
||
| ```{eval-rst} | ||
| .. data:: numpy_quaddtype.pi | ||
|
|
||
| The mathematical constant :math:`\pi` (pi). | ||
|
|
||
| :value: 3.14159265358979323846264338327950288... | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.e | ||
|
|
||
| Euler's number :math:`e`, the base of natural logarithms. | ||
|
|
||
| :value: 2.71828182845904523536028747135266249... | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.log2e | ||
|
|
||
| The base-2 logarithm of :math:`e`: :math:`\log_{2}{e}`. | ||
|
|
||
| :value: 1.44269504088896340735992468100189213... | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.log10e | ||
|
|
||
| The base-10 logarithm of :math:`e`: :math:`\log_{10}{e}`. | ||
|
|
||
| :value: 0.43429448190325182765112891891660508... | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.ln2 | ||
|
|
||
| The natural logarithm of 2: :math:`\log_{e}{2}`. | ||
|
|
||
| :value: 0.69314718055994530941723212145817656... | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.ln10 | ||
|
|
||
| The natural logarithm of 10: :math:`\log_{e}{10}`. | ||
|
|
||
| :value: 2.30258509299404568401799145468436420... | ||
|
|
||
| :type: QuadPrecision | ||
| ``` | ||
|
|
||
| ## Type Limits | ||
|
|
||
| ```{eval-rst} | ||
| .. data:: numpy_quaddtype.epsilon | ||
|
|
||
| Machine epsilon: the smallest positive number such that :math:`1.0 + \epsilon \neq 1.0`. | ||
|
|
||
| :value: :math:`2^{-112}` or approximately :math:`1.93 \cdot 10^{-34}` | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.max_value | ||
|
|
||
| The largest representable finite quad-precision value. | ||
|
|
||
| The largest negative representable finite quad-precision value is ``-numpy_quaddtype.max_value``. | ||
|
|
||
| :value: :math:`2^{16383} \cdot (2 - 2^{-112})` or approximately :math:`1.19 \cdot 10^{4932}` | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.smallest_normal | ||
|
|
||
| The smallest positive normal (normalized, mantissa has a leading 1 bit) quad-precision value. | ||
|
|
||
| :value: :math:`2^{-16382} \cdot (1 - 2^{-112})` or approximately :math:`3.36 \cdot 10^{-4932}` | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.smallest_subnormal | ||
|
|
||
| The smallest positive subnormal (denormalized, mantissa has a leading 0 bit) quad-precision value. | ||
|
|
||
| :value: :math:`2^{-16494}` or approximately :math:`6.48 \cdot 10^{-4966}` | ||
|
|
||
| :type: QuadPrecision | ||
|
|
||
| .. data:: numpy_quaddtype.resolution | ||
|
|
||
| The approximate decimal resolution of quad precision, i.e. `10 ** (-precision)`. | ||
|
|
||
| :value: :math:`10^{-33}` | ||
|
|
||
| :type: QuadPrecision | ||
| ``` | ||
|
|
||
| ## Type Information | ||
|
|
||
| ```{eval-rst} | ||
| .. data:: numpy_quaddtype.bits | ||
|
|
||
| The total number of bits in quad precision representation. | ||
|
|
||
| :value: 128 | ||
| :type: int | ||
|
|
||
| .. data:: numpy_quaddtype.precision | ||
|
|
||
| The approximate number of significant decimal digits. | ||
|
|
||
| :value: 33 | ||
| :type: int | ||
| ``` | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```python | ||
| from numpy_quaddtype import ( | ||
| pi, e, log2e, log10e, ln2, ln10, | ||
| epsilon, max_value, smallest_normal, | ||
| bits, precision | ||
| ) | ||
|
|
||
| # Mathematical constants | ||
| print(f"π = {pi}") | ||
| print(f"e = {e}") | ||
|
|
||
| # Verify relationships | ||
| import numpy as np | ||
| from numpy_quaddtype import QuadPrecDType | ||
|
|
||
| # e^(ln2) should equal 2 | ||
| two = np.exp(np.array(ln2)) | ||
| print(f"e^(ln2) = {two}") | ||
|
|
||
| # log2(e) * ln(2) should equal 1 | ||
| one = log2e * ln2 | ||
| print(f"log2(e) × ln(2) = {one}") | ||
|
|
||
| # Type limits | ||
| print(f"\nQuad precision uses {bits} bits") | ||
| print(f"Approximately {precision} decimal digits of precision") | ||
| print(f"Machine epsilon: {epsilon}") | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| # Core Types | ||
|
|
||
| The fundamental types provided by NumPy QuadDType. | ||
|
|
||
| ## Quad Precision Value | ||
|
|
||
| ```{eval-rst} | ||
| .. class:: numpy_quaddtype.QuadPrecision(value, backend="sleef") | ||
|
|
||
| A quad-precision (128-bit) floating-point scalar. | ||
|
|
||
| QuadPrecision is a NumPy scalar type that provides IEEE 754 binary128 | ||
| floating-point arithmetic. It can be used standalone or as elements | ||
| of NumPy arrays. | ||
|
|
||
| :param value: The value to convert to quad precision. It can be: | ||
|
|
||
| - ``float`` or ``int``: Python numeric types | ||
| - ``str``: String representation for maximum precision | ||
| - ``bytes``: Raw 16-byte representation | ||
| - ``numpy.floating`` or ``numpy.integer``: NumPy numeric types | ||
| - ``QuadPrecision``: Another QuadPrecision value | ||
| :type value: float, int, str, bytes, numpy scalar, or QuadPrecision | ||
|
|
||
| :param backend: Computation backend to use. Either ``"sleef"`` (default) | ||
| or ``"longdouble"``. | ||
| :type backend: str, optional | ||
|
|
||
| **Examples** | ||
|
|
||
| Create from different input types:: | ||
|
|
||
| >>> from numpy_quaddtype import QuadPrecision | ||
| >>> QuadPrecision(3.14) | ||
| QuadPrecision('3.14000000000000012434...') | ||
| >>> QuadPrecision("3.14159265358979323846264338327950288") | ||
| QuadPrecision('3.14159265358979323846264338327950288') | ||
| >>> QuadPrecision(42) | ||
| QuadPrecision('42.0') | ||
|
|
||
| Arithmetic operations:: | ||
|
|
||
| >>> x = QuadPrecision("1.5") | ||
| >>> y = QuadPrecision("2.5") | ||
| >>> x + y | ||
| QuadPrecision('4.0') | ||
| >>> x * y | ||
| QuadPrecision('3.75') | ||
|
|
||
| .. attribute:: dtype | ||
| :type: QuadPrecDType | ||
|
|
||
| The NumPy dtype for this scalar. | ||
|
|
||
| .. attribute:: real | ||
| :type: QuadPrecision | ||
|
|
||
| The real part (always self for QuadPrecision). | ||
|
|
||
| .. attribute:: imag | ||
| :type: QuadPrecision | ||
|
|
||
| The imaginary part (always zero for QuadPrecision). | ||
| ``` | ||
|
|
||
| ## Quad Precision DType | ||
|
|
||
| ```{eval-rst} | ||
| .. class:: numpy_quaddtype.QuadPrecDType(backend="sleef") | ||
|
|
||
| NumPy dtype for quad-precision floating-point arrays. | ||
|
|
||
| QuadPrecDType is a custom NumPy dtype that enables the creation and | ||
| manipulation of arrays containing quad-precision values. | ||
|
|
||
| :param backend: Computation backend. Either ``"sleef"`` (default) or | ||
| ``"longdouble"``. | ||
| :type backend: str, optional | ||
|
|
||
| **Examples** | ||
|
|
||
| Create arrays with QuadPrecDType:: | ||
|
|
||
| >>> import numpy as np | ||
| >>> from numpy_quaddtype import QuadPrecDType | ||
| >>> arr = np.array([1, 2, 3], dtype=QuadPrecDType()) | ||
| >>> arr.dtype | ||
| QuadPrecDType128 | ||
| >>> np.zeros(5, dtype=QuadPrecDType()) | ||
| array([0.0, 0.0, 0.0, 0.0, 0.0], dtype=QuadPrecDType128) | ||
|
|
||
| .. attribute:: backend | ||
| :type: QuadBackend | ||
|
|
||
| The computation backend (``SLEEF`` or ``LONGDOUBLE``). | ||
|
|
||
| .. attribute:: itemsize | ||
| :type: int | ||
|
|
||
| The size of each element in bytes (always 16). | ||
|
|
||
| .. attribute:: alignment | ||
| :type: int | ||
|
|
||
| The memory alignment in bytes (always 16). | ||
|
|
||
| .. attribute:: name | ||
| :type: str | ||
|
|
||
| The string name of the dtype (``"QuadPrecDType128"``). | ||
| ``` | ||
|
|
||
| ```{eval-rst} | ||
| .. class:: numpy_quaddtype.QuadBackend | ||
|
|
||
| Enumeration of available computation backends. | ||
|
|
||
| .. attribute:: SLEEF | ||
| :value: 0 | ||
|
|
||
| SLEEF library backend (default). Provides true IEEE 754 binary128 | ||
| quad precision with SIMD optimization. | ||
|
|
||
| .. attribute:: LONGDOUBLE | ||
| :value: 1 | ||
|
|
||
| The platform's native long double backend. The precision varies by platform. | ||
|
|
||
| **Example** | ||
|
|
||
| :: | ||
|
|
||
| >>> from numpy_quaddtype import QuadPrecDType, QuadBackend | ||
| >>> dtype = QuadPrecDType() | ||
| >>> dtype.backend == QuadBackend.SLEEF | ||
| True | ||
| ``` | ||
|
|
||
| ## Convenience Functions | ||
|
|
||
| ```{eval-rst} | ||
| .. function:: numpy_quaddtype.SleefQuadPrecision(value) | ||
|
|
||
| Create a QuadPrecision scalar using the SLEEF backend. | ||
|
|
||
| Equivalent to ``QuadPrecision(value, backend="sleef")``. | ||
|
|
||
| :param value: Value to convert to quad precision. | ||
| :return: Quad precision scalar using SLEEF backend. | ||
| :rtype: QuadPrecision | ||
| ``` | ||
|
|
||
| ```{eval-rst} | ||
| .. function:: numpy_quaddtype.LongDoubleQuadPrecision(value) | ||
|
|
||
| Create a QuadPrecision scalar using the longdouble backend. | ||
|
|
||
| Equivalent to ``QuadPrecision(value, backend="longdouble")``. | ||
|
|
||
| :param value: Value to convert to quad precision. | ||
| :return: Quad precision scalar using longdouble backend. | ||
| :rtype: QuadPrecision | ||
| ``` | ||
|
|
||
| ```{eval-rst} | ||
| .. function:: numpy_quaddtype.SleefQuadPrecDType() | ||
|
|
||
| Create a QuadPrecDType using the SLEEF backend. | ||
|
|
||
| Equivalent to ``QuadPrecDType(backend="sleef")``. | ||
|
|
||
| :return: Dtype for SLEEF-backed quad precision arrays. | ||
| :rtype: QuadPrecDType | ||
| ``` | ||
|
|
||
| ```{eval-rst} | ||
| .. function:: numpy_quaddtype.LongDoubleQuadPrecDType() | ||
|
|
||
| Create a QuadPrecDType using the longdouble backend. | ||
|
|
||
| Equivalent to ``QuadPrecDType(backend="longdouble")``. | ||
|
|
||
| :return: Dtype for longdouble-backed quad precision arrays. | ||
| :rtype: QuadPrecDType | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No multiplier is needed here, what you wrote earlier was the "Largest Subnormal Value" (We don't need to document that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this from https://sleef.org/quad.xhtml for SLEEF_QUAD_MIN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe they made error as well, IEEE does not define it like this https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format
you can confirm this from code too,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll also recommend to run this code on Mac as well :) (I'll run later as I get access to my machine)
My current machine supports
__float128so maybe because of aliasing I am getting true results as per standard.If they made mistake in their implementation then it'll get caught
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked on macos and now can confirm this is their documentation issue, you can take my suggestion commit