Skip to content

Commit

Permalink
embarrasing hack for ufunc bug with operator overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenovic committed Sep 4, 2016
1 parent 4a53c89 commit bd3bb72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
20 changes: 19 additions & 1 deletion clifford/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,25 @@ def __init__(self, layout, value=None):
if self.value.shape != (self.layout.gaDims,):
raise ValueError("value must be a sequence of length %s" %
self.layout.gaDims)



def __array_wrap__(self,out_arr, context=None):
uf, objs, huh = context
if uf.__name__ =='multiply':
return objs[1]*objs[0]
if uf.__name__ =='divide':
return objs[1].inv()*objs[0]
elif uf.__name__=='add':
return objs[1]+objs[0]
elif uf.__name__=='subtract':
return -objs[1]+objs[0]
elif uf.__name__ =='exp':
return math.e**(objs[0])

else:
raise ValueError('i dont know what to do')


def _checkOther(self, other, coerce=1):
"""Ensure that the other argument has the same Layout or coerce value if
necessary/requested.
Expand Down
28 changes: 16 additions & 12 deletions examples/G2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -557,68 +557,72 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 66,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4.0 + (1.0^e01)"
"4.0 + (1.0^e0)"
]
},
"execution_count": 62,
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e01.__radd__(float64(4))"
"import clifford as cf\n",
"layout, blades = cf.Cl(2) \n",
"\n",
"e0= blades['e0']\n",
"e0.__radd__(float64(4))"
]
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 67,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([ 4., 4., 4., 5.])"
"4.0 + (1.0^e0)"
]
},
"execution_count": 63,
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"float64(4)+e01"
"e0.__add__(float64(4))"
]
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 69,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2.718281828459045"
"array([ 4., 5., 4., 4.])"
]
},
"execution_count": 64,
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e"
"float64(4)+e0"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion test_clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_inverse(self):
def test_exp(self):

layout, blades = self.algebras[0]
R = e**(blades['e01'])
R = exp(blades['e01'])
e0 = blades['e0']
R*e0*~R

Expand Down

0 comments on commit bd3bb72

Please sign in to comment.