Skip to content

Commit

Permalink
Merge pull request #357 from eric-wieser/int-complement
Browse files Browse the repository at this point in the history
Preserve dtypes in left_complement, right_complement, and dual
  • Loading branch information
eric-wieser committed Sep 11, 2020
2 parents eaff2cc + cdea070 commit f73d17d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions clifford/_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,14 @@ def dual_func(self):
else:
# Equivalent to but faster than
# Iinv = self.pseudoScalar.inv().value
Iinv = np.zeros(self.gaDims)
II_scalar = self.gmt[-1, 0, -1]
inv_II_scalar = 1 / II_scalar
if II_scalar in (1, -1):
Iinv = np.zeros(self.gaDims, dtype=int)
else:
Iinv = np.zeros(self.gaDims, dtype=type(inv_II_scalar))
# set the pseudo-scalar part
Iinv[-1] = 1 / II_scalar
Iinv[-1] = inv_II_scalar

gmt_func = self.gmt_func
@_numba_utils.njit
Expand Down Expand Up @@ -574,7 +578,7 @@ def _gen_complement_func(self, omt):

@_numba_utils.njit
def comp_func(Xval):
Yval = np.zeros(dims)
Yval = np.zeros(dims, dtype=Xval.dtype)
for i, s in enumerate(signlist):
Yval[i] = Xval[dims-1-i]*s
return Yval
Expand Down
4 changes: 4 additions & 0 deletions clifford/test/test_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,17 @@ def test_binary_op_preserves_dtype(self, dtype, func, g3):
e1 = blades['e1'].astype(dtype)
e2 = blades['e2'].astype(dtype)
assert func(e1, np.int8(1)).value.dtype == dtype
assert func(np.int8(1), e1).value.dtype == dtype
assert func(e1, e2).value.dtype == dtype

@pytest.mark.parametrize('func', [
operator.inv,
operator.pos,
operator.neg,
MultiVector.gradeInvol,
MultiVector.dual,
MultiVector.right_complement,
MultiVector.left_complement,
])
def test_unary_op_preserves_dtype(self, func, g3):
""" test that simple unary ops on blades do not promote types """
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Changes in 1.4.x
* Projection using :meth:`Multivector.__call__` no longer raises :exc:`ValueError`
for grades not present in the algebra, and instead just returns zero.

* Where possible, ``MultiVector``\ s preserve their data type in the dual, and
the right and left complements.

Changes in 1.3.x
++++++++++++++++

Expand Down

0 comments on commit f73d17d

Please sign in to comment.