Following numpy's convention, the matrix multiplication operator should be @, while * performs elementwise multiplication. Thus I have added the set of operation corresponding to matrix multiplications to the Gf class. I simply changed the names from mul to matmul and created the mul functions such that they call the matmul functions. In other words, the Gf objects works the same, but now one can also perform the @ multiplication if used to numpy. However, it is not possible to do elementwise multiplication.
Moreover, I noticed the the __rmul__ function of the Gf class was never called when the left operator was a numpy array. That is because the numpy array has a __mul__ function that is instead called and leads to errors. To prioritize the Gf functions, I have added a __array_priority__ value to the Gf class, which makes it call its __rmul__ before numpy's __mul__.
Dear all,
Following numpy's convention, the matrix multiplication operator should be @, while * performs elementwise multiplication. Thus I have added the set of operation corresponding to matrix multiplications to the Gf class. I simply changed the names from
mul
tomatmul
and created themul
functions such that they call thematmul
functions. In other words, the Gf objects works the same, but now one can also perform the @ multiplication if used to numpy. However, it is not possible to do elementwise multiplication.Moreover, I noticed the the
__rmul__
function of the Gf class was never called when the left operator was a numpy array. That is because the numpy array has a__mul__
function that is instead called and leads to errors. To prioritize the Gf functions, I have added a__array_priority__
value to the Gf class, which makes it call its__rmul__
before numpy's__mul__
.