On Wed, May 1, 2013 at 4:22 PM, Daπid <davidmenhur@gmail.com> wrote:
On 1 May 2013 17:13, Todd <toddrjen@gmail.com> wrote:
Speaking of which, I think there should be a function to construct a complex array out of two identically-shaped floating-point arrays, as well as perhaps an np.i class that converts a real array to an imaginary one (using __mul__ and such).
np.i would be exactly the same as array * 1j, or am I missing anything?
I don't think we have a ufunc loop for multiply() that takes a float64 and a complex128 and returns a complex128. We just have a (complex128,complex128)->complex128. `x * 1j` first converts `x` to a complex128 array with the value in the real component, then multiplies that with 1j to move that value over to the imag component. A single operation that takes a float64 array and just makes a complex128 array with the values put in the imag component will reduce a temporary.
The same goes for constructing a complex, real + imag * 1j
Similarly, we can eliminate two temporaries here. Both of the cases are probably best addressed by a single function. The syntactic sugar of an np.i object is unnecessary, IMO. imag = np.tocomplex(0.0, x) z = np.tocomplex(x, y) -- Robert Kern