pygeodesy 24.5.8__py2.py3-none-any.whl → 24.5.24__py2.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.
- {PyGeodesy-24.5.8.dist-info → PyGeodesy-24.5.24.dist-info}/METADATA +2 -2
- PyGeodesy-24.5.24.dist-info/RECORD +116 -0
- pygeodesy/__init__.py +16 -12
- pygeodesy/__main__.py +9 -10
- pygeodesy/albers.py +42 -42
- pygeodesy/auxilats/__init__.py +1 -1
- pygeodesy/auxilats/__main__.py +7 -10
- pygeodesy/auxilats/auxAngle.py +32 -31
- pygeodesy/auxilats/auxLat.py +81 -51
- pygeodesy/azimuthal.py +123 -124
- pygeodesy/basics.py +165 -176
- pygeodesy/booleans.py +14 -15
- pygeodesy/cartesianBase.py +25 -23
- pygeodesy/clipy.py +3 -3
- pygeodesy/constants.py +8 -6
- pygeodesy/css.py +50 -42
- pygeodesy/datums.py +50 -48
- pygeodesy/dms.py +6 -6
- pygeodesy/ecef.py +27 -27
- pygeodesy/elevations.py +2 -2
- pygeodesy/ellipsoidalBase.py +28 -27
- pygeodesy/ellipsoidalBaseDI.py +8 -7
- pygeodesy/ellipsoidalNvector.py +11 -12
- pygeodesy/ellipsoids.py +41 -35
- pygeodesy/elliptic.py +12 -10
- pygeodesy/epsg.py +4 -3
- pygeodesy/errors.py +35 -13
- pygeodesy/etm.py +62 -53
- pygeodesy/fmath.py +48 -41
- pygeodesy/formy.py +93 -65
- pygeodesy/frechet.py +117 -102
- pygeodesy/fstats.py +52 -46
- pygeodesy/fsums.py +169 -145
- pygeodesy/gars.py +10 -9
- pygeodesy/geodesicw.py +32 -30
- pygeodesy/geodesicx/__init__.py +1 -1
- pygeodesy/geodesicx/__main__.py +4 -4
- pygeodesy/geodesicx/gx.py +40 -32
- pygeodesy/geodesicx/gxarea.py +15 -12
- pygeodesy/geodesicx/gxbases.py +3 -4
- pygeodesy/geodesicx/gxline.py +6 -8
- pygeodesy/geodsolve.py +28 -26
- pygeodesy/geohash.py +47 -44
- pygeodesy/geoids.py +37 -35
- pygeodesy/hausdorff.py +112 -99
- pygeodesy/heights.py +136 -129
- pygeodesy/internals.py +576 -0
- pygeodesy/interns.py +6 -207
- pygeodesy/iters.py +22 -19
- pygeodesy/karney.py +18 -15
- pygeodesy/ktm.py +31 -24
- pygeodesy/latlonBase.py +12 -11
- pygeodesy/lazily.py +140 -218
- pygeodesy/lcc.py +24 -25
- pygeodesy/ltp.py +83 -71
- pygeodesy/ltpTuples.py +7 -5
- pygeodesy/mgrs.py +5 -4
- pygeodesy/named.py +136 -49
- pygeodesy/namedTuples.py +33 -25
- pygeodesy/nvectorBase.py +10 -9
- pygeodesy/osgr.py +14 -12
- pygeodesy/points.py +13 -13
- pygeodesy/props.py +7 -7
- pygeodesy/rhumb/__init__.py +1 -1
- pygeodesy/rhumb/bases.py +3 -2
- pygeodesy/rhumb/solve.py +2 -2
- pygeodesy/solveBase.py +8 -7
- pygeodesy/sphericalTrigonometry.py +5 -5
- pygeodesy/streprs.py +8 -7
- pygeodesy/trf.py +8 -8
- pygeodesy/triaxials.py +67 -63
- pygeodesy/units.py +48 -50
- pygeodesy/unitsBase.py +24 -11
- pygeodesy/ups.py +7 -6
- pygeodesy/utily.py +4 -4
- pygeodesy/utm.py +53 -52
- pygeodesy/utmupsBase.py +11 -8
- pygeodesy/vector2d.py +6 -7
- pygeodesy/vector3d.py +16 -17
- pygeodesy/vector3dBase.py +5 -5
- PyGeodesy-24.5.8.dist-info/RECORD +0 -115
- {PyGeodesy-24.5.8.dist-info → PyGeodesy-24.5.24.dist-info}/WHEEL +0 -0
- {PyGeodesy-24.5.8.dist-info → PyGeodesy-24.5.24.dist-info}/top_level.txt +0 -0
pygeodesy/fsums.py
CHANGED
|
@@ -23,18 +23,22 @@ and L{Fsum.__itruediv__}.
|
|
|
23
23
|
# make sure int/int division yields float quotient, see .basics
|
|
24
24
|
from __future__ import division as _; del _ # PYCHOK semicolon
|
|
25
25
|
|
|
26
|
-
from pygeodesy.basics import isbool, iscomplex, isint, isscalar,
|
|
27
|
-
|
|
26
|
+
from pygeodesy.basics import isbool, iscomplex, isint, isscalar, \
|
|
27
|
+
_signOf, itemsorted, signOf, _xiterable, \
|
|
28
|
+
_enquote
|
|
28
29
|
from pygeodesy.constants import INT0, _isfinite, NEG0, _pos_self, \
|
|
29
30
|
_0_0, _1_0, _N_1_0, Float, Int
|
|
30
|
-
from pygeodesy.errors import _OverflowError, _TypeError,
|
|
31
|
-
_xError, _xError2, _xkwds_get
|
|
31
|
+
from pygeodesy.errors import _OverflowError, _TypeError, _UnexpectedError, \
|
|
32
|
+
_ValueError, _xError, _xError2, _xkwds_get, \
|
|
33
|
+
_xkwds_pop2
|
|
34
|
+
# from pygeodesy.internals import _enquote # from .basics
|
|
32
35
|
from pygeodesy.interns import NN, _arg_, _COMMASPACE_, _DASH_, _DOT_, \
|
|
33
|
-
|
|
34
|
-
_not_finite_, _PERCENT_, _PLUS_,
|
|
35
|
-
_SLASH_, _SPACE_, _STAR_, _UNDER_
|
|
36
|
+
_EQUAL_, _from_, _LANGLE_, _NOTEQUAL_, \
|
|
37
|
+
_not_finite_, _PERCENT_, _PLUS_, \
|
|
38
|
+
_RANGLE_, _SLASH_, _SPACE_, _STAR_, _UNDER_
|
|
36
39
|
from pygeodesy.lazily import _ALL_LAZY, _getenv, _sys_version_info2
|
|
37
|
-
from pygeodesy.named import _Named, _NamedTuple,
|
|
40
|
+
from pygeodesy.named import _name__, _name2__, _Named, _NamedTuple, \
|
|
41
|
+
_NotImplemented
|
|
38
42
|
from pygeodesy.props import _allPropertiesOf_n, deprecated_property_RO, \
|
|
39
43
|
Property_RO, property_RO
|
|
40
44
|
from pygeodesy.streprs import Fmt, fstr, unstr
|
|
@@ -43,23 +47,18 @@ from pygeodesy.streprs import Fmt, fstr, unstr
|
|
|
43
47
|
from math import ceil as _ceil, fabs, floor as _floor # PYCHOK used! .ltp
|
|
44
48
|
|
|
45
49
|
__all__ = _ALL_LAZY.fsums
|
|
46
|
-
__version__ = '24.05.
|
|
50
|
+
__version__ = '24.05.24'
|
|
47
51
|
|
|
48
|
-
_abs = abs
|
|
49
52
|
_add_op_ = _PLUS_ # in .auxilats.auxAngle
|
|
50
53
|
_eq_op_ = _EQUAL_ * 2 # _DEQUAL_
|
|
51
54
|
_div_ = 'div'
|
|
52
|
-
_Float = float # in .fstats
|
|
53
55
|
_floordiv_op_ = _SLASH_ * 2 # _DSLASH_
|
|
54
56
|
_fset_op_ = _EQUAL_
|
|
55
57
|
_ge_op_ = _RANGLE_ + _EQUAL_
|
|
56
58
|
_gt_op_ = _RANGLE_
|
|
57
59
|
_iadd_op_ = _add_op_ + _EQUAL_ # in .auxilats.auxAngle, .fstats
|
|
58
60
|
_integer_ = 'integer'
|
|
59
|
-
_isAn = isinstance # in .fstats
|
|
60
61
|
_le_op_ = _LANGLE_ + _EQUAL_
|
|
61
|
-
_len = len
|
|
62
|
-
_List = list
|
|
63
62
|
_lt_op_ = _LANGLE_
|
|
64
63
|
_mod_ = 'mod'
|
|
65
64
|
_mod_op_ = _PERCENT_
|
|
@@ -71,7 +70,6 @@ _significant_ = 'significant'
|
|
|
71
70
|
_sub_op_ = _DASH_ # in .auxilats.auxAngle
|
|
72
71
|
_threshold_ = 'threshold'
|
|
73
72
|
_truediv_op_ = _SLASH_
|
|
74
|
-
_Tuple = tuple # in .fstats
|
|
75
73
|
_divmod_op_ = _floordiv_op_ + _mod_op_
|
|
76
74
|
_isub_op_ = _sub_op_ + _fset_op_ # in .auxilats.auxAngle
|
|
77
75
|
|
|
@@ -83,7 +81,7 @@ def _2delta(*ab):
|
|
|
83
81
|
a, b = _2sum(*ab)
|
|
84
82
|
except _OverflowError:
|
|
85
83
|
a, b = ab
|
|
86
|
-
return
|
|
84
|
+
return float(a if fabs(a) > fabs(b) else b)
|
|
87
85
|
|
|
88
86
|
|
|
89
87
|
def _2error(unused): # in .fstats
|
|
@@ -95,7 +93,7 @@ def _2error(unused): # in .fstats
|
|
|
95
93
|
def _2finite(x):
|
|
96
94
|
'''(INTERNAL) return C{float(x)} if finite.
|
|
97
95
|
'''
|
|
98
|
-
x =
|
|
96
|
+
x = float(x)
|
|
99
97
|
return x if _isfinite(x) else _2error(x)
|
|
100
98
|
|
|
101
99
|
|
|
@@ -113,16 +111,16 @@ def _X_ps(X): # for _2floats only
|
|
|
113
111
|
return X._ps
|
|
114
112
|
|
|
115
113
|
|
|
116
|
-
def _2floats(xs, origin=0, _X=_X_ps, _x=
|
|
114
|
+
def _2floats(xs, origin=0, _X=_X_ps, _x=float):
|
|
117
115
|
'''(INTERNAL) Yield each B{C{xs}} as a C{float}.
|
|
118
116
|
'''
|
|
119
117
|
try:
|
|
120
|
-
i, x = origin,
|
|
118
|
+
i, x = origin, _X
|
|
121
119
|
_fin = _isfinite
|
|
122
120
|
_FsT = _Fsum_Fsum2Tuple_types
|
|
123
|
-
|
|
124
|
-
for x in xs:
|
|
125
|
-
if
|
|
121
|
+
_isa = isinstance
|
|
122
|
+
for x in _xiterable(xs):
|
|
123
|
+
if _isa(x, _FsT):
|
|
126
124
|
for p in _X(x._Fsum):
|
|
127
125
|
yield p
|
|
128
126
|
else:
|
|
@@ -130,7 +128,8 @@ def _2floats(xs, origin=0, _X=_X_ps, _x=_Float):
|
|
|
130
128
|
yield f if _fin(f) else _2error(f)
|
|
131
129
|
i += 1
|
|
132
130
|
except Exception as X:
|
|
133
|
-
raise _xError(X,
|
|
131
|
+
raise _xError(X, xs=xs) if x is _X else \
|
|
132
|
+
_xError(X, Fmt.INDEX(xs=i), x)
|
|
134
133
|
|
|
135
134
|
|
|
136
135
|
def _Fsumf_(*xs): # floats=True, in .auxLat, ...
|
|
@@ -160,13 +159,13 @@ def _2halfeven(s, r, p):
|
|
|
160
159
|
def _isFsum(x): # in .fmath
|
|
161
160
|
'''(INTERNAL) Is C{x} an C{Fsum} instance?
|
|
162
161
|
'''
|
|
163
|
-
return
|
|
162
|
+
return isinstance(x, Fsum)
|
|
164
163
|
|
|
165
164
|
|
|
166
165
|
def _isFsumTuple(x): # in .fmath
|
|
167
166
|
'''(INTERNAL) Is C{x} an C{Fsum} or C{Fsum2Tuple} instance?
|
|
168
167
|
'''
|
|
169
|
-
return
|
|
168
|
+
return isinstance(x, _Fsum_Fsum2Tuple_types)
|
|
170
169
|
|
|
171
170
|
|
|
172
171
|
def _1_Over(x, op, **raiser_RESIDUAL): # vs _1_over
|
|
@@ -188,8 +187,8 @@ def _1primed(xs): # in .fmath
|
|
|
188
187
|
def _psum(ps): # PYCHOK used!
|
|
189
188
|
'''(INTERNAL) Partials summation, updating C{ps}.
|
|
190
189
|
'''
|
|
191
|
-
# assert
|
|
192
|
-
i =
|
|
190
|
+
# assert isinstance(ps, list)
|
|
191
|
+
i = len(ps) - 1
|
|
193
192
|
s = _0_0 if i < 0 else ps[i]
|
|
194
193
|
_2s = _2sum
|
|
195
194
|
while i > 0:
|
|
@@ -212,7 +211,7 @@ def _Psum(ps, **name_RESIDUAL):
|
|
|
212
211
|
f = Fsum(**name_RESIDUAL) if name_RESIDUAL else Fsum()
|
|
213
212
|
if ps:
|
|
214
213
|
f._ps[:] = ps
|
|
215
|
-
f._n =
|
|
214
|
+
f._n = len(f._ps)
|
|
216
215
|
return f
|
|
217
216
|
|
|
218
217
|
|
|
@@ -255,7 +254,7 @@ def _strcomplex(s, *args):
|
|
|
255
254
|
'''(INTERNAL) C{Complex} 2- or 3-arg C{pow} error as C{str}.
|
|
256
255
|
'''
|
|
257
256
|
c = _strcomplex.__name__[4:]
|
|
258
|
-
n = _DASH_(
|
|
257
|
+
n = _DASH_(len(args), _arg_)
|
|
259
258
|
t = unstr(pow, *args)
|
|
260
259
|
return _SPACE_(c, s, _from_, n, t)
|
|
261
260
|
|
|
@@ -284,12 +283,17 @@ def _2sum(a, b): # by .testFmath
|
|
|
284
283
|
raise _OverflowError(u, txt=t)
|
|
285
284
|
|
|
286
285
|
|
|
287
|
-
def _threshold(threshold):
|
|
288
|
-
'''(INTERNAL) Get the L{ResidualError}s threshold
|
|
286
|
+
def _threshold(threshold=_0_0, **kwds):
|
|
287
|
+
'''(INTERNAL) Get the L{ResidualError}s threshold,
|
|
288
|
+
optionally from single kwds C{B{RESIDUAL}=scalar}.
|
|
289
289
|
'''
|
|
290
|
+
if kwds:
|
|
291
|
+
threshold, kwds = _xkwds_pop2(kwds, RESIDUAL=threshold)
|
|
292
|
+
# threshold = kwds.pop('RESIDUAL', threshold)
|
|
293
|
+
if kwds:
|
|
294
|
+
raise _UnexpectedError(**kwds)
|
|
290
295
|
try:
|
|
291
|
-
|
|
292
|
-
return t if _isfinite(t) else _2error(t) # PYCHOK None
|
|
296
|
+
return _2finite(threshold) # PYCHOK None
|
|
293
297
|
except Exception as x:
|
|
294
298
|
raise ResidualError(threshold=threshold, cause=x)
|
|
295
299
|
|
|
@@ -318,27 +322,27 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
318
322
|
_math_fsum = None
|
|
319
323
|
_n = 0
|
|
320
324
|
# _ps = [] # partial sums
|
|
321
|
-
# _ps_max = 0 # max(Fsum._ps_max,
|
|
325
|
+
# _ps_max = 0 # max(Fsum._ps_max, len(Fsum._ps))
|
|
322
326
|
_RESIDUAL = _threshold(_getenv('PYGEODESY_FSUM_RESIDUAL', _0_0))
|
|
323
327
|
|
|
324
328
|
def __init__(self, *xs, **name_RESIDUAL):
|
|
325
329
|
'''New L{Fsum} for I{running} precision floating point summation.
|
|
326
330
|
|
|
327
|
-
@arg xs: No, one or more items to add (each C{scalar} or
|
|
328
|
-
or L{Fsum2Tuple} instance), all positional.
|
|
329
|
-
@kwarg name_RESIDUAL: Optional C{B{name}=NN} for this
|
|
330
|
-
the C{B{RESIDUAL}=0.0} threshold for
|
|
331
|
+
@arg xs: No, one or more initial items to add (each C{scalar} or
|
|
332
|
+
an L{Fsum} or L{Fsum2Tuple} instance), all positional.
|
|
333
|
+
@kwarg name_RESIDUAL: Optional C{B{name}=NN} (C{str}) for this
|
|
334
|
+
L{Fsum} and the C{B{RESIDUAL}=0.0} threshold for
|
|
335
|
+
L{ResidualError}s (C{scalar}).
|
|
331
336
|
|
|
332
337
|
@see: Methods L{Fsum.fadd} and L{Fsum.RESIDUAL}.
|
|
333
338
|
'''
|
|
334
339
|
if name_RESIDUAL:
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
self.RESIDUAL(R)
|
|
340
|
+
n, kwds = _name2__(**name_RESIDUAL)
|
|
341
|
+
if kwds:
|
|
342
|
+
R = Fsum._RESIDUAL
|
|
343
|
+
t = _threshold(R, **kwds)
|
|
344
|
+
if t != R:
|
|
345
|
+
self._RESIDUAL = t
|
|
342
346
|
if n:
|
|
343
347
|
self.name = n
|
|
344
348
|
|
|
@@ -395,9 +399,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
395
399
|
in Python 2- and remainder C{mod} an L{Fsum} instance.
|
|
396
400
|
|
|
397
401
|
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar} modulus.
|
|
398
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
399
|
-
|
|
400
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
402
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
403
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
404
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
401
405
|
|
|
402
406
|
@raise ResidualError: Non-zero, significant residual or invalid
|
|
403
407
|
B{C{RESIDUAL}}.
|
|
@@ -417,7 +421,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
417
421
|
|
|
418
422
|
@see: Methods L{Fsum.fsum} and L{Fsum.int_float}.
|
|
419
423
|
'''
|
|
420
|
-
return
|
|
424
|
+
return float(self._fprs)
|
|
421
425
|
|
|
422
426
|
def __floor__(self): # PYCHOK not special in Python 2-
|
|
423
427
|
'''Return this instance' C{math.floor} as C{int} or C{float}.
|
|
@@ -462,7 +466,8 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
462
466
|
def __iadd__(self, other):
|
|
463
467
|
'''Apply C{B{self} += B{other}} to this instance.
|
|
464
468
|
|
|
465
|
-
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar}
|
|
469
|
+
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar} value or
|
|
470
|
+
an iterable of several of the former.
|
|
466
471
|
|
|
467
472
|
@return: This instance, updated (L{Fsum}).
|
|
468
473
|
|
|
@@ -471,7 +476,10 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
471
476
|
|
|
472
477
|
@see: Methods L{Fsum.fadd_} and L{Fsum.fadd}.
|
|
473
478
|
'''
|
|
474
|
-
|
|
479
|
+
try:
|
|
480
|
+
return self._fadd(other, _iadd_op_)
|
|
481
|
+
except TypeError:
|
|
482
|
+
return self._facc_inplace(other, _iadd_op_, self._facc)
|
|
475
483
|
|
|
476
484
|
def __ifloordiv__(self, other):
|
|
477
485
|
'''Apply C{B{self} //= B{other}} to this instance.
|
|
@@ -543,9 +551,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
543
551
|
@arg other: The exponent (C{scalar}, L{Fsum} or L{Fsum2Tuple}).
|
|
544
552
|
@arg mod: Optional modulus (C{int} or C{None}) for the 3-argument
|
|
545
553
|
C{pow(B{self}, B{other}, B{mod})} version.
|
|
546
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
547
|
-
|
|
548
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
554
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
555
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
556
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
549
557
|
|
|
550
558
|
@return: This instance, updated (L{Fsum}).
|
|
551
559
|
|
|
@@ -578,7 +586,8 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
578
586
|
def __isub__(self, other):
|
|
579
587
|
'''Apply C{B{self} -= B{other}} to this instance.
|
|
580
588
|
|
|
581
|
-
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar}
|
|
589
|
+
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar} value or
|
|
590
|
+
an iterable of several of the former.
|
|
582
591
|
|
|
583
592
|
@return: This instance, updated (L{Fsum}).
|
|
584
593
|
|
|
@@ -586,7 +595,10 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
586
595
|
|
|
587
596
|
@see: Methods L{Fsum.fsub_} and L{Fsum.fsub}.
|
|
588
597
|
'''
|
|
589
|
-
|
|
598
|
+
try:
|
|
599
|
+
return self._fsub(other, _isub_op_)
|
|
600
|
+
except TypeError:
|
|
601
|
+
return self._facc_inplace(other, _isub_op_, self._facc_neg)
|
|
590
602
|
|
|
591
603
|
def __iter__(self):
|
|
592
604
|
'''Return an C{iter}ator over a C{partials} duplicate.
|
|
@@ -597,9 +609,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
597
609
|
'''Apply C{B{self} /= B{other}} to this instance.
|
|
598
610
|
|
|
599
611
|
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar} divisor.
|
|
600
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
601
|
-
|
|
602
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
612
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
613
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
614
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
603
615
|
|
|
604
616
|
@return: This instance, updated (L{Fsum}).
|
|
605
617
|
|
|
@@ -734,7 +746,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
734
746
|
'''
|
|
735
747
|
f = self._copy_2(self.__round__)
|
|
736
748
|
# <https://docs.Python.org/3.12/reference/datamodel.html?#object.__round__>
|
|
737
|
-
return f._fset(round(
|
|
749
|
+
return f._fset(round(float(self), *ndigits)) # can be C{int}
|
|
738
750
|
|
|
739
751
|
def __rpow__(self, other, *mod):
|
|
740
752
|
'''Return C{B{other}**B{self}} as an L{Fsum}.
|
|
@@ -781,9 +793,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
781
793
|
'''Return C{B{self} / B{other}} as an L{Fsum}.
|
|
782
794
|
|
|
783
795
|
@arg other: An L{Fsum}, L{Fsum2Tuple} or C{scalar} divisor.
|
|
784
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
785
|
-
|
|
786
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
796
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
797
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
798
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
787
799
|
|
|
788
800
|
@return: The quotient (L{Fsum}).
|
|
789
801
|
|
|
@@ -815,7 +827,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
815
827
|
'''
|
|
816
828
|
n, r = self._fint2
|
|
817
829
|
if r:
|
|
818
|
-
i, d =
|
|
830
|
+
i, d = float(r).as_integer_ratio()
|
|
819
831
|
n *= d
|
|
820
832
|
n += i
|
|
821
833
|
else: # PYCHOK no cover
|
|
@@ -859,14 +871,17 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
859
871
|
s = self.signOf() # res=True
|
|
860
872
|
return s
|
|
861
873
|
|
|
862
|
-
def copy(self, deep=False, name
|
|
874
|
+
def copy(self, deep=False, **name):
|
|
863
875
|
'''Copy this instance, C{shallow} or B{C{deep}}.
|
|
864
876
|
|
|
877
|
+
@kwarg name: Optional, overriding C{B{name}='"copy"} (C{str}).
|
|
878
|
+
|
|
865
879
|
@return: The copy (L{Fsum}).
|
|
866
880
|
'''
|
|
867
|
-
|
|
881
|
+
n = _name__(name, name__=self.copy)
|
|
882
|
+
f = _Named.copy(self, deep=deep, name=n)
|
|
868
883
|
if f._ps is self._ps:
|
|
869
|
-
f._ps =
|
|
884
|
+
f._ps = list(self._ps) # separate list
|
|
870
885
|
if not deep:
|
|
871
886
|
f._n = 1
|
|
872
887
|
# assert f._Fsum is f
|
|
@@ -875,10 +890,10 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
875
890
|
def _copy_2(self, which, name=NN):
|
|
876
891
|
'''(INTERNAL) Copy for I{dyadic} operators.
|
|
877
892
|
'''
|
|
878
|
-
n = name or which.__name__
|
|
893
|
+
n = name or which.__name__ # _dunder_nameof
|
|
879
894
|
# NOT .classof due to .Fdot(a, *b) args, etc.
|
|
880
895
|
f = _Named.copy(self, deep=False, name=n)
|
|
881
|
-
f._ps =
|
|
896
|
+
f._ps = list(self._ps) # separate list
|
|
882
897
|
# assert f._n == self._n
|
|
883
898
|
# assert f._Fsum is f
|
|
884
899
|
return f
|
|
@@ -915,7 +930,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
915
930
|
'''(INTERNAL) Format the caught exception C{X}.
|
|
916
931
|
'''
|
|
917
932
|
E, t = _xError2(X)
|
|
918
|
-
u = unstr(self.named3, *xs[:3], _ELLIPSIS=
|
|
933
|
+
u = unstr(self.named3, *xs[:3], _ELLIPSIS=len(xs) > 3, **kwds)
|
|
919
934
|
return E(u, txt=t, cause=X)
|
|
920
935
|
|
|
921
936
|
def _facc(self, xs, up=True, **origin_X_x):
|
|
@@ -924,16 +939,24 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
924
939
|
if xs:
|
|
925
940
|
_xs = _2floats(xs, **origin_X_x) # PYCHOK yield
|
|
926
941
|
ps = self._ps
|
|
927
|
-
ps[:] = self._ps_acc(
|
|
942
|
+
ps[:] = self._ps_acc(list(ps), _xs, up=up)
|
|
928
943
|
return self
|
|
929
944
|
|
|
930
945
|
def _facc_1(self, xs, **up):
|
|
931
946
|
'''(INTERNAL) Accumulate 0, 1 or more C{scalars} or L{Fsum}s,
|
|
932
947
|
all positional C{xs} in the caller of this method.
|
|
933
948
|
'''
|
|
934
|
-
return self._fadd(xs[0], _add_op_, **up) if
|
|
949
|
+
return self._fadd(xs[0], _add_op_, **up) if len(xs) == 1 else \
|
|
935
950
|
self._facc(xs, origin=1, **up)
|
|
936
951
|
|
|
952
|
+
def _facc_inplace(self, other, op, _facc):
|
|
953
|
+
'''(INTERNAL) Accumulate from an iterable.
|
|
954
|
+
'''
|
|
955
|
+
try:
|
|
956
|
+
return _facc(other, origin=1) if _xiterable(other) else self
|
|
957
|
+
except Exception as X:
|
|
958
|
+
raise self._ErrorX(X, op, other)
|
|
959
|
+
|
|
937
960
|
def _facc_neg(self, xs, **up_origin):
|
|
938
961
|
'''(INTERNAL) Accumulate more C{scalars} or L{Fsum}s, negated.
|
|
939
962
|
'''
|
|
@@ -941,7 +964,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
941
964
|
return X._ps_neg
|
|
942
965
|
|
|
943
966
|
def _n(x):
|
|
944
|
-
return -
|
|
967
|
+
return -float(x)
|
|
945
968
|
|
|
946
969
|
return self._facc(xs, _X=_N, _x=_n, **up_origin)
|
|
947
970
|
|
|
@@ -967,16 +990,17 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
967
990
|
_Pow, p, s, r = _Pow4(power)
|
|
968
991
|
if p: # and xs:
|
|
969
992
|
op = which.__name__
|
|
993
|
+
_flt = float
|
|
970
994
|
_Fs = Fsum
|
|
971
|
-
|
|
995
|
+
_isa = isinstance
|
|
972
996
|
_pow = self._pow_2_3
|
|
973
997
|
|
|
974
998
|
def _P(X):
|
|
975
999
|
f = _Pow(X, p, power, op, **raiser_RESIDUAL)
|
|
976
|
-
return f._ps if
|
|
1000
|
+
return f._ps if _isa(f, _Fs) else (f,)
|
|
977
1001
|
|
|
978
1002
|
def _p(x):
|
|
979
|
-
x =
|
|
1003
|
+
x = _flt(x)
|
|
980
1004
|
f = _pow(x, s, power, op, **raiser_RESIDUAL)
|
|
981
1005
|
if f and r:
|
|
982
1006
|
f *= _pow(x, r, power, op, **raiser_RESIDUAL)
|
|
@@ -984,7 +1008,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
984
1008
|
|
|
985
1009
|
f = self._facc(xs, origin=1, _X=_P, _x=_p)
|
|
986
1010
|
else:
|
|
987
|
-
f = self._facc_scalar_(
|
|
1011
|
+
f = self._facc_scalar_(float(len(xs))) # x**0 == 1
|
|
988
1012
|
return f
|
|
989
1013
|
|
|
990
1014
|
def _facc_scalar(self, xs, **up):
|
|
@@ -1006,7 +1030,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1006
1030
|
# and re-accumulating the final C{partial}.
|
|
1007
1031
|
# '''
|
|
1008
1032
|
# ps = self._ps
|
|
1009
|
-
# while
|
|
1033
|
+
# while len(ps) > 1:
|
|
1010
1034
|
# p = ps.pop()
|
|
1011
1035
|
# if p:
|
|
1012
1036
|
# n = self._n
|
|
@@ -1030,10 +1054,10 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1030
1054
|
@raise ValueError: Invalid or non-finite B{C{xs}} value.
|
|
1031
1055
|
'''
|
|
1032
1056
|
if _isFsumTuple(xs):
|
|
1033
|
-
self._facc_scalar(xs._ps)
|
|
1057
|
+
self._facc_scalar(xs._ps)
|
|
1034
1058
|
elif isscalar(xs): # for backward compatibility
|
|
1035
1059
|
self._facc_scalar_(_2float(x=xs)) # PYCHOK no cover
|
|
1036
|
-
elif xs: #
|
|
1060
|
+
elif xs: # _xiterable(xs)
|
|
1037
1061
|
self._facc(xs)
|
|
1038
1062
|
return self
|
|
1039
1063
|
|
|
@@ -1051,9 +1075,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1051
1075
|
'''(INTERNAL) Apply C{B{self} += B{other}}.
|
|
1052
1076
|
'''
|
|
1053
1077
|
if not self._ps: # new Fsum(x)
|
|
1054
|
-
self._fset(other,
|
|
1078
|
+
self._fset(other, op=op, **up)
|
|
1055
1079
|
elif _isFsumTuple(other):
|
|
1056
|
-
self._facc_scalar(other._ps, **up)
|
|
1080
|
+
self._facc_scalar(other._ps, **up)
|
|
1057
1081
|
elif self._scalar(other, op):
|
|
1058
1082
|
self._facc_scalar_(other, **up)
|
|
1059
1083
|
return self
|
|
@@ -1078,7 +1102,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1078
1102
|
q -= 1
|
|
1079
1103
|
# t = self.signOf()
|
|
1080
1104
|
# if t and t != s:
|
|
1081
|
-
# raise self._Error(op, other, _AssertionError,
|
|
1105
|
+
# raise self._Error(op, other, _AssertionError, txt__=signOf)
|
|
1082
1106
|
return DivMod2Tuple(q, self) # q is C{int} in Python 3+, but C{float} in Python 2-
|
|
1083
1107
|
|
|
1084
1108
|
def _finite(self, other, op=None):
|
|
@@ -1092,10 +1116,10 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1092
1116
|
def fint(self, name=NN, **raiser_RESIDUAL):
|
|
1093
1117
|
'''Return this instance' current running sum as C{integer}.
|
|
1094
1118
|
|
|
1095
|
-
@kwarg name: Optional
|
|
1096
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
1097
|
-
|
|
1098
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1119
|
+
@kwarg name: Optional, overriding C{B{name}="fint"} (C{str}).
|
|
1120
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
1121
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
1122
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1099
1123
|
|
|
1100
1124
|
@return: The C{integer} sum (L{Fsum}) if this instance C{is_integer}
|
|
1101
1125
|
with a zero or insignificant I{integer} residual.
|
|
@@ -1111,8 +1135,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1111
1135
|
if R:
|
|
1112
1136
|
t = _stresidual(_integer_, r, **R)
|
|
1113
1137
|
raise ResidualError(_integer_, i, txt=t)
|
|
1114
|
-
|
|
1115
|
-
return f._fset(i)
|
|
1138
|
+
return _Psum_(i, name=_name__(name, name__=self.fint))
|
|
1116
1139
|
|
|
1117
1140
|
def fint2(self, **name):
|
|
1118
1141
|
'''Return this instance' current running sum as C{int} and the
|
|
@@ -1131,9 +1154,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1131
1154
|
'''(INTERNAL) Get 2-tuple (C{int}, I{integer} residual).
|
|
1132
1155
|
'''
|
|
1133
1156
|
s, r = self._fprs2
|
|
1134
|
-
i =
|
|
1135
|
-
n =
|
|
1136
|
-
r =
|
|
1157
|
+
i = int(s)
|
|
1158
|
+
n = len(self._ps)
|
|
1159
|
+
r = self._ps_1sum(i) if r and n > 1 else float(s - i)
|
|
1137
1160
|
return i, (r or INT0) # Fsum2Tuple?
|
|
1138
1161
|
|
|
1139
1162
|
@deprecated_property_RO
|
|
@@ -1172,24 +1195,24 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1172
1195
|
'''(INTERNAL) Apply C{B{self} *= B{other}}.
|
|
1173
1196
|
'''
|
|
1174
1197
|
if _isFsumTuple(other):
|
|
1175
|
-
if
|
|
1198
|
+
if len(self._ps) != 1:
|
|
1176
1199
|
f = self._mul_Fsum(other, op)
|
|
1177
|
-
elif
|
|
1200
|
+
elif len(other._ps) != 1: # and len(self._ps) == 1
|
|
1178
1201
|
f = other._mul_scalar(self._ps[0], op)
|
|
1179
|
-
else: #
|
|
1202
|
+
else: # len(other._ps) == len(self._ps) == 1
|
|
1180
1203
|
f = self._finite(self._ps[0] * other._ps[0])
|
|
1181
1204
|
else:
|
|
1182
1205
|
s = self._scalar(other, op)
|
|
1183
1206
|
f = self._mul_scalar(s, op)
|
|
1184
|
-
return self._fset(f) # n=
|
|
1207
|
+
return self._fset(f) # n=len(self) + 1
|
|
1185
1208
|
|
|
1186
1209
|
def fover(self, over, **raiser_RESIDUAL):
|
|
1187
1210
|
'''Apply C{B{self} /= B{over}} and summate.
|
|
1188
1211
|
|
|
1189
1212
|
@arg over: An L{Fsum} or C{scalar} denominator.
|
|
1190
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
1191
|
-
|
|
1192
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1213
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
1214
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
1215
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1193
1216
|
|
|
1194
1217
|
@return: Precision running sum (C{float}).
|
|
1195
1218
|
|
|
@@ -1198,7 +1221,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1198
1221
|
|
|
1199
1222
|
@see: Methods L{Fsum.fsum} and L{Fsum.__itruediv__}.
|
|
1200
1223
|
'''
|
|
1201
|
-
return
|
|
1224
|
+
return float(self.fdiv(over, **raiser_RESIDUAL)._fprs)
|
|
1202
1225
|
|
|
1203
1226
|
fpow = __ipow__
|
|
1204
1227
|
|
|
@@ -1218,7 +1241,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1218
1241
|
f = self._pow(other, other, op, **raiser_RESIDUAL)
|
|
1219
1242
|
else: # pow(self, other)
|
|
1220
1243
|
f = self._pow(other, other, op, **raiser_RESIDUAL)
|
|
1221
|
-
return self._fset(f
|
|
1244
|
+
return self._fset(f) # n=max(len(self), 1)
|
|
1222
1245
|
|
|
1223
1246
|
@Property_RO
|
|
1224
1247
|
def _fprs(self):
|
|
@@ -1236,20 +1259,20 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1236
1259
|
'''(INTERNAL) Get and cache this instance' precision
|
|
1237
1260
|
running sum and residual (L{Fsum2Tuple}).
|
|
1238
1261
|
'''
|
|
1239
|
-
ps =
|
|
1240
|
-
n =
|
|
1241
|
-
if n > 0: #
|
|
1262
|
+
ps = self._ps
|
|
1263
|
+
n = len(ps) - 2
|
|
1264
|
+
if n > 0: # len(ps) > 2
|
|
1242
1265
|
s = _psum(ps)
|
|
1243
|
-
n =
|
|
1266
|
+
n = len(ps) - 2
|
|
1244
1267
|
if n > 0:
|
|
1245
1268
|
r = self._ps_1sum(s)
|
|
1246
1269
|
return Fsum2Tuple(*_s_r(s, r))
|
|
1247
|
-
if n == 0: #
|
|
1270
|
+
if n == 0: # len(ps) == 2
|
|
1248
1271
|
s, r = _s_r(*_2sum(*ps))
|
|
1249
1272
|
ps[:] = (r, s) if r else (s,)
|
|
1250
|
-
elif ps: #
|
|
1273
|
+
elif ps: # len(ps) == 1
|
|
1251
1274
|
s, r = ps[0], INT0
|
|
1252
|
-
else: #
|
|
1275
|
+
else: # len(ps) == 0
|
|
1253
1276
|
s, r = _0_0, INT0
|
|
1254
1277
|
ps[:] = s,
|
|
1255
1278
|
# assert self._ps is ps
|
|
@@ -1270,7 +1293,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1270
1293
|
Fsum(*xs) if xs else _0_0)
|
|
1271
1294
|
return self._fset(f)
|
|
1272
1295
|
|
|
1273
|
-
def _fset(self, other,
|
|
1296
|
+
def _fset(self, other, n=0, up=True, **op):
|
|
1274
1297
|
'''(INTERNAL) Overwrite this instance with an other or a C{scalar}.
|
|
1275
1298
|
'''
|
|
1276
1299
|
if other is self:
|
|
@@ -1284,7 +1307,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1284
1307
|
Fsum._fprs ._update_from(self, other)
|
|
1285
1308
|
Fsum._fprs2._update_from(self, other)
|
|
1286
1309
|
elif isscalar(other):
|
|
1287
|
-
s = other if
|
|
1310
|
+
s = float(self._finite(other, **op)) if op else other
|
|
1288
1311
|
self._ps[:] = s,
|
|
1289
1312
|
self._n = n or 1
|
|
1290
1313
|
if up:
|
|
@@ -1294,7 +1317,8 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1294
1317
|
# Property's _fset zaps the value just set by the @setter
|
|
1295
1318
|
self.__dict__.update(_fint2=t, _fprs=s, _fprs2=Fsum2Tuple(s, INT0))
|
|
1296
1319
|
else: # PYCHOK no cover
|
|
1297
|
-
|
|
1320
|
+
op = _xkwds_get(op, op=_fset_op_)
|
|
1321
|
+
raise self._Error(op, other, _TypeError)
|
|
1298
1322
|
return self
|
|
1299
1323
|
|
|
1300
1324
|
def _fset_ps(self, other, n=0): # in .fmath
|
|
@@ -1320,7 +1344,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1320
1344
|
|
|
1321
1345
|
@see: Method L{Fsum.fadd_} for further details.
|
|
1322
1346
|
'''
|
|
1323
|
-
return self._fsub(xs[0], _sub_op_) if
|
|
1347
|
+
return self._fsub(xs[0], _sub_op_) if len(xs) == 1 else \
|
|
1324
1348
|
self._facc_neg(xs, origin=1)
|
|
1325
1349
|
|
|
1326
1350
|
def _fsub(self, other, op):
|
|
@@ -1328,7 +1352,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1328
1352
|
'''
|
|
1329
1353
|
if _isFsumTuple(other):
|
|
1330
1354
|
if other is self: # or other._fprs2 == self._fprs2:
|
|
1331
|
-
self._fset(_0_0, n=
|
|
1355
|
+
self._fset(_0_0, n=len(self) * 2)
|
|
1332
1356
|
elif other._ps:
|
|
1333
1357
|
self._facc_scalar(other._ps_neg)
|
|
1334
1358
|
elif self._scalar(other, op):
|
|
@@ -1385,13 +1409,13 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1385
1409
|
'''
|
|
1386
1410
|
return Fsum2Tuple(self._facc_1(xs)._fprs2, **name)
|
|
1387
1411
|
|
|
1388
|
-
def fsum2(self, xs=(), name
|
|
1412
|
+
def fsum2(self, xs=(), **name):
|
|
1389
1413
|
'''Add an iterable's items, summate and return the
|
|
1390
1414
|
current precision running sum I{and} the C{residual}.
|
|
1391
1415
|
|
|
1392
1416
|
@arg xs: Iterable of items to add (each item C{scalar}
|
|
1393
1417
|
or an L{Fsum} or L{Fsum2Tuple} instance).
|
|
1394
|
-
@kwarg name: Optional name (C{str}).
|
|
1418
|
+
@kwarg name: Optional C{B{name}=NN} (C{str}).
|
|
1395
1419
|
|
|
1396
1420
|
@return: L{Fsum2Tuple}C{(fsum, residual)} with C{fsum} the
|
|
1397
1421
|
current precision running sum and C{residual}, the
|
|
@@ -1419,12 +1443,12 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1419
1443
|
'''
|
|
1420
1444
|
return self._fsum2(xs, self._facc_1)
|
|
1421
1445
|
|
|
1422
|
-
def _fsum2(self, xs,
|
|
1446
|
+
def _fsum2(self, xs, _facc, **origin):
|
|
1423
1447
|
'''(INTERNAL) Helper for L{Fsum.fsum2_} and L{Fsum.fsum2f_}.
|
|
1424
1448
|
'''
|
|
1425
1449
|
p, q = self._fprs2
|
|
1426
1450
|
if xs:
|
|
1427
|
-
s, r =
|
|
1451
|
+
s, r = _facc(xs, **origin)._fprs2
|
|
1428
1452
|
return s, _2delta(s - p, r - q) # _fsum(_1primed((s, -p, r, -q))
|
|
1429
1453
|
else:
|
|
1430
1454
|
return p, _0_0
|
|
@@ -1452,7 +1476,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1452
1476
|
n = _1_0
|
|
1453
1477
|
if _isFsumTuple(other):
|
|
1454
1478
|
if other is self or self == other:
|
|
1455
|
-
return self._fset(n
|
|
1479
|
+
return self._fset(n, n=len(self))
|
|
1456
1480
|
d, r = other._fprs2
|
|
1457
1481
|
if r:
|
|
1458
1482
|
R = self._raiser(r, d, **raiser_RESIDUAL)
|
|
@@ -1466,7 +1490,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1466
1490
|
except Exception as X:
|
|
1467
1491
|
raise self._ErrorX(X, op, other)
|
|
1468
1492
|
f = self._mul_scalar(s, _mul_op_) # handles 0, INF, NAN
|
|
1469
|
-
return self._fset(f)
|
|
1493
|
+
return self._fset(f)
|
|
1470
1494
|
|
|
1471
1495
|
@property_RO
|
|
1472
1496
|
def imag(self):
|
|
@@ -1479,9 +1503,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1479
1503
|
def int_float(self, **raiser_RESIDUAL):
|
|
1480
1504
|
'''Return this instance' current running sum as C{int} or C{float}.
|
|
1481
1505
|
|
|
1482
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
1483
|
-
|
|
1484
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1506
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
1507
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
1508
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1485
1509
|
|
|
1486
1510
|
@return: This C{integer} sum if this instance C{is_integer},
|
|
1487
1511
|
otherwise return the C{float} sum if the residual is
|
|
@@ -1501,7 +1525,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1501
1525
|
if R:
|
|
1502
1526
|
t = _stresidual(_non_zero_, r, **R)
|
|
1503
1527
|
raise ResidualError(int_float=s, txt=t)
|
|
1504
|
-
s =
|
|
1528
|
+
s = float(s)
|
|
1505
1529
|
return s
|
|
1506
1530
|
|
|
1507
1531
|
def is_exact(self):
|
|
@@ -1536,9 +1560,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1536
1560
|
'''Is this instance' running sum C{scalar} without residual or with
|
|
1537
1561
|
a residual I{ratio} not exceeding the RESIDUAL threshold?
|
|
1538
1562
|
|
|
1539
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
1540
|
-
L{ResidualError}s and C{B{RESIDUAL}=scalar}
|
|
1541
|
-
the L{RESIDUAL<Fsum.RESIDUAL>}
|
|
1563
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
1564
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
1565
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1542
1566
|
|
|
1543
1567
|
@return: C{True} if this instance' non-zero residual C{ratio} exceeds
|
|
1544
1568
|
the L{RESIDUAL<Fsum.RESIDUAL>} threshold (C{bool}).
|
|
@@ -1589,7 +1613,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1589
1613
|
def partials(self):
|
|
1590
1614
|
'''Get this instance' current, partial sums (C{tuple} of C{float}s).
|
|
1591
1615
|
'''
|
|
1592
|
-
return
|
|
1616
|
+
return tuple(self._ps)
|
|
1593
1617
|
|
|
1594
1618
|
def pow(self, x, *mod, **raiser_RESIDUAL):
|
|
1595
1619
|
'''Return C{B{self}**B{x}} as L{Fsum}.
|
|
@@ -1597,9 +1621,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1597
1621
|
@arg x: The exponent (C{scalar} or L{Fsum}).
|
|
1598
1622
|
@arg mod: Optional modulus (C{int} or C{None}) for the 3-argument
|
|
1599
1623
|
C{pow(B{self}, B{other}, B{mod})} version.
|
|
1600
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
1601
|
-
|
|
1602
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1624
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
1625
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
1626
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1603
1627
|
|
|
1604
1628
|
@return: The C{pow(self, B{x})} or C{pow(self, B{x}, *B{mod})}
|
|
1605
1629
|
result (L{Fsum}).
|
|
@@ -1677,7 +1701,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1677
1701
|
'''
|
|
1678
1702
|
# assert isint(x) and x >= 0
|
|
1679
1703
|
ps = self._ps
|
|
1680
|
-
if
|
|
1704
|
+
if len(ps) > 1:
|
|
1681
1705
|
_mul_Fsum = Fsum._mul_Fsum
|
|
1682
1706
|
if x > 4:
|
|
1683
1707
|
p = self
|
|
@@ -1709,8 +1733,8 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1709
1733
|
if r:
|
|
1710
1734
|
# assert s != 0
|
|
1711
1735
|
if isint(x, both=True): # self**int
|
|
1712
|
-
x =
|
|
1713
|
-
y =
|
|
1736
|
+
x = int(x)
|
|
1737
|
+
y = abs(x)
|
|
1714
1738
|
if y > 1:
|
|
1715
1739
|
f = self._pow_int(y, other, op, **raiser_RESIDUAL)
|
|
1716
1740
|
if x > 0: # i.e. > 1
|
|
@@ -1734,7 +1758,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1734
1758
|
if R:
|
|
1735
1759
|
raise self._ResidualError(op, other, r, **R)
|
|
1736
1760
|
n, d = self.as_integer_ratio()
|
|
1737
|
-
if
|
|
1761
|
+
if abs(n) > abs(d):
|
|
1738
1762
|
n, d, x = d, n, (-x)
|
|
1739
1763
|
s = n / d
|
|
1740
1764
|
# assert isscalar(s) and isscalar(x)
|
|
@@ -1745,7 +1769,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1745
1769
|
'''
|
|
1746
1770
|
n = 0
|
|
1747
1771
|
_2s = _2sum
|
|
1748
|
-
for x in (
|
|
1772
|
+
for x in (tuple(xs) if xs is ps else xs):
|
|
1749
1773
|
# assert isscalar(x) and _isfinite(x)
|
|
1750
1774
|
if x:
|
|
1751
1775
|
i = 0
|
|
@@ -1758,7 +1782,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1758
1782
|
n += 1
|
|
1759
1783
|
if n:
|
|
1760
1784
|
self._n += n
|
|
1761
|
-
# Fsum._ps_max = max(Fsum._ps_max,
|
|
1785
|
+
# Fsum._ps_max = max(Fsum._ps_max, len(ps))
|
|
1762
1786
|
if up:
|
|
1763
1787
|
self._update()
|
|
1764
1788
|
return ps
|
|
@@ -1768,7 +1792,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1768
1792
|
each scalar C{factor} and accumulate into an C{Fsum}.
|
|
1769
1793
|
'''
|
|
1770
1794
|
def _pfs(ps, fs):
|
|
1771
|
-
if
|
|
1795
|
+
if len(ps) < len(fs):
|
|
1772
1796
|
ps, fs = fs, ps
|
|
1773
1797
|
_fin = _isfinite
|
|
1774
1798
|
for f in fs:
|
|
@@ -1806,7 +1830,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1806
1830
|
if r and raiser:
|
|
1807
1831
|
t = self._RESIDUAL
|
|
1808
1832
|
if RESIDUAL:
|
|
1809
|
-
t = _threshold(
|
|
1833
|
+
t = _threshold(t, **RESIDUAL)
|
|
1810
1834
|
if t < 0 or (s + r) != s:
|
|
1811
1835
|
q = (r / s) if s else s # == 0.
|
|
1812
1836
|
if fabs(q) > fabs(t):
|
|
@@ -1823,7 +1847,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1823
1847
|
and properties L{Fsum.ceil}, L{Fsum.floor},
|
|
1824
1848
|
L{Fsum.imag} and L{Fsum.residual}.
|
|
1825
1849
|
'''
|
|
1826
|
-
return
|
|
1850
|
+
return float(self._fprs)
|
|
1827
1851
|
|
|
1828
1852
|
@property_RO
|
|
1829
1853
|
def residual(self):
|
|
@@ -1881,9 +1905,9 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1881
1905
|
'''Return C{B{self}**(1 / B{root})} as L{Fsum}.
|
|
1882
1906
|
|
|
1883
1907
|
@arg root: The order (C{scalar} or L{Fsum}), non-zero.
|
|
1884
|
-
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False}
|
|
1885
|
-
|
|
1886
|
-
to override the L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1908
|
+
@kwarg raiser_RESIDUAL: Use C{B{raiser}=False} to ignore
|
|
1909
|
+
L{ResidualError}s (C{bool}) and C{B{RESIDUAL}=scalar}
|
|
1910
|
+
to override the current L{RESIDUAL<Fsum.RESIDUAL>}.
|
|
1887
1911
|
|
|
1888
1912
|
@return: The C{self ** (1 / B{root})} result (L{Fsum}).
|
|
1889
1913
|
|
|
@@ -1937,7 +1961,7 @@ class Fsum(_Named): # sync __methods__ with .vector3dBase.Vector3dBase
|
|
|
1937
1961
|
'''
|
|
1938
1962
|
p = self.classname
|
|
1939
1963
|
if lenc:
|
|
1940
|
-
p = Fmt.SQUARE(p,
|
|
1964
|
+
p = Fmt.SQUARE(p, len(self))
|
|
1941
1965
|
n = _enquote(self.name, white=_UNDER_)
|
|
1942
1966
|
t = self._fprs2.toStr(**prec_sep_fmt)
|
|
1943
1967
|
return NN(p, _SPACE_, n, t)
|
|
@@ -2075,7 +2099,7 @@ class Fsum2Tuple(_NamedTuple): # in .fstats
|
|
|
2075
2099
|
return self._Fsum._n
|
|
2076
2100
|
|
|
2077
2101
|
def _other_op(self, other, which):
|
|
2078
|
-
C, s = (
|
|
2102
|
+
C, s = (tuple, self) if isinstance(other, tuple) else (Fsum, self._Fsum)
|
|
2079
2103
|
return getattr(C, which.__name__)(s, other)
|
|
2080
2104
|
|
|
2081
2105
|
@property_RO
|
|
@@ -2232,7 +2256,7 @@ if __name__ == '__main__':
|
|
|
2232
2256
|
F = Fsum()
|
|
2233
2257
|
if F.is_math_fsum():
|
|
2234
2258
|
for t in frandoms(n, seeded=True):
|
|
2235
|
-
assert
|
|
2259
|
+
assert float(F.fset_(*t)) == _fsum(t)
|
|
2236
2260
|
printf(_DOT_, end=NN)
|
|
2237
2261
|
printf(NN)
|
|
2238
2262
|
|