Skip to content

Commit

Permalink
Make it an error to pass string and value at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Mar 24, 2020
1 parent 4e470ab commit 019a426
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions clifford/_multivector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ def __init__(self, layout, value=None, string=None, *, dtype: np.dtype = np.floa

self.layout = layout

if value is None:
if string is None:
self.value = np.zeros((self.layout.gaDims,), dtype=dtype)
else:
self.value = layout.parse_multivector(string).value
if string is not None:
if value is not None:
raise TypeError("Cannot pass both string and value")
self.value = layout.parse_multivector(string).value

elif value is None:
self.value = np.zeros((self.layout.gaDims,), dtype=dtype)

else:
self.value = np.array(value)
if self.value.shape != (self.layout.gaDims,):
Expand Down
8 changes: 8 additions & 0 deletions clifford/test/test_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ def test_meet(self, g3):
assert equivalent_up_to_scale((b^c).meet(a), 1)
assert equivalent_up_to_scale((a).meet(a), a)

def test_multivector_constructor(self, g3):
# either is ok
g3.MultiVector(string='e1')
g3.MultiVector(value=np.zeros(8))
# both together is illegal
with pytest.raises(TypeError):
g3.MultiVector(string='e1', value=np.zeros(8))


class TestBasicConformal41:
def test_metric(self, g4_1):
Expand Down

0 comments on commit 019a426

Please sign in to comment.