Skip to content

Commit 0b8c38a

Browse files
eric-wieserutensil
authored andcommitted
Deprecate Pdiffs, sPds, and Pdop_identity (#194)
These attributes all have shorter spellings, and now that `__eq__` and `__ne__` work, there's little need to cache them.
1 parent 31a16a0 commit 0b8c38a

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

galgebra/ga.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Geometric Algebra (inherits Metric)
33
"""
4-
4+
import warnings
55
import operator
66
import copy
77
from collections import OrderedDict
@@ -268,20 +268,6 @@ class Ga(metric.Metric):
268268
Derivatives of basis functions. Two dimensional list. First entry is differentiating coordinate index.
269269
Second entry is basis vector index. Quantities are linear combinations of basis vector symbols.
270270
271-
.. attribute:: Pdop_identity
272-
273-
Partial differential operator identity (operates on multivector function to return function).
274-
275-
.. attribute:: Pdiffs
276-
277-
Dictionary of partial differential operators (operates on multivector functions) for each coordinate
278-
:math:`\{x: \partial_{x}, ...\}`
279-
280-
.. attribute:: sPds
281-
282-
Dictionary of scalar partial differential operators (operates on scalar functions) for each coordinate
283-
:math:`\{x: \partial_{x}, ...\}`
284-
285271
.. attribute:: grad
286272
287273
Geometric derivative operator from left. ``grad*F`` returns multivector
@@ -420,12 +406,6 @@ def __init__(self, bases, **kwargs):
420406
if self.coords is not None:
421407
self.coord_vec = sum([coord * base for (coord, base) in zip(self.coords, self.basis)])
422408
self._build_reciprocal_basis(self.gsym)
423-
self.Pdop_identity = mv.Pdop({},ga=self) # Identity Pdop = 1
424-
self.Pdiffs = {}
425-
self.sPds = {}
426-
for x in self.coords: # Partial derivative operator for each coordinate
427-
self.Pdiffs[x] = mv.Pdop({x:1}, ga=self)
428-
self.sPds[x] = mv.Sdop([(S(1), self.Pdiffs[x])], ga=self)
429409
self._build_grads()
430410
else:
431411
self.r_basis_mv = None
@@ -516,6 +496,30 @@ def mv_x(self):
516496
def X(self):
517497
return self.mv(sum([coord*base for (coord, base) in zip(self.coords, self.basis)]))
518498

499+
@property
500+
def Pdiffs(self):
501+
# galgebra 0.4.5
502+
warnings.warn(
503+
"ga.Pdiffs[x] is deprecated, use `ga.pdop(x)` instead",
504+
DeprecationWarning, stacklevel=2)
505+
return {x: self.pdop(x) for x in self.coords}
506+
507+
@property
508+
def sPds(self):
509+
# galgebra 0.4.5
510+
warnings.warn(
511+
"ga.sPds[x] is deprecated, use `ga.sdop(x)` instead",
512+
DeprecationWarning, stacklevel=2)
513+
return {x: self.sdop(x) for x in self.coords}
514+
515+
@property
516+
def Pdop_identity(self):
517+
# galgebra 0.4.5
518+
warnings.warn(
519+
"ga.Pdop_identity is deprecated, use `ga.pdop({})` instead",
520+
DeprecationWarning, stacklevel=2)
521+
return self.pdop({})
522+
519523
def mv(self, root=None, *args, **kwargs):
520524
"""
521525
Instanciate and return a multivector for this, 'self',
@@ -600,7 +604,7 @@ def _build_grads(self):
600604
if self.norm:
601605
r_basis = [x / e_norm for (x, e_norm) in zip(self.r_basis_mv, self.e_norm)]
602606

603-
pdx = [self.Pdiffs[x] for x in self.coords]
607+
pdx = [self.pdop(x) for x in self.coords]
604608

605609
self.grad = mv.Dop(r_basis, pdx, ga=self)
606610
self.rgrad = mv.Dop(r_basis, pdx, ga=self, cmpflg=True)

galgebra/mv.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,11 +1617,11 @@ def Add(sdop1, sdop2):
16171617
if isinstance(sdop1, Sdop):
16181618
if not isinstance(sdop2, Mv):
16191619
sdop2 = sdop1.Ga.mv(sdop2)
1620-
sdop2 = Sdop([(sdop2, sdop1.Ga.Pdop_identity)], ga=sdop1.Ga)
1620+
sdop2 = Sdop([(sdop2, Pdop({}, ga=sdop1.Ga))], ga=sdop1.Ga)
16211621
elif isinstance(sdop2, Sdop):
16221622
if not isinstance(sdop1, Mv):
16231623
sdop1 = sdop2.Ga.mv(sdop1)
1624-
sdop1 = Sdop([(sdop1, sdop2.Ga.Pdop_identity)], ga=sdop2.Ga)
1624+
sdop1 = Sdop([(sdop1, Pdop({}, ga=sdop2.Ga))], ga=sdop2.Ga)
16251625
else:
16261626
raise TypeError("Neither argument is a Dop instance")
16271627
return Sdop.Add(sdop1, sdop2)
@@ -1677,10 +1677,12 @@ class Pdop(object):
16771677
Attributes
16781678
----------
16791679
pdiffs : dict
1680-
a dictionary where coordinates are keys and key value are the number of
1680+
A dictionary where coordinates are keys and key value are the number of
16811681
times one differentiates with respect to the key.
16821682
order : int
1683-
total number of differentiations
1683+
Total number of differentiations.
1684+
When this is zero (i.e. when :attr:`pdiffs` is ``{}``) then this object
1685+
is the identity operator, and returns its operand unchanged.
16841686
"""
16851687

16861688
init_slots = {'ga': (None, 'Associated geometric algebra')}
@@ -1774,7 +1776,7 @@ def factor(self):
17741776
del new_pdiffs[x]
17751777
else:
17761778
new_pdiffs[x] -= 1
1777-
return Pdop(new_pdiffs, ga=self.Ga), self.Ga.Pdiffs[x]
1779+
return Pdop(new_pdiffs, ga=self.Ga), Pdop(x, ga=self.Ga)
17781780

17791781
def __call__(self, arg):
17801782
"""
@@ -2019,11 +2021,11 @@ def Add(dop1, dop2):
20192021
if isinstance(dop1, Dop):
20202022
if not isinstance(dop2, Mv):
20212023
dop2 = dop1.Ga.mv(dop2)
2022-
dop2 = Dop([(dop2, dop1.Ga.Pdop_identity)], cmpflg=dop1.cmpflg, ga=dop1.Ga)
2024+
dop2 = Dop([(dop2, Pdop({}, ga=dop1.Ga))], cmpflg=dop1.cmpflg, ga=dop1.Ga)
20232025
elif isinstance(dop2, Dop):
20242026
if not isinstance(dop1, Mv):
20252027
dop1 = dop2.Ga.mv(dop1)
2026-
dop1 = Dop([(dop1, dop2.Ga.Pdop_identity)], cmpflg=dop2.cmpflg, ga=dop2.Ga)
2028+
dop1 = Dop([(dop1, Pdop({}, ga=dop2.Ga))], cmpflg=dop2.cmpflg, ga=dop2.Ga)
20272029
else:
20282030
raise TypeError("Neither argument is a Dop instance")
20292031
return Dop.Add(dop1, dop2)

test/test_differential_ops.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ def test_components(self):
109109

110110
class TestSdop(object):
111111

112+
def test_deprecation(self):
113+
coords = x, y, z = symbols('x y z', real=True)
114+
ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
115+
116+
with pytest.warns(DeprecationWarning):
117+
ga.sPds
118+
112119
def test_shorthand(self):
113120
coords = x, y, z = symbols('x y z', real=True)
114121
ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
@@ -173,6 +180,11 @@ def test_deprecation(self):
173180
p = Pdop(None, ga=ga)
174181
assert p == Pdop({}, ga=ga)
175182

183+
with pytest.warns(DeprecationWarning):
184+
ga.Pdop_identity
185+
with pytest.warns(DeprecationWarning):
186+
ga.Pdiffs
187+
176188
def test_misc(self):
177189
""" Other miscellaneous tests """
178190
coords = x, y, z = symbols('x y z', real=True)

0 commit comments

Comments
 (0)