SciRuby / rb-gsl

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

Issue with Interp #28

Open DanielLeuenberger opened 8 years ago

DanielLeuenberger commented 8 years ago

Hi, I have this small test (test_interp.rb) of the Interp function:

require "gsl" x=[0,1,2,3,4].to_gv y=[0,1,2,3,4].to_gv x_new = [3.5].to_gv puts "x: #{x.inspect}" puts "y: #{y.inspect}" puts "x_new: #{x_new.inspect}" i=GSL::Interp.alloc("linear",x.length) y_new = i.eval(x,y,x_new) puts "y_new: #{y_new.inspect}"

With ruby 1.9.3p125, rb-gsl 1.14.7 and GSL 1.14 this always works fine.

With ruby 2.2.0, rb-gsl 1.16.0.6 and GSL 1.16 this gives the error:

test_interp.rb:9:in `eval': Ruby/GSL error code 1, interpolation error (file interp.c, line 150), input domain error (GSL::ERROR::EDOM)

The bad thing is: this error is not reproducable, sometimes the example works, but most of the time it does not. Is there a known issue which explains the behaviour?

Thanks and best regards Daniel

DanielLeuenberger commented 8 years ago

After unsuccessful fiddling around with older Versions of GSL and rb-gsl, I accidentally tried the following way of allocating the Interp object:

i=GSL::Interp.alloc("linear",x,y)

Now, the Baby example above works.

Maybe this helps also others and might help to fix a bug in the library?

v0dro commented 8 years ago

I think we should restrict allocation to one method only. I'll have a look soon.

DanielLeuenberger commented 8 years ago

Also the second way of allocating the Interp object, leads occasionally to the same error, though not so often as the first one. A fix would be highly appreciated! Thanks a lot!

urbanrotnik commented 3 years ago

I am also facing this problem...

I think we should restrict allocation to one method only. I'll have a look soon.

@v0dro What you mean with .. allocation to one method only.? Should I call interp.alloc only once per my ruby method or is a problem if I use Vector.alloc in the same method?