Skip to content

Commit b72f6fa

Browse files
committed
Removes determinant and sympy dependency
1 parent 51bffaf commit b72f6fa

3 files changed

Lines changed: 1 addition & 41 deletions

File tree

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ lxml
55
# Calculation
66
numpy
77
scipy
8-
sympy
98

109
# Unit testing
1110
pytest

sasdata/quantities/quantity.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import h5py
77
import numpy as np
8-
import sympy as sp
98
from numpy._typing import ArrayLike
109

1110
from sasdata.quantities import units
@@ -64,18 +63,6 @@ def matinv(a: Union["Quantity[ArrayLike]", ArrayLike]):
6463
return np.linalg.inv(a)
6564

6665

67-
def determinant(a: Union["Quantity[ArrayLike]", ArrayLike]):
68-
"""Find the determinant of an array or an array based quantity."""
69-
if isinstance(a, Quantity):
70-
return DerivedQuantity(
71-
value=np.linalg.det(a.value),
72-
units=a.units, # TODO: hmmm, need to think about this
73-
history=QuantityHistory.apply_operation(Determinant, a.history),
74-
)
75-
else:
76-
return np.linalg.det(a)
77-
78-
7966
def norm_1(a: Union["Quantity[ArrayLike]", ArrayLike], axes: int | tuple[int] | None = None):
8067
"""Caculate the 1-norm of an array or an array based quantity."""
8168
if isinstance(a, Quantity):
@@ -1201,22 +1188,6 @@ def __eq__(self, other):
12011188
return False
12021189

12031190

1204-
class Determinant(UnaryOperation):
1205-
"""Array Determinant - backed by numpy's det method"""
1206-
1207-
serialisation_name = "determinant"
1208-
1209-
def evaluate(self, variables: dict[int, T]) -> T:
1210-
return np.linalg.det(self.a.evaluate(variables))
1211-
1212-
def _derivative(self, hash_value: int) -> Operation:
1213-
return Trace(sp.adjugate(self.a) * self.a._derivative(hash_value))
1214-
1215-
def _clean(self):
1216-
clean_a = self.a._clean()
1217-
return Determinant(clean_a) # Do nothing for now - can consider identity matrix and common columns
1218-
1219-
12201191
class Dot(BinaryOperation):
12211192
"""Dot product - backed by numpy's dot method"""
12221193

@@ -1280,10 +1251,6 @@ def _clean(self):
12801251
# Removes double inversions
12811252
return clean_a.a
12821253

1283-
elif isinstance(clean_a, Determinant):
1284-
# Inverse of determinant is determinant of inverse
1285-
return Determinant(MatInv(clean_a.a))
1286-
12871254
else:
12881255
return MatInv(clean_a)
12891256

@@ -1451,7 +1418,6 @@ def __eq__(self, other):
14511418
Log,
14521419
Transpose,
14531420
Trace,
1454-
Determinant,
14551421
Dot,
14561422
MatMul,
14571423
MatInv,

test/quantities/utest_operations.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
ArcTan,
1212
Constant,
1313
Cos,
14-
Determinant,
1514
Div,
1615
Dot,
1716
Exp,
@@ -52,7 +51,7 @@
5251
)
5352

5453

55-
@pytest.fixture(params=[Determinant, Inv, Exp, Ln, MatInv, Neg, Sin, ArcSin, Cos, ArcCos, Tan, ArcTan, Transpose])
54+
@pytest.fixture(params=[Inv, Exp, Ln, MatInv, Neg, Sin, ArcSin, Cos, ArcCos, Tan, ArcTan, Transpose])
5655
def unary_operation(request):
5756
return request.param(x)
5857

@@ -205,8 +204,6 @@ def test_evaluation(op, result):
205204
(ArcCos, -1.0, math.pi),
206205
(ArcTan, 0.0, 0.0),
207206
(ArcTan, -1.0, -0.25 * math.pi),
208-
(Determinant, np.array([[1, 2], [3, 4]]), pytest.approx(-2.0)),
209-
(Determinant, np.array([[1, 4, 1], [2, 4, 2], [3, 4, 3]]), pytest.approx(0.0)),
210207
(Trace, np.array([[1, 2], [3, 4]]), pytest.approx(5.0)),
211208
(Trace, np.array([[1, 4, 1], [2, 4, 2], [3, 4, 3]]), pytest.approx(8.0)),
212209
],
@@ -264,8 +261,6 @@ def test_matmul_evaluation(op, a, b, result):
264261
)
265262
def test_axis_none_evaluation(op, a, result):
266263
f = op(Constant(a))
267-
print(f.evaluate({}))
268-
print(result)
269264
assert (f.evaluate({}) == result).all()
270265

271266

0 commit comments

Comments
 (0)