Mixed type operations for complex numbers should be supported
For all the operations involving complex numbers and two input operands: we should also support one of the input operands being a real number. These are much more efficient to compute, and we save a conversion. So we will gain efficiency in two dimensions. Example:
"opcode": "BH_ADD",
...
"types": [
[ "BH_BOOL", "BH_BOOL", "BH_BOOL" ],
[ "BH_COMPLEX128", "BH_COMPLEX128", "BH_COMPLEX128" ],
[ "BH_COMPLEX64", "BH_COMPLEX64", "BH_COMPLEX64" ],
[ "BH_COMPLEX128", "BH_COMPLEX128", "BH_FLOAT64" ],
[ "BH_COMPLEX64", "BH_COMPLEX64", "BH_FLOAT32" ],
[ "BH_COMPLEX128", "BH_FLOAT64", "BH_COMPLEX128" ],
[ "BH_COMPLEX64", "BH_FLOAT32", "BH_COMPLEX64" ],
...
This is relevant most for: BH_ADD, BH_SUBTRACT, BH_MULTIPLY, BH_DIVIDE, BH_POWER
The benefits are lesser for, but if we are dong it ... might as well:BH_EQUAL, BH_NOT_EQUAL
It would probably also be relevant for the composite byte code BH_MULTIPLY
Some code:
import numpy as np
a = np.arange(10, dtype=np.float32)
z = np.arange(10, dtype=np.complex64)
print a + z
This won't run, but we would very much like it to run.
@madsbk This seems to be fixed? I get type casted correctly when running the following:
import numpy as np
a = np.arange(3, dtype=np.float32)
b = np.arange(3, dtype=np.float64)
z = np.arange(3, dtype=np.complex64)
x = np.arange(3, dtype=np.complex128)
r = a + z
print r # => [ 0.+0.j 2.+0.j 4.+0.j]
print r.dtype # => complex64
r = b + x
print r # => [ 0.+0.j 2.+0.j 4.+0.j]
print r.dtype # => complex128
r = b + z
print r # => [ 0.+0.j 2.+0.j 4.+0.j]
print r.dtype # => complex128
r = a + x
print r # => [ 0.+0.j 2.+0.j 4.+0.j]
print r.dtype # => complex128