Skip to content

Commit 71e44c8

Browse files
committed
Deprecate useless copies of (base|blade)_expansion_dict
These are just `list(_dict.item())`. Furthermore, `nc_subs` can now be made faster in a future commit now that it is only called with dictionaries.
1 parent b9783d9 commit 71e44c8

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

doc/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Changelog
44

55
- :support:`245` (also :issue:`248`) The following attributes have been deprecated to reduce the number of similar members in :class:`~galgebra.ga.Ga`.
66

7+
* Unified into :attr:`galgebra.ga.Ga.blade_expansion_dict`:
8+
9+
* :attr:`galgebra.ga.Ga.blade_expansion` |rarr| ``blade_expansion_dict.items()``
10+
11+
* Unified into :attr:`galgebra.ga.Ga.base_expansion_dict`:
12+
13+
* :attr:`galgebra.ga.Ga.base_expansion` |rarr| ``base_expansion_dict.items()``
14+
715
* Unified into :attr:`galgebra.ga.Ga.basic_mul_table_dict`:
816

917
* :attr:`galgebra.ga.Ga.basic_mul_table` |rarr| ``basic_mul_table_dict.items()``

galgebra/ga.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,68 +1337,79 @@ def non_orthogonal_bases_products(self, base12): # base12 = (base1, base2)
13371337

13381338
def _build_base_blade_conversions(self):
13391339

1340-
blade_expansion = []
1341-
blade_index = []
1340+
blade_expansion_dict = OrderedDict()
13421341

13431342
# expand blade basis in terms of base basis
1344-
for blade in self.blades.flat:
1345-
index = self.indexes_to_blades_dict.inverse[blade]
1343+
for blade, index in zip(self.blades.flat, self.indexes.flat):
13461344
grade = len(index)
13471345
if grade <= 1:
1348-
blade_expansion.append(blade)
1349-
blade_index.append(index)
1346+
blade_expansion_dict[blade] = blade
13501347
else:
1351-
a = self.indexes_to_blades_dict[(index[0],)]
1352-
Aexpand = blade_expansion[blade_index.index(index[1:])]
1348+
a = self.indexes_to_blades_dict[index[:1]]
1349+
A = self.indexes_to_blades_dict[index[1:]]
1350+
Aexpand = blade_expansion_dict[A]
13531351
# Formula for outer (^) product of a vector and grade-r multivector
13541352
# a^A_{r} = (a*A + (-1)^{r}*A*a)/2
13551353
# The folowing evaluation takes the most time for setup it is the due to
13561354
# the substitution required for the multiplications
13571355
a_W_A = half * (self.basic_mul(a, Aexpand) - ((-1) ** grade) * self.basic_mul(Aexpand, a))
1358-
blade_index.append(index)
1359-
blade_expansion.append(expand(a_W_A))
1356+
blade_expansion_dict[blade] = expand(a_W_A)
13601357

1361-
self.blade_expansion = blade_expansion
1362-
self.blade_expansion_dict = OrderedDict(list(zip(self.blades.flat, blade_expansion)))
1358+
self.blade_expansion_dict = blade_expansion_dict
13631359

13641360
if self.debug:
13651361
print('blade_expansion_dict =', self.blade_expansion_dict)
13661362

13671363
# expand base basis in terms of blade basis
13681364

1369-
base_expand = []
1365+
base_expansion_dict = OrderedDict()
13701366

13711367
for base, blade, index in zip(self.bases.flat, self.blades.flat, self.indexes.flat):
13721368
grade = len(index)
13731369
if grade <= 1:
1374-
base_expand.append((base, base))
1370+
base_expansion_dict[base] = base
13751371
else: # back substitution of tridiagonal system
13761372
tmp = self.blade_expansion_dict[blade]
13771373
tmp = tmp.subs(base, -blade)
1378-
tmp = -tmp.subs(base_expand)
1379-
base_expand.append((base, expand(tmp)))
1374+
tmp = -tmp.subs(base_expansion_dict)
1375+
base_expansion_dict[base] = expand(tmp)
13801376

1381-
self.base_expand = base_expand
1382-
self.base_expansion_dict = OrderedDict(base_expand)
1377+
self.base_expansion_dict = base_expansion_dict
13831378

13841379
if self.debug:
13851380
print('base_expansion_dict =', self.base_expansion_dict)
13861381

1382+
@property
1383+
def base_expansion(self):
1384+
# galgebra 0.5.0
1385+
warnings.warn(
1386+
"`ga.base_expansion` is deprecated, use `ga.base_expansion_dict.items()`",
1387+
DeprecationWarning, stacklevel=2)
1388+
return list(self.base_expansion_dict.items())
1389+
1390+
@property
1391+
def blade_expansion(self):
1392+
# galgebra 0.5.0
1393+
warnings.warn(
1394+
"`ga.blade_expansion` is deprecated, use `ga.blade_expansion_dict.items()`",
1395+
DeprecationWarning, stacklevel=2)
1396+
return list(self.blade_expansion_dict.items())
1397+
13871398
def base_to_blade_rep(self, A):
13881399

13891400
if self.is_ortho:
13901401
return A
13911402
else:
13921403
# return expand(A).subs(self.base_expansion_dict)
1393-
return nc_subs(expand(A), self.base_expand)
1404+
return nc_subs(expand(A), self.base_expansion_dict.items())
13941405

13951406
def blade_to_base_rep(self, A):
13961407

13971408
if self.is_ortho:
13981409
return A
13991410
else:
14001411
# return expand(A).subs(self.blade_expansion_dict)
1401-
return nc_subs(expand(A), self.blades.flat, self.blade_expansion)
1412+
return nc_subs(expand(A), self.blade_expansion_dict.items())
14021413

14031414
###### Products (*,^,|,<,>) for multivector representations ########
14041415

test/test_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,13 @@ def test_deprecations(self):
465465

466466
# all derived from
467467
ga.basic_mul_table_dict
468+
469+
# deprecated to reduce the number of similar members
470+
with pytest.warns(DeprecationWarning):
471+
ga.blade_expansion
472+
with pytest.warns(DeprecationWarning):
473+
ga.base_expansion
474+
475+
# all derived from
476+
ga.blade_expansion_dict
477+
ga.base_expansion_dict

0 commit comments

Comments
 (0)