/usr/lib/ruby/vendor_ruby/gsl/interp2d_fix.rb is in ruby-gsl 2.1.0.3+dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # Reasons for existence of this code:
#
# It so happens that GSL's 2D interpolation methods are somehow swapping X and
# Y co-ordinates and returning a wrong result. This is a bug in GSL, and in order
# to make up for that, we swap the x and y points before passing them to GSL.
# The detect_gsl_interp2d_swapping_bug method tests the inter2d eval function
# to see if the bug exists so that in case a future GSL update fixes the bug,
# this Ruby wrapper will remain unaffected.
#
# For testing whether the bug exists, the eval method is run and tested against
# what is known to be corrent output (ans_expected), and the @@swapped class
# variable is set to true if the result is not consistent with the expected
# output. If @swapped is true, the x and y values are internally swapped by
# the Ruby wrapper before passing them to GSL for processing.
module GSL
class Interp2d
module BugDetectHelper
class << self
def asymmetric_function(x, y)
x - 2*y
end
end
end
def self.detect_gsl_interp2d_swapping_bug
@@swapped = nil
x = GSL::Vector.alloc((-4..4).to_a)
y = GSL::Vector.alloc((-4..4).to_a)
z = []
x.each do |xi|
y.each do |yi|
z << BugDetectHelper.asymmetric_function(xi, yi)
end
end
z = GSL::Vector.alloc(z)
i2d = GSL::Interp2d.alloc(GSL::Interp2d::BICUBIC, x, y, z)
test_x = x[1]
test_y = y[1]
ans_normal = i2d.eval(x,y,z,test_x, test_y)
ans_swapped = i2d.eval(x,y,z,test_y, test_x)
ans_expected = BugDetectHelper.asymmetric_function(test_x, test_y)
@@swapped = ans_expected == ans_normal
@@swapped
end
def self.swapped
@@swapped
end
end
class Spline2d
@@swapped = GSL::Interp2d.detect_gsl_interp2d_swapping_bug
def self.swapped
@@swapped
end
end
end
GSL::Interp2d.detect_gsl_interp2d_swapping_bug
|