Skip to content

Commit

Permalink
Deprecate Pdiffs, sPds, and Pdop_identity
Browse files Browse the repository at this point in the history
These attributes all have shorter spellings, and now that `__eq__` and `__ne__` work, there's little need to cache them.
  • Loading branch information
eric-wieser committed Dec 19, 2019
1 parent 31a16a0 commit a15abea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
48 changes: 26 additions & 22 deletions galgebra/ga.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Geometric Algebra (inherits Metric)
"""

import warnings
import operator
import copy
from collections import OrderedDict
Expand Down Expand Up @@ -268,20 +268,6 @@ class Ga(metric.Metric):
Derivatives of basis functions. Two dimensional list. First entry is differentiating coordinate index.
Second entry is basis vector index. Quantities are linear combinations of basis vector symbols.
.. attribute:: Pdop_identity
Partial differential operator identity (operates on multivector function to return function).
.. attribute:: Pdiffs
Dictionary of partial differential operators (operates on multivector functions) for each coordinate
:math:`\{x: \partial_{x}, ...\}`
.. attribute:: sPds
Dictionary of scalar partial differential operators (operates on scalar functions) for each coordinate
:math:`\{x: \partial_{x}, ...\}`
.. attribute:: grad
Geometric derivative operator from left. ``grad*F`` returns multivector
Expand Down Expand Up @@ -420,12 +406,6 @@ def __init__(self, bases, **kwargs):
if self.coords is not None:
self.coord_vec = sum([coord * base for (coord, base) in zip(self.coords, self.basis)])
self._build_reciprocal_basis(self.gsym)
self.Pdop_identity = mv.Pdop({},ga=self) # Identity Pdop = 1
self.Pdiffs = {}
self.sPds = {}
for x in self.coords: # Partial derivative operator for each coordinate
self.Pdiffs[x] = mv.Pdop({x:1}, ga=self)
self.sPds[x] = mv.Sdop([(S(1), self.Pdiffs[x])], ga=self)
self._build_grads()
else:
self.r_basis_mv = None
Expand Down Expand Up @@ -516,6 +496,30 @@ def mv_x(self):
def X(self):
return self.mv(sum([coord*base for (coord, base) in zip(self.coords, self.basis)]))

@property
def Pdiffs(self):
# galgebra 0.4.5
warnings.warn(
"ga.Pdiffs[x] is deprecated, use `ga.pdop(x)` instead",
DeprecationWarning, stacklevel=2)
return {x: self.pdop(x) for x in self.coords}

@property
def sPds(self):
# galgebra 0.4.5
warnings.warn(
"ga.sPds[x] is deprecated, use `ga.sdop(x)` instead",
DeprecationWarning, stacklevel=2)
return {x: self.sdop(x) for x in self.coords}

@property
def Pdop_identity(self):
# galgebra 0.4.5
warnings.warn(
"ga.Pdop_identity is deprecated, use `ga.pdop({})` instead",
DeprecationWarning, stacklevel=2)
return self.pdop({})

def mv(self, root=None, *args, **kwargs):
"""
Instanciate and return a multivector for this, 'self',
Expand Down Expand Up @@ -600,7 +604,7 @@ def _build_grads(self):
if self.norm:
r_basis = [x / e_norm for (x, e_norm) in zip(self.r_basis_mv, self.e_norm)]

pdx = [self.Pdiffs[x] for x in self.coords]
pdx = [self.pdop(x) for x in self.coords]

self.grad = mv.Dop(r_basis, pdx, ga=self)
self.rgrad = mv.Dop(r_basis, pdx, ga=self, cmpflg=True)
Expand Down
16 changes: 9 additions & 7 deletions galgebra/mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,11 +1617,11 @@ def Add(sdop1, sdop2):
if isinstance(sdop1, Sdop):
if not isinstance(sdop2, Mv):
sdop2 = sdop1.Ga.mv(sdop2)
sdop2 = Sdop([(sdop2, sdop1.Ga.Pdop_identity)], ga=sdop1.Ga)
sdop2 = Sdop([(sdop2, Pdop({}, ga=sdop1.Ga))], ga=sdop1.Ga)
elif isinstance(sdop2, Sdop):
if not isinstance(sdop1, Mv):
sdop1 = sdop2.Ga.mv(sdop1)
sdop1 = Sdop([(sdop1, sdop2.Ga.Pdop_identity)], ga=sdop2.Ga)
sdop1 = Sdop([(sdop1, Pdop({}, ga=sdop2.Ga))], ga=sdop2.Ga)
else:
raise TypeError("Neither argument is a Dop instance")
return Sdop.Add(sdop1, sdop2)
Expand Down Expand Up @@ -1677,10 +1677,12 @@ class Pdop(object):
Attributes
----------
pdiffs : dict
a dictionary where coordinates are keys and key value are the number of
A dictionary where coordinates are keys and key value are the number of
times one differentiates with respect to the key.
order : int
total number of differentiations
Total number of differentiations.
When this is zero (i.e. when :attr:`pdiffs` is ``{}``) then this object
is the identity operator, and returns its operand unchanged.
"""

init_slots = {'ga': (None, 'Associated geometric algebra')}
Expand Down Expand Up @@ -1774,7 +1776,7 @@ def factor(self):
del new_pdiffs[x]
else:
new_pdiffs[x] -= 1
return Pdop(new_pdiffs, ga=self.Ga), self.Ga.Pdiffs[x]
return Pdop(new_pdiffs, ga=self.Ga), Pdop(x, ga=self.Ga)

def __call__(self, arg):
"""
Expand Down Expand Up @@ -2019,11 +2021,11 @@ def Add(dop1, dop2):
if isinstance(dop1, Dop):
if not isinstance(dop2, Mv):
dop2 = dop1.Ga.mv(dop2)
dop2 = Dop([(dop2, dop1.Ga.Pdop_identity)], cmpflg=dop1.cmpflg, ga=dop1.Ga)
dop2 = Dop([(dop2, Pdop({}, ga=dop1.Ga))], cmpflg=dop1.cmpflg, ga=dop1.Ga)
elif isinstance(dop2, Dop):
if not isinstance(dop1, Mv):
dop1 = dop2.Ga.mv(dop1)
dop1 = Dop([(dop1, dop2.Ga.Pdop_identity)], cmpflg=dop2.cmpflg, ga=dop2.Ga)
dop1 = Dop([(dop1, Pdop({}, ga=dop2.Ga))], cmpflg=dop2.cmpflg, ga=dop2.Ga)
else:
raise TypeError("Neither argument is a Dop instance")
return Dop.Add(dop1, dop2)
Expand Down
12 changes: 12 additions & 0 deletions test/test_differential_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def test_components(self):

class TestSdop(object):

def test_deprecation(self):
coords = x, y, z = symbols('x y z', real=True)
ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)

with pytest.warns(DeprecationWarning):
ga.sPds

def test_shorthand(self):
coords = x, y, z = symbols('x y z', real=True)
ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
Expand Down Expand Up @@ -173,6 +180,11 @@ def test_deprecation(self):
p = Pdop(None, ga=ga)
assert p == Pdop({}, ga=ga)

with pytest.warns(DeprecationWarning):
ga.Pdop_identity
with pytest.warns(DeprecationWarning):
ga.Pdiffs

def test_misc(self):
""" Other miscellaneous tests """
coords = x, y, z = symbols('x y z', real=True)
Expand Down

0 comments on commit a15abea

Please sign in to comment.