summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-02-03 00:37:19 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2021-02-05 17:55:25 +0100
commita1640ad416c427d397695f51011000a1d7583f22 (patch)
treeba8145416c5ae1e7acef1cb205a9b20bf1be72ab /numpy
parent8f0aaf522293f8a72c96bc38773c4cd9f0d552c8 (diff)
downloadnumpy-a1640ad416c427d397695f51011000a1d7583f22.tar.gz
ENH: Add support for all potential extended-precision `np.number`s
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi18
-rw-r--r--numpy/typing/_extended_precision.py42
2 files changed, 56 insertions, 4 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index b29ba38da..0312dfad0 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -127,6 +127,20 @@ from numpy.typing._callable import (
_NumberOp,
_ComparisonOp,
)
+from numpy.typing._extended_precision import (
+ uint128 as uint128,
+ uint256 as uint256,
+ int128 as int128,
+ int256 as int256,
+ float80 as float80,
+ float96 as float96,
+ float128 as float128,
+ float256 as float256,
+ complex160 as complex160,
+ complex192 as complex192,
+ complex256 as complex256,
+ complex512 as complex512,
+)
from typing import (
Any,
@@ -2195,7 +2209,6 @@ class floating(inexact[_NBit1]):
float16 = floating[_16Bit]
float32 = floating[_32Bit]
float64 = floating[_64Bit]
-float128 = floating[_128Bit]
half = floating[_NBitHalf]
single = floating[_NBitSingle]
@@ -2230,7 +2243,6 @@ class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):
complex64 = complexfloating[_32Bit, _32Bit]
complex128 = complexfloating[_64Bit, _64Bit]
-complex256 = complexfloating[_128Bit, _128Bit]
csingle = complexfloating[_NBitSingle, _NBitSingle]
singlecomplex = complexfloating[_NBitSingle, _NBitSingle]
@@ -2284,8 +2296,6 @@ class str_(character, str):
unicode_ = str_
str0 = str_
-# TODO: Platform dependent types: float128, complex256, float96
-
def array(
object: object,
dtype: DTypeLike = ...,
diff --git a/numpy/typing/_extended_precision.py b/numpy/typing/_extended_precision.py
new file mode 100644
index 000000000..3f1ce2038
--- /dev/null
+++ b/numpy/typing/_extended_precision.py
@@ -0,0 +1,42 @@
+"""A module with platform-specific extended precision `numpy.number` subclasses.
+
+The subclasses are defined here (instead of ``__init__.pyi``) such
+that they can be imported conditionally via the numpy's mypy plugin.
+"""
+
+from typing import TYPE_CHECKING
+
+import numpy as np
+from . import (
+ _80Bit,
+ _96Bit,
+ _128Bit,
+ _256Bit,
+)
+
+if TYPE_CHECKING:
+ uint128 = np.unsignedinteger[_128Bit]
+ uint256 = np.unsignedinteger[_256Bit]
+ int128 = np.signedinteger[_128Bit]
+ int256 = np.signedinteger[_256Bit]
+ float80 = np.floating[_80Bit]
+ float96 = np.floating[_96Bit]
+ float128 = np.floating[_128Bit]
+ float256 = np.floating[_256Bit]
+ complex160 = np.complexfloating[_80Bit, _80Bit]
+ complex192 = np.complexfloating[_96Bit, _96Bit]
+ complex256 = np.complexfloating[_128Bit, _128Bit]
+ complex512 = np.complexfloating[_256Bit, _256Bit]
+else:
+ uint128 = NotImplemented
+ uint256 = NotImplemented
+ int128 = NotImplemented
+ int256 = NotImplemented
+ float80 = NotImplemented
+ float96 = NotImplemented
+ float128 = NotImplemented
+ float256 = NotImplemented
+ complex160 = NotImplemented
+ complex192 = NotImplemented
+ complex256 = NotImplemented
+ complex512 = NotImplemented