rms-polymath 0.0.1__py3-none-any.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.
- polymath/__init__.py +24 -0
- polymath/_version.py +16 -0
- polymath/boolean.py +224 -0
- polymath/extensions/__init__.py +103 -0
- polymath/extensions/indexer.py +595 -0
- polymath/extensions/item_ops.py +419 -0
- polymath/extensions/iterator.py +80 -0
- polymath/extensions/mask_ops.py +472 -0
- polymath/extensions/math_ops.py +646 -0
- polymath/extensions/pickler.py +1064 -0
- polymath/extensions/shaper.py +401 -0
- polymath/extensions/shrinker.py +190 -0
- polymath/extensions/tvl.py +335 -0
- polymath/matrix.py +589 -0
- polymath/matrix3.py +715 -0
- polymath/pair.py +245 -0
- polymath/polynomial.py +483 -0
- polymath/quaternion.py +836 -0
- polymath/qube.py +4873 -0
- polymath/scalar.py +1648 -0
- polymath/units.py +898 -0
- polymath/vector.py +1012 -0
- polymath/vector3.py +308 -0
- rms_polymath-0.0.1.dist-info/LICENSE +201 -0
- rms_polymath-0.0.1.dist-info/METADATA +42 -0
- rms_polymath-0.0.1.dist-info/RECORD +28 -0
- rms_polymath-0.0.1.dist-info/WHEEL +5 -0
- rms_polymath-0.0.1.dist-info/top_level.txt +1 -0
polymath/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# polymath/__init__.py
|
|
3
|
+
################################################################################
|
|
4
|
+
|
|
5
|
+
from polymath.boolean import Boolean
|
|
6
|
+
from polymath.matrix import Matrix
|
|
7
|
+
from polymath.matrix3 import Matrix3
|
|
8
|
+
from polymath.pair import Pair
|
|
9
|
+
from polymath.polynomial import Polynomial
|
|
10
|
+
from polymath.quaternion import Quaternion
|
|
11
|
+
from polymath.qube import Qube
|
|
12
|
+
from polymath.scalar import Scalar
|
|
13
|
+
from polymath.units import Units
|
|
14
|
+
from polymath.vector import Vector
|
|
15
|
+
from polymath.vector3 import Vector3
|
|
16
|
+
|
|
17
|
+
import polymath.extensions
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
from _version import __version__
|
|
21
|
+
except ImportError as err:
|
|
22
|
+
__version__ = 'Version unspecified'
|
|
23
|
+
|
|
24
|
+
################################################################################
|
polymath/_version.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# file generated by setuptools_scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
TYPE_CHECKING = False
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from typing import Tuple, Union
|
|
6
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
7
|
+
else:
|
|
8
|
+
VERSION_TUPLE = object
|
|
9
|
+
|
|
10
|
+
version: str
|
|
11
|
+
__version__: str
|
|
12
|
+
__version_tuple__: VERSION_TUPLE
|
|
13
|
+
version_tuple: VERSION_TUPLE
|
|
14
|
+
|
|
15
|
+
__version__ = version = '0.0.1'
|
|
16
|
+
__version_tuple__ = version_tuple = (0, 0, 1)
|
polymath/boolean.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# polymath/boolean.py: Boolean subclass of PolyMath base class
|
|
3
|
+
################################################################################
|
|
4
|
+
|
|
5
|
+
from __future__ import division
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from polymath.qube import Qube
|
|
9
|
+
from polymath.scalar import Scalar
|
|
10
|
+
|
|
11
|
+
class Boolean(Scalar):
|
|
12
|
+
"""A PolyMath subclass involving booleans. Masked values are unknown,
|
|
13
|
+
neither True nor False.
|
|
14
|
+
|
|
15
|
+
Units and derivatives are disallowed.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
NRANK = 0 # the number of numerator axes.
|
|
19
|
+
NUMER = () # shape of the numerator.
|
|
20
|
+
|
|
21
|
+
FLOATS_OK = False # True to allow floating-point numbers.
|
|
22
|
+
INTS_OK = False # True to allow integers.
|
|
23
|
+
BOOLS_OK = True # True to allow booleans.
|
|
24
|
+
|
|
25
|
+
UNITS_OK = False # True to allow units; False to disallow them.
|
|
26
|
+
DERIVS_OK = False # True to allow derivatives and to allow this class to
|
|
27
|
+
# have a denominator; False to disallow them.
|
|
28
|
+
|
|
29
|
+
DEFAULT_VALUE = False
|
|
30
|
+
|
|
31
|
+
#===========================================================================
|
|
32
|
+
@staticmethod
|
|
33
|
+
def as_boolean(arg, recursive=True):
|
|
34
|
+
"""The argument converted to Boolean if possible."""
|
|
35
|
+
|
|
36
|
+
if isinstance(arg, Boolean):
|
|
37
|
+
return arg
|
|
38
|
+
|
|
39
|
+
if isinstance(arg, np.bool_): # np.bool_ is not a subclass of bool
|
|
40
|
+
arg = bool(arg)
|
|
41
|
+
|
|
42
|
+
return Boolean(arg, units=False, derivs={})
|
|
43
|
+
|
|
44
|
+
#===========================================================================
|
|
45
|
+
def as_int(self):
|
|
46
|
+
"""A Scalar equal to one where True, zero where False.
|
|
47
|
+
|
|
48
|
+
This method overrides the default behavior defined in the base class to
|
|
49
|
+
return a Scalar of ints instead of a Boolean. True become one; False
|
|
50
|
+
becomes zero.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
if np.isscalar(self._values_):
|
|
54
|
+
result = Scalar(int(self._values_))
|
|
55
|
+
else:
|
|
56
|
+
result = Scalar(self._values_.astype('int'))
|
|
57
|
+
|
|
58
|
+
return result
|
|
59
|
+
|
|
60
|
+
#===========================================================================
|
|
61
|
+
def as_float(self):
|
|
62
|
+
"""A floating-point numeric version of this object.
|
|
63
|
+
|
|
64
|
+
This method overrides the default behavior defined in the base class to
|
|
65
|
+
return a Scalar of floats instead of a Boolean. True become one; False
|
|
66
|
+
becomes zero.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
if np.isscalar(self._values_):
|
|
70
|
+
result = Scalar(float(self._values_))
|
|
71
|
+
else:
|
|
72
|
+
result = Scalar(self._values_.astype('float'))
|
|
73
|
+
|
|
74
|
+
return result
|
|
75
|
+
|
|
76
|
+
#===========================================================================
|
|
77
|
+
def as_numeric(self):
|
|
78
|
+
"""A numeric version of this object.
|
|
79
|
+
|
|
80
|
+
This method overrides the default behavior defined in the base class to
|
|
81
|
+
return a Scalar of ints instead of a Boolean.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
return self.as_int()
|
|
85
|
+
|
|
86
|
+
#===========================================================================
|
|
87
|
+
def as_index(self):
|
|
88
|
+
"""An object suitable for indexing a NumPy ndarray."""
|
|
89
|
+
|
|
90
|
+
return (self._values_ & self.antimask)
|
|
91
|
+
|
|
92
|
+
#===========================================================================
|
|
93
|
+
def is_numeric(self):
|
|
94
|
+
"""True if this object is numeric; False otherwise.
|
|
95
|
+
|
|
96
|
+
This method overrides the default behavior in the base class to return
|
|
97
|
+
return False. Every other subclass is numeric.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
#===========================================================================
|
|
103
|
+
def sum(self, axis=None, value=True, builtins=None,
|
|
104
|
+
recursive=True, out=None):
|
|
105
|
+
"""The sum of the unmasked values along the specified axis.
|
|
106
|
+
|
|
107
|
+
Input:
|
|
108
|
+
axis an integer axis or a tuple of axes. The sum is
|
|
109
|
+
determined across these axes, leaving any remaining axes
|
|
110
|
+
in the returned value. If None (the default), then the
|
|
111
|
+
sum is performed across all axes if the object.
|
|
112
|
+
value value to match.
|
|
113
|
+
builtins if True and the result is a single unmasked scalar, the
|
|
114
|
+
result is returned as a Python int or float instead of
|
|
115
|
+
as an instance of Qube. Default is that specified by
|
|
116
|
+
Qube.PREFER_BUILTIN_TYPES.
|
|
117
|
+
recursive Ignored for class Boolean.
|
|
118
|
+
out Ignored. Enables "np.sum(Qube)" to work.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
if value:
|
|
122
|
+
return self.as_int().sum(axis=axis, builtins=builtins)
|
|
123
|
+
else:
|
|
124
|
+
return (Scalar.ONE - self.as_int()).sum(axis=axis,
|
|
125
|
+
builtins=builtins)
|
|
126
|
+
|
|
127
|
+
#===========================================================================
|
|
128
|
+
def identity(self):
|
|
129
|
+
"""An object of this subclass equivalent to the identity."""
|
|
130
|
+
|
|
131
|
+
return Boolean(True).as_readonly()
|
|
132
|
+
|
|
133
|
+
############################################################################
|
|
134
|
+
# Arithmetic operators
|
|
135
|
+
############################################################################
|
|
136
|
+
|
|
137
|
+
def __pos__(self, recursive=True):
|
|
138
|
+
return self.as_int()
|
|
139
|
+
|
|
140
|
+
def __neg__(self, recursive=True):
|
|
141
|
+
return -self.as_int()
|
|
142
|
+
|
|
143
|
+
def __abs__(self, recursive=True):
|
|
144
|
+
return self.as_int()
|
|
145
|
+
|
|
146
|
+
def __add__(self, arg, recursive=True):
|
|
147
|
+
return self.as_int() + arg
|
|
148
|
+
|
|
149
|
+
def __radd__(self, arg, recursive=True):
|
|
150
|
+
return self.as_int() + arg
|
|
151
|
+
|
|
152
|
+
def __iadd__(self, arg):
|
|
153
|
+
Qube._raise_unsupported_op('+=', self)
|
|
154
|
+
|
|
155
|
+
def __sub__(self, arg, recursive=True):
|
|
156
|
+
return self.as_int() - arg
|
|
157
|
+
|
|
158
|
+
def __rsub__(self, arg, recursive=True):
|
|
159
|
+
return -self.as_int() + arg
|
|
160
|
+
|
|
161
|
+
def __isub__(self, arg):
|
|
162
|
+
Qube._raise_unsupported_op('-=', self)
|
|
163
|
+
|
|
164
|
+
def __mul__(self, arg, recursive=True):
|
|
165
|
+
return self.as_int() * arg
|
|
166
|
+
|
|
167
|
+
def __rmul__(self, arg, recursive=True):
|
|
168
|
+
return self.as_int() * arg
|
|
169
|
+
|
|
170
|
+
def __imul__(self, arg):
|
|
171
|
+
Qube._raise_unsupported_op('*=', self)
|
|
172
|
+
|
|
173
|
+
def __truediv__(self, arg, recursive=True):
|
|
174
|
+
return self.as_int() / arg
|
|
175
|
+
|
|
176
|
+
def __rtruediv__(self, arg, recursive=True):
|
|
177
|
+
if not isinstance(arg, Qube):
|
|
178
|
+
arg = Scalar(arg)
|
|
179
|
+
return arg / self.as_int()
|
|
180
|
+
|
|
181
|
+
def __itruediv__(self, arg):
|
|
182
|
+
Qube._raise_unsupported_op('/=', self)
|
|
183
|
+
|
|
184
|
+
def __floordiv__(self, arg):
|
|
185
|
+
return self.as_int() // arg
|
|
186
|
+
|
|
187
|
+
def __rfloordiv__(self, arg):
|
|
188
|
+
if not isinstance(arg, Qube):
|
|
189
|
+
arg = Scalar(arg)
|
|
190
|
+
return arg // self.as_int()
|
|
191
|
+
|
|
192
|
+
def __ifloordiv__(self, arg):
|
|
193
|
+
Qube._raise_unsupported_op('//=', self)
|
|
194
|
+
|
|
195
|
+
def __mod__(self, arg):
|
|
196
|
+
return self.as_int() % arg
|
|
197
|
+
|
|
198
|
+
def __rmod__(self, arg):
|
|
199
|
+
if not isinstance(arg, Qube):
|
|
200
|
+
arg = Scalar(arg)
|
|
201
|
+
return arg % self.as_int()
|
|
202
|
+
|
|
203
|
+
def __imod__(self, arg):
|
|
204
|
+
Qube._raise_unsupported_op('%=', self)
|
|
205
|
+
|
|
206
|
+
def __pow__(self, arg):
|
|
207
|
+
return self.as_int()**arg
|
|
208
|
+
|
|
209
|
+
################################################################################
|
|
210
|
+
# Useful class constants
|
|
211
|
+
################################################################################
|
|
212
|
+
|
|
213
|
+
Boolean.TRUE = Boolean(True).as_readonly()
|
|
214
|
+
Boolean.FALSE = Boolean(False).as_readonly()
|
|
215
|
+
Boolean.MASKED = Boolean(False,True).as_readonly()
|
|
216
|
+
|
|
217
|
+
################################################################################
|
|
218
|
+
# Once the load is complete, we can fill in a reference to the Boolean class
|
|
219
|
+
# inside the Qube object.
|
|
220
|
+
################################################################################
|
|
221
|
+
|
|
222
|
+
Qube.BOOLEAN_CLASS = Boolean
|
|
223
|
+
|
|
224
|
+
################################################################################
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# polymath/extensions/__init__.py
|
|
3
|
+
################################################################################
|
|
4
|
+
|
|
5
|
+
from polymath.qube import Qube
|
|
6
|
+
|
|
7
|
+
from polymath.extensions import indexer
|
|
8
|
+
Qube.__getitem__ = indexer.__getitem__
|
|
9
|
+
Qube.__setitem__ = indexer.__setitem__
|
|
10
|
+
Qube._prep_index = indexer._prep_index
|
|
11
|
+
Qube._prep_scalar_index = indexer._prep_scalar_index
|
|
12
|
+
|
|
13
|
+
from polymath.extensions import item_ops
|
|
14
|
+
Qube.extract_numer = item_ops.extract_numer
|
|
15
|
+
Qube.extract_denom = item_ops.extract_denom
|
|
16
|
+
Qube.extract_denoms = item_ops.extract_denoms
|
|
17
|
+
Qube.slice_numer = item_ops.slice_numer
|
|
18
|
+
Qube.transpose_numer = item_ops.transpose_numer
|
|
19
|
+
Qube.reshape_numer = item_ops.reshape_numer
|
|
20
|
+
Qube.flatten_numer = item_ops.flatten_numer
|
|
21
|
+
Qube.transpose_denom = item_ops.transpose_denom
|
|
22
|
+
Qube.reshape_denom = item_ops.reshape_denom
|
|
23
|
+
Qube.flatten_denom = item_ops.flatten_denom
|
|
24
|
+
Qube.join_items = item_ops.join_items
|
|
25
|
+
Qube.split_items = item_ops.split_items
|
|
26
|
+
Qube.swap_items = item_ops.swap_items
|
|
27
|
+
Qube.chain = item_ops.chain
|
|
28
|
+
|
|
29
|
+
from polymath.extensions import iterator
|
|
30
|
+
Qube.__iter__ = iterator.__iter__
|
|
31
|
+
Qube.ndenumerate = iterator.ndenumerate
|
|
32
|
+
|
|
33
|
+
from polymath.extensions import mask_ops
|
|
34
|
+
Qube.mask_where = mask_ops.mask_where
|
|
35
|
+
Qube.mask_where_eq = mask_ops.mask_where_eq
|
|
36
|
+
Qube.mask_where_ne = mask_ops.mask_where_ne
|
|
37
|
+
Qube.mask_where_le = mask_ops.mask_where_le
|
|
38
|
+
Qube.mask_where_ge = mask_ops.mask_where_ge
|
|
39
|
+
Qube.mask_where_lt = mask_ops.mask_where_lt
|
|
40
|
+
Qube.mask_where_gt = mask_ops.mask_where_gt
|
|
41
|
+
Qube.mask_where_between = mask_ops.mask_where_between
|
|
42
|
+
Qube.mask_where_outside = mask_ops.mask_where_outside
|
|
43
|
+
Qube.clip = mask_ops.clip
|
|
44
|
+
Qube.is_below = mask_ops.is_below
|
|
45
|
+
Qube.is_above = mask_ops.is_above
|
|
46
|
+
Qube.is_outside = mask_ops.is_outside
|
|
47
|
+
Qube.is_inside = mask_ops.is_inside
|
|
48
|
+
|
|
49
|
+
from polymath.extensions import math_ops
|
|
50
|
+
Qube._mean_or_sum = math_ops._mean_or_sum
|
|
51
|
+
Qube._check_axis = math_ops._check_axis
|
|
52
|
+
Qube._zero_sized_result = math_ops._zero_sized_result
|
|
53
|
+
Qube.dot = math_ops.dot
|
|
54
|
+
Qube.norm = math_ops.norm
|
|
55
|
+
Qube.norm_sq = math_ops.norm_sq
|
|
56
|
+
Qube.cross = math_ops.cross
|
|
57
|
+
Qube.outer = math_ops.outer
|
|
58
|
+
Qube.as_diagonal = math_ops.as_diagonal
|
|
59
|
+
Qube.rms = math_ops.rms
|
|
60
|
+
|
|
61
|
+
from polymath.extensions import pickler
|
|
62
|
+
Qube.pickle = pickler # help(Qube.pickle) shows the docstring
|
|
63
|
+
Qube.__getstate__ = pickler.__getstate__
|
|
64
|
+
Qube.__setstate__ = pickler.__setstate__
|
|
65
|
+
Qube._encode_floats = pickler._encode_floats
|
|
66
|
+
Qube._decode_floats = pickler._decode_floats
|
|
67
|
+
Qube._encode_ints = pickler._encode_ints
|
|
68
|
+
Qube._decode_ints = pickler._decode_ints
|
|
69
|
+
Qube._encode_bools = pickler._encode_bools
|
|
70
|
+
Qube._decode_bools = pickler._decode_bools
|
|
71
|
+
Qube.pickle_digits = pickler.pickle_digits
|
|
72
|
+
Qube.pickle_reference = pickler.pickle_reference
|
|
73
|
+
Qube.set_pickle_digits = pickler.set_pickle_digits
|
|
74
|
+
Qube.set_default_pickle_digits = pickler.set_default_pickle_digits
|
|
75
|
+
Qube._check_pickle_digits = pickler._check_pickle_digits
|
|
76
|
+
Qube._pickle_debug = pickler._pickle_debug
|
|
77
|
+
|
|
78
|
+
from polymath.extensions import shaper
|
|
79
|
+
Qube.reshape = shaper.reshape
|
|
80
|
+
Qube.flatten = shaper.flatten
|
|
81
|
+
Qube.swap_axes = shaper.swap_axes
|
|
82
|
+
Qube.roll_axis = shaper.roll_axis
|
|
83
|
+
Qube.move_axis = shaper.move_axis
|
|
84
|
+
Qube.stack = shaper.stack
|
|
85
|
+
|
|
86
|
+
from polymath.extensions import shrinker
|
|
87
|
+
Qube.shrink = shrinker.shrink
|
|
88
|
+
Qube.unshrink = shrinker.unshrink
|
|
89
|
+
|
|
90
|
+
from polymath.extensions import tvl
|
|
91
|
+
Qube.tvl_and = tvl.tvl_and
|
|
92
|
+
Qube.tvl_or = tvl.tvl_or
|
|
93
|
+
Qube.tvl_any = tvl.tvl_any
|
|
94
|
+
Qube.tvl_all = tvl.tvl_all
|
|
95
|
+
Qube.tvl_eq = tvl.tvl_eq
|
|
96
|
+
Qube.tvl_ne = tvl.tvl_ne
|
|
97
|
+
Qube.tvl_lt = tvl.tvl_lt
|
|
98
|
+
Qube.tvl_gt = tvl.tvl_gt
|
|
99
|
+
Qube.tvl_le = tvl.tvl_le
|
|
100
|
+
Qube.tvl_ge = tvl.tvl_ge
|
|
101
|
+
Qube._tvl_op = tvl._tvl_op
|
|
102
|
+
|
|
103
|
+
################################################################################
|