SciRuby / rb-gsl

Ruby interface to the GNU Scientific Library
https://github.com/SciRuby/rb-gsl
Other
100 stars 46 forks source link

Assign Ruby Complex types to GSL::Matrix::Complex #27

Open v0dro opened 8 years ago

v0dro commented 8 years ago

Currently numbers of the Ruby Complex type cannot be assigned to a matrix of type GSL::Matrix::Complex, it must have GSL::Complex types:


q = GSL::Matrix::Complex.alloc(2,2)
# => #<GSL::Matrix::Complex[2,2]:0x7da6cc0>
# [ [ 0.000e+00 0.000e+00 ] [ 0.000e+00 0.000e+00 ]
# [ 0.000e+00 0.000e+00 ] [ 0.000e+00 0.000e+00 ] ]

q[0,0] = Complex(2,3)
# TypeError: wrong type Complex, (nil, Array, Float, Integer, or GSL::Complex expected)

q[0,0] = GSL::Complex.alloc(2,3)
#=> #<GSL::Matrix::Complex[2,2]:0x7d9b488>
#[ [ 2.000e+00 3.000e+00 ] [ 0.000e+00 0.000e+00 ]
# [ 0.000e+00 0.000e+00 ] [ 0.000e+00 0.000e+00 ] ]

Making this work with Ruby Complex types would be great.

envp commented 8 years ago

I've added PR #38 for this, @v0dro can you please review?