complex-numbers

What's the fastest way to convert an interleaved NumPy integer array to complex64?

♀尐吖头ヾ 提交于 2019-12-01 16:18:51
I have a stream of incoming data that has interleaved real and imaginary integers. Converting these to complex64 values is the slowest operation in my program. This is my current approach: import numpy as np a = np.zeros(1000000, dtype=np.int16) b = np.complex64(a[::2]) + np.complex64(1j) * np.complex64(a[1::2]) Can I do better without making a C extension or using something like cython? If I can't do better, what's my easiest approach using a technology like one of these? [~] |1> import numpy as np [~] |2> a = np.zeros(1000000, dtype=np.int16) [~] |3> b = a.astype(np.float32).view(np

What's the fastest way to convert an interleaved NumPy integer array to complex64?

 ̄綄美尐妖づ 提交于 2019-12-01 15:08:02
问题 I have a stream of incoming data that has interleaved real and imaginary integers. Converting these to complex64 values is the slowest operation in my program. This is my current approach: import numpy as np a = np.zeros(1000000, dtype=np.int16) b = np.complex64(a[::2]) + np.complex64(1j) * np.complex64(a[1::2]) Can I do better without making a C extension or using something like cython? If I can't do better, what's my easiest approach using a technology like one of these? 回答1: [~] |1> import

Cython: error adding complex[double] to double

雨燕双飞 提交于 2019-12-01 14:29:16
According to libcpp/complex.pxd adding T to complex[T] is supported: complex[T] operator+(complex[T]&, T&) complex[T] operator+(T&, complex[T]&) But it doesn't work: a.pyx: # distutils: language = c++ cimport libcpp.complex def f(): libcpp.complex.complex[double](1,2) + libcpp.complex.complex[double](2,3) # ok libcpp.complex.complex[double](1,2) + 5. # Cannot assign type 'double' to 'complex[double]' 5. + libcpp.complex.complex[double](1,2) # Invalid operand types for '+' (double; complex[double]) setup.pyx: from distutils.core import setup from Cython.Build import cythonize setup( name =

Interpolate whole arrays of complex numbers

杀马特。学长 韩版系。学妹 提交于 2019-12-01 13:57:51
I have a number of 2-dimensional np.arrays (all of equal size) containing complex numbers. Each of them belongs to one position in a 4-dimensional space. Those positions are sparse and distributed irregularly (a latin hypercube to be precise). I would like to interpolate this data to other points in the same 4-dimensional space. I can successfully do this for simple numbers, using either sklearn.kriging() , scipy.interpolate.Rbf() (or others): # arrayof co-ordinates: 2 4D sets X = np.array([[1.0, 0.0, 0.0, 0.0],\ [0.0, 1.0, 0.0, 0.0]]) # two numbers, one for each of the points above Y = np

Is it guaranteed that Complex Float variables will be 8-byte aligned in memory?

谁说我不能喝 提交于 2019-12-01 13:02:37
In C99 the new complex types were defined. I am trying to understand whether a compiler can take advantage of this knowledge in optimizing memory accesses. Are these objects ( A - F ) of type complex float guaranteed to be 8-byte aligned in memory? #include "complex.h" typedef complex float cfloat; cfloat A; cfloat B[10]; void func(cfloat C, cfloat *D) { cfloat E; cfloat F[10]; } Note that for D , the question relates to the object pointed to by D , not to the pointer storage itself. And, if that is assumed aligned, how can one be sure that the address passed is of an actual complex and not a

Interpolate whole arrays of complex numbers

天涯浪子 提交于 2019-12-01 12:47:10
问题 I have a number of 2-dimensional np.arrays (all of equal size) containing complex numbers. Each of them belongs to one position in a 4-dimensional space. Those positions are sparse and distributed irregularly (a latin hypercube to be precise). I would like to interpolate this data to other points in the same 4-dimensional space. I can successfully do this for simple numbers, using either sklearn.kriging() , scipy.interpolate.Rbf() (or others): # arrayof co-ordinates: 2 4D sets X = np.array([

Cython: error adding complex[double] to double

巧了我就是萌 提交于 2019-12-01 12:11:57
问题 According to libcpp/complex.pxd adding T to complex[T] is supported: complex[T] operator+(complex[T]&, T&) complex[T] operator+(T&, complex[T]&) But it doesn't work: a.pyx: # distutils: language = c++ cimport libcpp.complex def f(): libcpp.complex.complex[double](1,2) + libcpp.complex.complex[double](2,3) # ok libcpp.complex.complex[double](1,2) + 5. # Cannot assign type 'double' to 'complex[double]' 5. + libcpp.complex.complex[double](1,2) # Invalid operand types for '+' (double; complex

How to compute the square root of negative numbers?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 11:21:25
I'm trying to create a complex number from the square root of a negative number using the following code: include Math z = Complex(sqrt(-9)) But it produces this error: Math::DomainError: Numerical argument is out of domain - "sqrt" from kata2.rb:20:in `sqrt' from kata2.rb:20:in `polinomio' from kata2.rb:34 from /home/howarto/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>' How can I build a complex number from the square root of a negative number? The Math.sqrt function can't compute the square root of negative numbers: irb> Math.sqrt(-1) Math::DomainError: Numerical argument is out of

How to compute the square root of negative numbers?

牧云@^-^@ 提交于 2019-12-01 07:26:39
问题 I'm trying to create a complex number from the square root of a negative number using the following code: include Math z = Complex(sqrt(-9)) But it produces this error: Math::DomainError: Numerical argument is out of domain - "sqrt" from kata2.rb:20:in `sqrt' from kata2.rb:20:in `polinomio' from kata2.rb:34 from /home/howarto/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>' How can I build a complex number from the square root of a negative number? 回答1: The Math.sqrt function can't compute

Problem casting STL complex<double> to fftw_complex

删除回忆录丶 提交于 2019-11-30 12:25:33
问题 The FFTW manual says that its fftw_complex type is bit compatible to std::complex<double> class in STL. But that doesn't work for me: #include <complex> #include <fftw3.h> int main() { std::complex<double> x(1,0); fftw_complex fx; fx = reinterpret_cast<fftw_complex>(x); } This gives me an error: error: invalid cast from type ‘std::complex<double>’ to type ‘double [2]’ What am I doing wrong? 回答1: Re-write your code as follows: #include <complex> #include <fftw3.h> int main() { std::complex