bh107 / bohrium

Automatic parallelization of Python/NumPy, C, and C++ codes on Linux and MacOSX
http://www.bh107.org
Apache License 2.0
221 stars 31 forks source link

Mixed type operations for complex numbers should be supported #29

Open tblum opened 9 years ago

tblum commented 9 years ago

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

omegahm commented 8 years ago

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.

omegahm commented 7 years ago

@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