Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# M = dimension of space
# N = number of vectors
M, N = A.shape
if is_complex is None:
if A.dtype == 'complex':
is_complex = True
else:
is_complex = False
if is_complex:
N = N * 2
M = M * 2
if layout is None:
layout, blades = Cl(M)
e_ = layout.basis_vectors_lst[:M]
a = [0 ^ e_[0]] * N
if not is_complex:
for n in range(N):
for m in range(M):
a[n] = (a[n]) + ((A[m, n]) ^ e_[m])
else:
for n in range(N // 2):
n_ = 2 * n
for m in range(M // 2):
m_ = 2 * m
def test_gp_op_ip(self):
layout = Cl(4, 1)[0]
e1 = layout.blades['e1']
e2 = layout.blades['e2']
e3 = layout.blades['e3']
e4 = layout.blades['e4']
e5 = layout.blades['e5']
e123 = layout.blades['e123']
np.testing.assert_almost_equal(e123.value, (e1 ^ e2 ^ e3).value)
np.testing.assert_almost_equal(e123.value, (e1 * e2 * e3).value)
e12345 = layout.blades['e12345']
np.testing.assert_almost_equal(e12345.value, (e1 ^ e2 ^ e3 ^ e4 ^ e5).value)
np.testing.assert_almost_equal(e12345.value, (e1 * e2 * e3 * e4 * e5).value)
e12 = layout.blades['e12']
np.testing.assert_almost_equal(-e12.value, (e2 ^ e1).value)
def test_factorise(self):
layout_a = Cl(3)[0]
layout,blades,stuff = conformalize(layout_a)
e1 = layout.blades['e1']
e2 = layout.blades['e2']
e3 = layout.blades['e3']
e4 = layout.blades['e4']
e5 = layout.blades['e5']
up = stuff['up']
blade = up(e1 + 3*e2 + 4*e3)^up(5*e1 + 3.3*e2 + 10*e3)^up(-13.1*e1)
basis, scale = blade.factorise()
new_blade = (reduce(lambda a, b: a^b, basis)*scale)
print(new_blade)
print(blade)
np.testing.assert_almost_equal(new_blade.value, blade.value, 5)
def test_metric(self):
layout = Cl(4, 1)[0]
e1 = layout.blades['e1']
e2 = layout.blades['e2']
e3 = layout.blades['e3']
e4 = layout.blades['e4']
e5 = layout.blades['e5']
self.assertAlmostEqual((e1 * e1)[0], 1)
self.assertAlmostEqual((e2 * e2)[0], 1)
self.assertAlmostEqual((e3 * e3)[0], 1)
self.assertAlmostEqual((e4 * e4)[0], 1)
self.assertAlmostEqual((e5 * e5)[0], -1)
def test_gp_op_ip(self):
layout = Cl(3)[0]
e1 = layout.blades['e1']
e2 = layout.blades['e2']
e3 = layout.blades['e3']
print('outer product')
e123 = layout.blades['e123']
np.testing.assert_almost_equal(e123.value, (e1 ^ e2 ^ e3).value)
np.testing.assert_almost_equal(e123.value, (e1 * e2 * e3).value)
print('outer product ordering')
e12 = layout.blades['e12']
np.testing.assert_almost_equal(-e12.value, (e2 ^ e1).value)
print('outer product zeros')
np.testing.assert_almost_equal(0, (e1 ^ e1).value)
np.testing.assert_almost_equal(0, (e2 ^ e2).value)
def test_sparse_multiply(self):
algebras = [Cl(i) for i in [3, 4]] + [conformalize(Cl(3)[0])]
# For all the algebras we are interested in
for alg in algebras:
layout = alg[0]
# Make two random multivectors
a = layout.randomMV()
b = layout.randomMV()
# Project the multivectors to the grades required
grades_possibilities = []
for r in range(1,len(layout.sig)):
possible_grades = [list(m) for m in list(itertools.combinations(range(len(layout.sig)), r))]
grades_possibilities += possible_grades
for i,grades_a in enumerate(grades_possibilities):
sparse_mv_a = sum([a(k) for k in grades_a])
for j,grades_b in enumerate(grades_possibilities):
sparse_mv_b = sum([b(k) for k in grades_b])
# Compute results
from . import Cl
layout, blades = Cl(5, 3)
locals().update(blades)
# for shorter reprs
layout.__name__ = 'layout'
layout.__module__ = __name__
n1 = e3 + e6
n2 = e4 + e7
n3 = e5 + e8
n1b = 0.5*(e6 - e3)
n2b = 0.5*(e7 - e4)
n3b = 0.5*(e8 - e5)
def up(x):
from . import Cl
layout, blades = Cl(2)
locals().update(blades)
# for shorter reprs
layout.__name__ = 'layout'
layout.__module__ = __name__
from . import Cl
layout, blades = Cl(3)
locals().update(blades)
# for shorter reprs
layout.__name__ = 'layout'
layout.__module__ = __name__
from . import Cl, conformalize
layout_orig, blades_orig = Cl(3)
layout, blades, stuff = conformalize(layout_orig)
locals().update(blades)
locals().update(stuff)
# for shorter reprs
layout.__name__ = 'layout'
layout.__module__ = __name__