Skip to content

Commit

Permalink
Merge pull request #2 from utensil-contrib/15-pip
Browse files Browse the repository at this point in the history
Merge brombo/galgebra#15 and fix tests under Python 2 & 3
  • Loading branch information
utensil committed Sep 21, 2018
2 parents 187322b + 0f7c76c commit 7c664a1
Show file tree
Hide file tree
Showing 13 changed files with 691 additions and 539 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __pycache__/

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
Expand Down Expand Up @@ -43,7 +44,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
*.cover
*.covercover
.hypothesis/

# Translations
Expand Down Expand Up @@ -102,3 +103,9 @@ venv.bak/

# mypy
.mypy_cache/

# py.test cache
.pytest_cache

# backup files from 2to3
**/*.bak
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

sudo: false

language: python

matrix:
include:
- os: linux
python: '2.7'
env: CONDA=true
# Remove too many targets for now to speed up a build
# - os: linux
# python: '3.5'
# env: CONDA=true
- os: linux
python: '3.6'
env: CONDA=true


before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then lsb_release -a ; fi

install:
- python setup.py install

script:
- py.test galgebra/test_test.py
- py.test galgebra/test_mv.py
71 changes: 38 additions & 33 deletions galgebra/ga.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ga.py

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import operator
import copy
from sympy import diff, Rational, Symbol, S, Mul, Pow, Add, \
Expand All @@ -9,10 +13,11 @@
from collections import OrderedDict
#from sympy.core.compatibility import combinations
from itertools import combinations
import printer
import metric
import mv
import lt
from . import printer
from . import metric
from . import mv
from . import lt
from functools import reduce

half = Rational(1, 2)
one = S(1)
Expand Down Expand Up @@ -104,7 +109,7 @@ def nc_subs(expr, base_keys, base_values=None):
keys for long lists of keys.
"""
if base_values is None:
[base_keys, base_values] = zip(*base_keys)
[base_keys, base_values] = list(zip(*base_keys))

if expr.is_commutative:
return expr
Expand All @@ -129,7 +134,7 @@ def nc_subs(expr, base_keys, base_values=None):


class Ga(metric.Metric):
"""
r"""
The vector space (basis, metric, derivatives of basis vectors) is
defined by the base class 'Metric'.
Expand Down Expand Up @@ -299,7 +304,7 @@ def preset(setting, root='e', debug=False):
return Ga(*kargs, **kwargs)

def __eq__(self, ga):
if self.name == self.ga:
if self.name == ga.name:
return True
return False

Expand Down Expand Up @@ -356,7 +361,7 @@ def __init__(self, bases, **kwargs):
if self.e_sq.is_number:
if self.e_sq == S(0):
self.sing_flg = True
print '!!!!If I**2 = 0, I cannot be normalized!!!!'
print('!!!!If I**2 = 0, I cannot be normalized!!!!')
#raise ValueError('!!!!If I**2 = 0, I cannot be normalized!!!!')
if self.e_sq > S(0):
self.i = self.e/sqrt(self.e_sq)
Expand All @@ -379,7 +384,7 @@ def __init__(self, bases, **kwargs):
self.grads()

if self.debug:
print 'Exit Ga.__init__()'
print('Exit Ga.__init__()')

self.a = [] # List of dummy vectors for Mlt calculations
self.agrads = {} # Gradient operator with respect to vector a
Expand All @@ -393,7 +398,7 @@ def make_grad(self, a, cmpflg=False): # make gradient operator with respect to
self.make_grad(ai)
return

if a in self.agrads.keys():
if a in list(self.agrads.keys()):
return self.agrads[a]

if isinstance(a, mv.Mv):
Expand Down Expand Up @@ -467,7 +472,7 @@ def mv(self, root=None, *kargs, **kwargs):
return mv.Mv(root, *kargs, **kwargs)

def mvr(self,norm=True):
"""
r"""
Returns tumple of reciprocal basis vectors. If norm=True or
basis vectors are orthogonal the reciprocal basis is normalized
in the sense that
Expand Down Expand Up @@ -765,7 +770,7 @@ def basis_product_tables(self):

self.dot_mode = '|'
if self.debug:
print 'Exit basis_product_tables.\n'
print('Exit basis_product_tables.\n')
return

def build_connection(self):
Expand Down Expand Up @@ -1056,7 +1061,7 @@ def non_orthogonal_mul_table(self):
self.basic_mul_table_dict = OrderedDict(mul_table)

if self.debug:
print 'basic_mul_table =\n', self.basic_mul_table
print('basic_mul_table =\n', self.basic_mul_table)
return

def non_orthogonal_bases_products(self, base12): # base12 = (base1,base2)
Expand Down Expand Up @@ -1103,10 +1108,10 @@ def base_blade_conversions(self):
blade_expansion.append(expand(a_W_A))

self.blade_expansion = blade_expansion
self.blade_expansion_dict = OrderedDict(zip(self.blades_lst, blade_expansion))
self.blade_expansion_dict = OrderedDict(list(zip(self.blades_lst, blade_expansion)))

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

# expand base basis in terms of blade basis

Expand All @@ -1126,7 +1131,7 @@ def base_blade_conversions(self):
self.base_expansion_dict = OrderedDict(base_expand)

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

return

Expand Down Expand Up @@ -1236,7 +1241,7 @@ def grade_decomposition(self, A):
grade_dict = {}
for (coef,blade) in zip(coefs,blades):
if blade == one:
if 0 in grade_dict.keys():
if 0 in list(grade_dict.keys()):
grade_dict[0] += coef
else:
grade_dict[0] = coef
Expand All @@ -1247,7 +1252,7 @@ def grade_decomposition(self, A):
else:
grade_dict[grade] = coef * blade
if isinstance(A, mv.Mv):
for grade in grade_dict.keys():
for grade in list(grade_dict.keys()):
grade_dict[grade] = self.mv(grade_dict[grade])
return grade_dict

Expand Down Expand Up @@ -1422,7 +1427,7 @@ def even_odd(self, A, even=True): # Return even or odd part of A
##################### Multivector derivatives ######################

def build_reciprocal_basis(self,gsym):
"""
r"""
Calculate reciprocal basis vectors e^{j} where
e^{j}\cdot e_{k} = \delta_{k}^{j}
and \delta_{k}^{j} is the kronecker delta. We use the formula
Expand All @@ -1439,7 +1444,7 @@ def build_reciprocal_basis(self,gsym):
"""

if self.debug:
print 'Enter build_reciprocal_basis.\n'
print('Enter build_reciprocal_basis.\n')

if self.is_ortho:
self.r_basis = [self.basis[i] / self.g[i, i] for i in self.n_range]
Expand All @@ -1462,7 +1467,7 @@ def build_reciprocal_basis(self,gsym):
else:
self.e_sq = simplify((self.e * self.e).obj)
if self.debug:
print 'E**2 =', self.e_sq
print('E**2 =', self.e_sq)
duals = list(self.blades_lst[-(self.n + 1):-1])
duals.reverse()

Expand All @@ -1477,14 +1482,14 @@ def build_reciprocal_basis(self,gsym):
if self.debug:
printer.oprint('E', self.iobj, 'E**2', self.e_sq, 'unnormalized reciprocal basis =\n', self.r_basis)
self.dot_mode = '|'
print 'reciprocal basis test ='
print('reciprocal basis test =')
for ei in self.basis:
for ej in self.r_basis:
ei_dot_ej = self.dot(ei, ej)
if ei_dot_ej == zero:
print 'e_{i}|e_{j} = ' + str(ei_dot_ej)
print('e_{i}|e_{j} = ' + str(ei_dot_ej))
else:
print 'e_{i}|e_{j} = ' + str(expand(ei_dot_ej / self.e_sq))
print('e_{i}|e_{j} = ' + str(expand(ei_dot_ej / self.e_sq)))

self.e_obj = self.blades_lst[-1]

Expand Down Expand Up @@ -1527,7 +1532,7 @@ def build_reciprocal_basis(self,gsym):
self.g_inv = g_inv

if self.debug:
print 'reciprocal basis dictionary =\n', self.r_basis_dict
print('reciprocal basis dictionary =\n', self.r_basis_dict)

# True is for left derivative and False is for right derivative
self.deriv = {('*', True): [], ('^', True): [], ('|', True): [],
Expand Down Expand Up @@ -1663,9 +1668,9 @@ def grad_sqr(self, A, grad_sqr_mode, mode, left):
mode = *_{2} = *, ^, or |.
"""
(Sop, Bop) = Ga.DopFop[(grad_sqr_mode, mode)]
print '(Sop, Bop) =', Sop, Bop
print('(Sop, Bop) =', Sop, Bop)

print 'grad_sqr:A =', A
print('grad_sqr:A =', A)

self.dot_mode == '|'
s = zero
Expand All @@ -1677,7 +1682,7 @@ def grad_sqr(self, A, grad_sqr_mode, mode, left):
for coord_i in self.coords:
dA_i.append(self.pDiff(A, coord_i))

print 'dA_i =', dA_i
print('dA_i =', dA_i)

if Sop:
for i in self.n_range:
Expand All @@ -1692,8 +1697,8 @@ def grad_sqr(self, A, grad_sqr_mode, mode, left):
if Bop and self.connect_flg:
for i in self.n_range:
coord_i = self.coords[i]
print 'mode =', mode
print 'dA_i[i] =', dA_i[i]
print('mode =', mode)
print('dA_i[i] =', dA_i[i])
if left:
if mode == '|':
s += self.dot(self.grad_sq_mv_connect[coord_i], dA_i[i])
Expand Down Expand Up @@ -1882,11 +1887,11 @@ def __init__(self, *kargs, **kwargs):

#print 'dxdu =', dxdu

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

#Construct metric tensor form coordinate maps
g = eye(n_sub) #Zero n_sub x n_sub sympy matrix
n_range = range(n_sub)
n_range = list(range(n_sub))
for i in n_range:
for j in n_range:
s = zero
Expand All @@ -1912,7 +1917,7 @@ def __init__(self, *kargs, **kwargs):
self.u = u

if debug:
print 'Exit Sm.__init__()'
print('Exit Sm.__init__()')

def vpds(self):
if not self.is_ortho:
Expand Down
Loading

0 comments on commit 7c664a1

Please sign in to comment.