diff --git a/galgebra/ga.py b/galgebra/ga.py index 81a03471..704f89aa 100644 --- a/galgebra/ga.py +++ b/galgebra/ga.py @@ -1,7 +1,7 @@ """ Geometric Algebra (inherits Metric) """ - +import warnings import operator import copy from collections import OrderedDict @@ -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 @@ -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 @@ -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', @@ -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) diff --git a/galgebra/mv.py b/galgebra/mv.py index bdc13091..0fdd7616 100644 --- a/galgebra/mv.py +++ b/galgebra/mv.py @@ -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) @@ -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')} @@ -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): """ @@ -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) diff --git a/test/test_differential_ops.py b/test/test_differential_ops.py index 1371332e..d97c33a1 100644 --- a/test/test_differential_ops.py +++ b/test/test_differential_ops.py @@ -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) @@ -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)