oprattr 0.3.0__tar.gz → 0.4.0__tar.gz
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.
Potentially problematic release.
This version of oprattr might be problematic. Click here for more details.
- {oprattr-0.3.0 → oprattr-0.4.0}/CHANGELOG.md +5 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/PKG-INFO +1 -1
- {oprattr-0.3.0 → oprattr-0.4.0}/pyproject.toml +1 -1
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/__init__.py +10 -1
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/_operations.py +19 -8
- {oprattr-0.3.0 → oprattr-0.4.0}/tests/test_object.py +14 -4
- oprattr-0.3.0/src/oprattr/operators.py +0 -41
- {oprattr-0.3.0 → oprattr-0.4.0}/.gitignore +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/.python-version +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/DEVELOPERS.md +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/LICENSE +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/README.md +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/abstract.py +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/mixins.py +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/py.typed +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/typeface.py +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/src/oprattr/typeface.pyi +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/tests/print-exceptions.py +0 -0
- {oprattr-0.3.0 → oprattr-0.4.0}/uv.lock +0 -0
|
@@ -2,11 +2,11 @@ import collections.abc
|
|
|
2
2
|
import functools
|
|
3
3
|
import numbers
|
|
4
4
|
|
|
5
|
+
from numerical import operators
|
|
5
6
|
import numpy
|
|
6
7
|
|
|
7
8
|
from . import abstract
|
|
8
9
|
from . import mixins
|
|
9
|
-
from . import operators
|
|
10
10
|
from . import typeface
|
|
11
11
|
from ._operations import (
|
|
12
12
|
unary,
|
|
@@ -121,6 +121,15 @@ class Operand(abstract.Object[T], mixins.Numpy):
|
|
|
121
121
|
"""Called for numpy.array(self)."""
|
|
122
122
|
return numpy.array(self._data, *args, **kwargs)
|
|
123
123
|
|
|
124
|
+
def _apply_ufunc(self, ufunc, method, *args, **kwargs):
|
|
125
|
+
if ufunc in (numpy.equal, numpy.not_equal):
|
|
126
|
+
# NOTE: We are probably here because the left operand is a
|
|
127
|
+
# `numpy.ndarray`, which would otherwise take control and return the
|
|
128
|
+
# pure `numpy` result.
|
|
129
|
+
f = getattr(ufunc, method)
|
|
130
|
+
return equality(f, *args)
|
|
131
|
+
return super()._apply_ufunc(ufunc, method, *args, **kwargs)
|
|
132
|
+
|
|
124
133
|
|
|
125
134
|
@Operand.implementation(numpy.array_equal)
|
|
126
135
|
def array_equal(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from numerical import operators
|
|
2
|
+
|
|
2
3
|
from .abstract import Quantity
|
|
3
4
|
|
|
4
5
|
|
|
@@ -84,19 +85,29 @@ def unary(f: operators.Operator, a):
|
|
|
84
85
|
|
|
85
86
|
def equality(f: operators.Operator, a, b):
|
|
86
87
|
"""Compute the equality operation f(a, b)."""
|
|
88
|
+
x = a._data if isinstance(a, Quantity) else a
|
|
89
|
+
y = b._data if isinstance(b, Quantity) else b
|
|
90
|
+
fxy = f(x, y)
|
|
91
|
+
try:
|
|
92
|
+
iter(fxy)
|
|
93
|
+
except TypeError:
|
|
94
|
+
r = bool(fxy)
|
|
95
|
+
else:
|
|
96
|
+
r = all(fxy)
|
|
97
|
+
isne = f(1, 2)
|
|
87
98
|
if isinstance(a, Quantity) and isinstance(b, Quantity):
|
|
88
99
|
if a._meta != b._meta:
|
|
89
|
-
return
|
|
90
|
-
return
|
|
100
|
+
return isne
|
|
101
|
+
return r
|
|
91
102
|
if isinstance(a, Quantity):
|
|
92
103
|
if not a._meta:
|
|
93
|
-
return
|
|
94
|
-
return
|
|
104
|
+
return r
|
|
105
|
+
return isne
|
|
95
106
|
if isinstance(b, Quantity):
|
|
96
107
|
if not b._meta:
|
|
97
|
-
return
|
|
98
|
-
return
|
|
99
|
-
return
|
|
108
|
+
return r
|
|
109
|
+
return isne
|
|
110
|
+
return r
|
|
100
111
|
|
|
101
112
|
|
|
102
113
|
def ordering(f: operators.Operator, a, b):
|
|
@@ -196,10 +196,20 @@ def test_equality():
|
|
|
196
196
|
assert x(1) != x(-1)
|
|
197
197
|
assert x(1) == 1
|
|
198
198
|
assert x(1) != -1
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
assert x(1, name=
|
|
202
|
-
assert 1 != x(1, name=
|
|
199
|
+
sA = Symbol('A')
|
|
200
|
+
sB = Symbol('B')
|
|
201
|
+
assert x(1, name=sA) == x(1, name=sA)
|
|
202
|
+
assert x(1, name=sA) != x(1, name=sB)
|
|
203
|
+
assert x(1, name=sA) != 1
|
|
204
|
+
assert 1 != x(1, name=sA)
|
|
205
|
+
array = numpy.array([-1, +1])
|
|
206
|
+
assert x(array) == x(array)
|
|
207
|
+
assert x(array, name=sA) == x(array, name=sA)
|
|
208
|
+
assert x(array, name=sA) != x(array, name=sB)
|
|
209
|
+
assert x(array, name=sA) != array
|
|
210
|
+
assert x(array) == array
|
|
211
|
+
assert array == x(array)
|
|
212
|
+
assert array != x(array, name=sA)
|
|
203
213
|
|
|
204
214
|
|
|
205
215
|
def test_ordering():
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
A namespace for operators used by this package's `Object` class.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import collections.abc
|
|
6
|
-
import builtins
|
|
7
|
-
import operator
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Operator:
|
|
11
|
-
"""Base class for enhanced operators."""
|
|
12
|
-
def __init__(self, __f: collections.abc.Callable, operation: str):
|
|
13
|
-
self._f = __f
|
|
14
|
-
self._operation = operation
|
|
15
|
-
|
|
16
|
-
def __repr__(self):
|
|
17
|
-
"""Called for repr(self)."""
|
|
18
|
-
return self._operation
|
|
19
|
-
|
|
20
|
-
def __call__(self, *args, **kwds):
|
|
21
|
-
"""Called for self(*args, **kwds)."""
|
|
22
|
-
return self._f(*args, **kwds)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
eq = Operator(operator.eq, r'a == b')
|
|
26
|
-
ne = Operator(operator.ne, r'a != b')
|
|
27
|
-
lt = Operator(operator.lt, r'a < b')
|
|
28
|
-
le = Operator(operator.le, r'a <= b')
|
|
29
|
-
gt = Operator(operator.gt, r'a > b')
|
|
30
|
-
ge = Operator(operator.ge, r'a >= b')
|
|
31
|
-
abs = Operator(builtins.abs, r'abs(a)')
|
|
32
|
-
pos = Operator(operator.pos, r'+a')
|
|
33
|
-
neg = Operator(operator.neg, r'-a')
|
|
34
|
-
add = Operator(operator.add, r'a + b')
|
|
35
|
-
sub = Operator(operator.sub, r'a - b')
|
|
36
|
-
mul = Operator(operator.mul, r'a * b')
|
|
37
|
-
truediv = Operator(operator.truediv, r'a / b')
|
|
38
|
-
floordiv = Operator(operator.floordiv, r'a // b')
|
|
39
|
-
mod = Operator(operator.mod, r'a % b')
|
|
40
|
-
pow = Operator(builtins.pow, r'a ** b')
|
|
41
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|