Skip to content

Commit 46cde16

Browse files
authored
Merge pull request #241 from eric-wieser/fix-easy-flake8
Fix easy issues with flake8
2 parents 12f3f33 + 793d9ff commit 46cde16

File tree

8 files changed

+107
-132
lines changed

8 files changed

+107
-132
lines changed

galgebra/deprecated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
################################# MV class for backward compatibility ###################
55

6+
67
class MV(Mv):
78

89
@staticmethod
@@ -33,7 +34,6 @@ def setup(basis, metric=None, coords=None, rframe=False, debug=False, curv=(None
3334
else:
3435
return list(MV.GA.mv())
3536

36-
3737
def __init__(self, base, mvtype, fct=None, blade_rep=True):
3838
kwargs = {}
3939
if fct is not None:

galgebra/dop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def _eval_derivative_n_times_terms(terms, x, n):
5858
for k, term in enumerate(terms):
5959
dc = _basic_diff(term[0], x)
6060
pd = _basic_diff(term[1], x)
61-
#print 'D0, term, dc, pd =', D0, term, dc, pd
61+
# print 'D0, term, dc, pd =', D0, term, dc, pd
6262
if dc != 0:
6363
new_terms.append((dc, term[1]))
64-
if pd != 0 :
64+
if pd != 0:
6565
new_terms.append((term[0], pd))
6666
terms = new_terms
6767
return _consolidate_terms(terms)

galgebra/ga.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
one = S(1)
2727
zero = S(0)
2828

29+
2930
def all_same(items):
3031
return all(x == items[0] for x in items)
3132

@@ -138,6 +139,7 @@ def nc_subs(expr, base_keys, base_values=None):
138139
_T = TypeVar('T')
139140
_U = TypeVar('T')
140141

142+
141143
class GradedTuple(Tuple[Tuple[_T, ...], ...]):
142144
""" A nested tuple grouped by grade.
143145
@@ -352,7 +354,6 @@ class Ga(metric.Metric):
352354
'sph3d': 'r,theta,phi:[1,X[0]**2,X[0]**2*cos(X[1])**2]:[1,1,0]:norm=True',
353355
'para3d': 'u,v,z:[u**2+v**2,u**2+v**2,1]:[1,1,0]:norm=True'}
354356

355-
356357
@staticmethod
357358
def dual_mode(mode='I+'):
358359
"""
@@ -476,15 +477,15 @@ def __init__(self, bases, *, wedge=True, **kwargs):
476477
if self.e_sq == S(0):
477478
self.sing_flg = True
478479
print('!!!!If I**2 = 0, I cannot be normalized!!!!')
479-
#raise ValueError('!!!!If I**2 = 0, I cannot be normalized!!!!')
480+
# raise ValueError('!!!!If I**2 = 0, I cannot be normalized!!!!')
480481
if self.e_sq > S(0):
481482
self.i = self.e/sqrt(self.e_sq)
482483
self.i_inv = self.i
483484
else: # I**2 = -1
484485
self.i = self.e/sqrt(-self.e_sq)
485486
self.i_inv = -self.i
486487
else:
487-
if self.Isq == '+': # I**2 = 1
488+
if self.Isq == '+': # I**2 = 1
488489
self.i = self.e/sqrt(self.e_sq)
489490
self.i_inv = self.i
490491
else: # I**2 = -1
@@ -675,7 +676,7 @@ def bases_dict(self, prefix=None):
675676
>>> locals().update(ga.bases())
676677
'''
677678
if prefix is None:
678-
prefix='e'
679+
prefix = 'e'
679680
bl = self.blades.flat[1:] # do not include the scalar, which is not named
680681
var_names = [prefix+''.join([k for k in str(b) if k.isdigit()]) for b in bl]
681682

@@ -950,7 +951,7 @@ def _build_connection(self):
950951

951952
######## Functions for Calculation products of blades/bases ########
952953

953-
#******************** Geometric Product (*) ***********************#
954+
# ******************* Geometric Product (*) ********************** #
954955

955956
def geometric_product_basis_blades(self, blade12):
956957
# geometric (*) product for orthogonal basis
@@ -1036,9 +1037,9 @@ def reduce_basis(self, blst):
10361037
blst_flg[i] = tmp[2]
10371038
else: # blst_expand[i] revised
10381039
blst_coef[i] = -blst_coef[i]
1039-
#if revision force one more pass in case revision
1040-
#causes repeated index previous to revised pair of
1041-
#indexes
1040+
# if revision force one more pass in case revision
1041+
# causes repeated index previous to revised pair of
1042+
# indexes
10421043
blst_flg[i] = False
10431044
blst_expand[i] = tmp[3]
10441045
blst_coef.append(-blst_coef[i] * tmp[0])
@@ -1106,10 +1107,10 @@ def reduce_basis_loop(g, blst):
11061107
else:
11071108
blst1_flg = False # more revision needed
11081109
return a1, blst1, blst1_flg, blst
1109-
1110+
11101111
return True # revision complete, blst in normal order
11111112

1112-
#******************* Outer/wedge (^) product **********************#
1113+
# ****************** Outer/wedge (^) product ********************* #
11131114

11141115
@staticmethod
11151116
def blade_reduce(lst):
@@ -1151,7 +1152,7 @@ def wedge_product_basis_blades(self, blade12): # blade12 = blade1*blade2
11511152
else:
11521153
return S(0)
11531154

1154-
#****** Dot (|) product, reft (<) and right (>) contractions ******#
1155+
# ***** Dot (|) product, reft (<) and right (>) contractions ***** #
11551156

11561157
def _dot_product_grade(self, grade1, grade2, mode):
11571158
"""
@@ -1456,7 +1457,6 @@ def split_multivector(self, A):
14561457
else:
14571458
return (0, A)
14581459

1459-
14601460
def remove_scalar_part(self, A):
14611461
"""
14621462
Return non-commutative part (sympy object) of ``A.obj``.
@@ -1478,7 +1478,6 @@ def remove_scalar_part(self, A):
14781478
else:
14791479
return A
14801480

1481-
14821481
def scalar_part(self, A):
14831482

14841483
if isinstance(A, mv.Mv):
@@ -1498,7 +1497,6 @@ def scalar_part(self, A):
14981497
else:
14991498
return 0
15001499

1501-
15021500
"""
15031501
else:
15041502
if A.is_commutative:
@@ -1955,6 +1953,7 @@ def ReciprocalFrame(self, basis, mode='norm'):
19551953
def Mlt(self,*args,**kwargs):
19561954
return lt.Mlt(args[0], self, *args[1:], **kwargs)
19571955

1956+
19581957
class Sm(Ga):
19591958
"""
19601959
Submanifold is a geometric algebra defined on a submanifold of a
@@ -2011,7 +2010,7 @@ def __init__(self, __u, __coords, *, ga, norm=False, name=None, root='e', debug=
20112010
Base Geometric Algebra
20122011
"""
20132012

2014-
#print '!!!Enter Sm!!!'
2013+
# print '!!!Enter Sm!!!'
20152014

20162015
if printer.GaLatexPrinter.latex_flg:
20172016
printer.GaLatexPrinter.restore()
@@ -2034,19 +2033,19 @@ def __init__(self, __u, __coords, *, ga, norm=False, name=None, root='e', debug=
20342033
basis_str = basis_str[:-1]
20352034
"""
20362035

2037-
#print 'u =', u
2036+
# print 'u =', u
20382037

2039-
if isinstance(u,mv.Mv): #Define vector manifold
2038+
if isinstance(u,mv.Mv): # Define vector manifold
20402039
self.ebasis = []
20412040
for coord in coords:
2042-
#Partial derivation of vector function to get basis vectors
2041+
# Partial derivation of vector function to get basis vectors
20432042
self.ebasis.append(u.diff(coord))
20442043

2045-
#print 'sm ebasis =', self.ebasis
2044+
# print 'sm ebasis =', self.ebasis
20462045

20472046
self.g = []
20482047
for b1 in self.ebasis:
2049-
#Metric tensor from dot products of basis vectors
2048+
# Metric tensor from dot products of basis vectors
20502049
tmp = []
20512050
for b2 in self.ebasis:
20522051
tmp.append(b1 | b2)
@@ -2064,12 +2063,12 @@ def __init__(self, __u, __coords, *, ga, norm=False, name=None, root='e', debug=
20642063
tmp.append(diff(x_i, u_j))
20652064
dxdu.append(tmp)
20662065

2067-
#print 'dxdu =', dxdu
2066+
# print 'dxdu =', dxdu
20682067

20692068
sub_pairs = list(zip(ga.coords, u))
20702069

2071-
#Construct metric tensor form coordinate maps
2072-
g = eye(n_sub) #Zero n_sub x n_sub sympy matrix
2070+
# Construct metric tensor form coordinate maps
2071+
g = eye(n_sub) # Zero n_sub x n_sub sympy matrix
20732072
n_range = list(range(n_sub))
20742073
for i in n_range:
20752074
for j in n_range:
@@ -2084,8 +2083,8 @@ def __init__(self, __u, __coords, *, ga, norm=False, name=None, root='e', debug=
20842083

20852084
Ga.__init__(self, root, g=g, coords=coords, norm=norm, debug=debug)
20862085

2087-
if isinstance(u,mv.Mv): #Construct additional functions for vector manifold
2088-
#self.r_basis_mv under construction
2086+
if isinstance(u,mv.Mv): # Construct additional functions for vector manifold
2087+
# self.r_basis_mv under construction
20892088

20902089
pass
20912090

galgebra/lt.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Multivector Linear Transformation
33
"""
44

5-
import sys
65
import inspect
76
import types
87
import itertools
@@ -17,13 +16,15 @@
1716
from . import metric
1817
from . import mv
1918

19+
2020
def aprint(a):
2121
out = ''
2222
for ai in a:
2323
out += str(ai)+','
2424
print('['+out[:-1]+']')
2525
return
2626

27+
2728
def Symbolic_Matrix(root,coords=None,mode='g',f=False,sub=True):
2829
if sub:
2930
pos = '_'
@@ -95,6 +96,7 @@ def Matrix_to_dictionary(mat_rep,basis):
9596
dict_rep[basis[row]] += mat_rep[col,row]*basis[col]
9697
return dict_rep
9798

99+
98100
def Dictionary_to_Matrix(dict_rep, ga):
99101
""" Convert dictionary representation of linear transformation to matrix """
100102
basis = list(dict_rep.keys())
@@ -117,6 +119,7 @@ def Dictionary_to_Matrix(dict_rep, ga):
117119
lst_mat.append(lst_mat_row)
118120
return Transpose(Matrix(lst_mat))
119121

122+
120123
class Lt(object):
121124
r"""
122125
A Linear Transformation
@@ -151,7 +154,7 @@ class Lt(object):
151154

152155
@staticmethod
153156
def setup(ga):
154-
#coords = [Symbol('mu_' + str(x)) for x in ga.coords]
157+
# coords = [Symbol('mu_' + str(x)) for x in ga.coords]
155158
coords = ga.coords
156159
x = sum([coords[i] * ga.basis[i] for i in ga.n_range])
157160
return coords, x
@@ -199,7 +202,7 @@ def __init__(self, *args, ga, f=False, mode='g'):
199202
for (lt_i, base) in zip(mat_rep, self.Ga.basis):
200203
self.lt_dict[base] = lt_i
201204
else:
202-
#mat_rep = map(list, zip(*mat_rep)) # Transpose list of lists
205+
# mat_rep = map(list, zip(*mat_rep)) # Transpose list of lists
203206
for (row, base1) in zip(mat_rep, self.Ga.basis):
204207
tmp = 0
205208
for (col, base2) in zip(row, self.Ga.basis):
@@ -592,7 +595,7 @@ def Mlt_latex_str(self):
592595
expr_lst = Mlt.expand_expr(self.fvalue,self.Ga)
593596
latex_str = '\\begin{align*} '
594597
first = True
595-
cnt = 1 # Component count on line
598+
cnt = 1 # Component count on line
596599
for term in expr_lst:
597600
coef_str = str(term[0])
598601
coef_latex = printer.latex(term[0])
@@ -610,15 +613,15 @@ def Mlt_latex_str(self):
610613
latex_str += ' & ' + coef_latex
611614
else:
612615
latex_str += coef_latex
613-
if cnt%self.lcnt == 0:
616+
if cnt % self.lcnt == 0:
614617
latex_str += '\\\\ '
615618
cnt = 1
616619
else:
617620
cnt += 1
618621
if self.lcnt == len(expr_lst) or self.lcnt == 1:
619622
latex_str = latex_str[:-3]
620623
latex_str = latex_str + ' \\end{align*} \n'
621-
return latex_str
624+
return latex_str
622625

623626
def Fmt(self, lcnt=1, title=None):
624627
"""
@@ -710,17 +713,17 @@ def __init__(self, f, Ga, args, fct=False):
710713
self.nargs = len(args)
711714
self.lcnt = 1
712715
if isinstance(f, mv.Mv):
713-
if f.is_vector(): # f is vector T = f | a1
716+
if f.is_vector(): # f is vector T = f | a1
714717
if self.nargs != 1:
715718
raise ValueError('For mlt nargs != 1 for vector!\n')
716719
Ga.make_grad(self.args)
717720
self.fvalue = (f | self.args[0]).obj
718721
self.f = None
719-
else: # To be inplemented for f a general pure grade mulitvector
722+
else: # To be inplemented for f a general pure grade mulitvector
720723
self.nargs = len(args)
721724
self.fvalue = f
722725
self.f = None
723-
elif isinstance(f, Lt): # f is linear transformation T = a1 | f(a2)
726+
elif isinstance(f, Lt): # f is linear transformation T = a1 | f(a2)
724727
if self.nargs != 2:
725728
raise ValueError('For mlt nargs != 2 for linear transformation!\n')
726729
Ga.make_grad(self.args)
@@ -734,35 +737,35 @@ def __init__(self, f, Ga, args, fct=False):
734737
else:
735738
self.args = [args]
736739
self.nargs = 1
737-
if self.nargs > 1: # General tensor of rank > 1
740+
if self.nargs > 1: # General tensor of rank > 1
738741
t_indexes = self.nargs * [Mlt.extact_basis_indexes(self.Ga)]
739742
print(t_indexes)
740743
print(self.Ga.Pdiffs)
741744
self.fvalue = 0
742745
for (t_index,a_prod) in zip(itertools.product(*t_indexes),
743746
itertools.product(*self.Ga.Pdiffs)):
744-
if fct: # Tensor field
747+
if fct: # Tensor field
745748
coef = Function(f+'_'+''.join(map(str,t_index)),real=True)(*self.Ga.coords)
746-
else: # Constant Tensor
749+
else: # Constant Tensor
747750
coef = symbols(f+'_'+''.join(map(str,t_index)),real=True)
748751
coef *= reduce(lambda x, y: x*y, a_prod)
749752
self.fvalue += coef
750-
else: # General tensor of rank = 1
753+
else: # General tensor of rank = 1
751754
self.fvalue = 0
752755
for (t_index,a_prod) in zip(Mlt.extact_basis_indexes(self.Ga),self.Ga.pdiffs[0]):
753-
if fct: # Tensor field
756+
if fct: # Tensor field
754757
coef = Function(f+'_'+''.join(map(str,t_index)),real=True)(*self.Ga.coords)
755-
else: # Constant Tensor
758+
else: # Constant Tensor
756759
coef = symbols(f+'_'+''.join(map(str,t_index)),real=True)
757760
self.fvalue += coef * a_prod
758761
else:
759-
if isinstance(f, types.FunctionType): # Tensor defined by general multi-linear function
762+
if isinstance(f, types.FunctionType): # Tensor defined by general multi-linear function
760763
args, _varargs, _kwargs, _defaults = inspect.getargspec(f)
761764
self.nargs = len(args)
762765
self.f = f
763766
Mlt.increment_slots(self.nargs, Ga)
764767
self.fvalue = f(*tuple(Ga.a[0:self.nargs]))
765-
else: # Tensor defined by component expression
768+
else: # Tensor defined by component expression
766769
self.f = None
767770
self.nargs = len(args)
768771
Mlt.increment_slots(self.nargs, Ga)
@@ -897,6 +900,7 @@ def comps(self):
897900
indexes = itertools.product(basis, repeat=rank)
898901
output = ''
899902
for i, (e, i_index) in enumerate(zip(indexes, i_indexes)):
900-
if i_index[-1] % ndim == 0: print('')
903+
if i_index[-1] % ndim == 0:
904+
print('')
901905
output += str(i)+':'+str(i_index)+':'+str(self(*e)) + '\n'
902906
return output

0 commit comments

Comments
 (0)