ruby-gsl-ng 0.2.4.1 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,8 +14,10 @@ module GSLng
14
14
  @owner = owner
15
15
  @m,@n = m,n
16
16
 
17
+ @backend = GSLng.backend
17
18
  ptr = GSLng.backend::gsl_matrix_submatrix2(owner.ptr, x, y, m, n)
18
19
  @ptr = FFI::AutoPointer.new(ptr, View.method(:release))
20
+ @ptr_value = @ptr.to_i
19
21
  end
20
22
 
21
23
  def View.release(ptr)
@@ -27,8 +27,12 @@ module GSLng
27
27
  # Close the pipe. It is desireable to call this in an "ensure" section, to avoid
28
28
  # leaving the child gnuplot process there if the main ruby process dies
29
29
  def close
30
- Process.kill 'TERM', @io.pid
31
- @io.close; @io = nil
30
+ pid = @io.pid
31
+ @io.flush; @io.close; @io = nil
32
+ begin
33
+ Process.kill 'TERM', pid
34
+ rescue Errno::ESRCH
35
+ end
32
36
  end
33
37
 
34
38
  # Send a command to the gnuplot process
@@ -16,6 +16,7 @@ module GSLng
16
16
 
17
17
  attr_reader :size, :stride
18
18
  attr_reader :ptr # @private
19
+ attr_reader :ptr_value # @private
19
20
 
20
21
  # @group Constructors
21
22
 
@@ -23,19 +24,23 @@ module GSLng
23
24
  # Otherwise, the vector will contain garbage.
24
25
  # You can optionally pass a block, in which case {#map_index!} will be called with it (i.e.: it works like {Array.new}).
25
26
  def initialize(n, zero = false)
26
- ptr = (zero ? GSLng.backend::gsl_vector_calloc(n) : GSLng.backend::gsl_vector_alloc(n))
27
+ @backend = GSLng.backend
28
+ ptr = (zero ? @backend.gsl_vector_calloc(n) : @backend.gsl_vector_alloc(n))
27
29
  @ptr = FFI::AutoPointer.new(ptr, Vector.method(:release))
30
+ @ptr_value = @ptr.to_i
28
31
  @size = n
29
32
  @stride = 1
30
33
  if (block_given?) then self.map_index!(Proc.new) end
31
34
  end
32
35
 
33
36
  def initialize_copy(other) # @private
34
- ptr = GSLng.backend::gsl_vector_alloc(other.size)
37
+ @backend = GSLng.backend
38
+ ptr = @backend.gsl_vector_alloc(other.size)
35
39
  @ptr = FFI::AutoPointer.new(ptr, Vector.method(:release))
40
+ @ptr_value = @ptr.to_i
36
41
  @size = other.size
37
42
  @stride = 1
38
- GSLng.backend::gsl_vector_memcpy(@ptr, other.ptr)
43
+ @backend.gsl_vector_memcpy(@ptr, other.ptr)
39
44
  end
40
45
 
41
46
  def Vector.release(ptr) # @private
@@ -49,10 +54,16 @@ module GSLng
49
54
  def Vector.from_array(array)
50
55
  if (array.empty?) then raise "Can't create empty vector" end
51
56
  v = Vector.new(array.size)
52
- GSLng.backend.gsl_vector_from_array(v.ptr.to_i, array)
57
+ GSLng.backend.gsl_vector_from_array(v.ptr_value, array)
53
58
  return v
54
59
  end
55
60
 
61
+ # Creates a Vector with linearly distributed values between +start+ and +stop+, separated by +delta+.
62
+ def Vector.linspace(start, stop, delta)
63
+ if (start > stop || delta <= 0) then raise 'Invalid values' end
64
+ Vector.new(((stop - start) / delta).floor.to_i + 1) {|i| start + delta * i}
65
+ end
66
+
56
67
  # Creates a Vector from an Array or a Range
57
68
  # @see Vector::from_array
58
69
  # @example
@@ -76,8 +87,8 @@ module GSLng
76
87
  # @return [Vector] self
77
88
  def add!(other)
78
89
  case other
79
- when Numeric; GSLng.backend::gsl_vector_add_constant(self.ptr, other.to_f)
80
- when Vector; GSLng.backend::gsl_vector_add(self.ptr, other.ptr)
90
+ when Numeric; @backend.gsl_vector_add_constant(@ptr, other.to_f)
91
+ when Vector; @backend.gsl_vector_add(@ptr, other.ptr)
81
92
  else
82
93
  x,y = other.coerce(self)
83
94
  x.add!(y)
@@ -89,8 +100,8 @@ module GSLng
89
100
  # @return [Vector] self
90
101
  def substract!(other)
91
102
  case other
92
- when Numeric; GSLng.backend::gsl_vector_add_constant(self.ptr, -other.to_f)
93
- when Vector; GSLng.backend::gsl_vector_sub(self.ptr, other.ptr)
103
+ when Numeric; @backend.gsl_vector_add_constant(@ptr, -other.to_f)
104
+ when Vector; @backend.gsl_vector_sub(@ptr, other.ptr)
94
105
  else
95
106
  x,y = other.coerce(self)
96
107
  x.sub!(y)
@@ -103,8 +114,8 @@ module GSLng
103
114
  # @return [Vector] self
104
115
  def multiply!(other)
105
116
  case other
106
- when Numeric; GSLng.backend::gsl_blas_dscal(other.to_f, self.ptr)
107
- when Vector; GSLng.backend::gsl_vector_mul(self.ptr, other.ptr)
117
+ when Numeric; @backend.gsl_blas_dscal(other.to_f, @ptr)
118
+ when Vector; @backend.gsl_vector_mul(@ptr, other.ptr)
108
119
  else
109
120
  x,y = other.coerce(self)
110
121
  x.mul!(y)
@@ -117,8 +128,8 @@ module GSLng
117
128
  # @return [Vector] self
118
129
  def divide!(other)
119
130
  case other
120
- when Numeric; GSLng.backend::gsl_blas_dscal(1.0 / other, self.ptr)
121
- when Vector; GSLng.backend::gsl_vector_div(self.ptr, other.ptr)
131
+ when Numeric; @backend.gsl_blas_dscal(1.0 / other, @ptr)
132
+ when Vector; @backend.gsl_vector_div(@ptr, other.ptr)
122
133
  else
123
134
  x,y = other.coerce(self)
124
135
  x.div!(y)
@@ -161,57 +172,57 @@ module GSLng
161
172
  # Vector[1,2,3] ^ Vector[0,1,2] => 8.0
162
173
  def dot(other)
163
174
  out = FFI::Buffer.new(:double)
164
- GSLng.backend::gsl_blas_ddot(self.ptr, other.ptr, out)
175
+ @backend.gsl_blas_ddot(@ptr, other.ptr, out)
165
176
  return out[0].get_double(0)
166
177
  end
167
178
  alias_method :^, :dot
168
179
 
169
180
  # Norm 2 of the vector (uses BLAS's dnrm2)
170
- def norm; GSLng.backend::gsl_blas_dnrm2(self.ptr) end
181
+ def norm; @backend.gsl_blas_dnrm2(@ptr) end
171
182
  alias_method :length, :norm
172
183
 
173
184
  # Returns the sum of all elements (uses BLAS's dasum)
174
- def sum; GSLng.backend::gsl_blas_dasum(self.ptr) end
185
+ def sum; @backend.gsl_blas_dasum(@ptr) end
175
186
 
176
187
  # Optimized version of: self += other * alpha (where alpha is a Numeric). Uses BLAS's daxpy.
177
- def mul_add(other, alpha); GSLng.backend::gsl_blas_daxpy(alpha, other.ptr, self.ptr); return self end
188
+ def mul_add(other, alpha); @backend.gsl_blas_daxpy(alpha, other.ptr, @ptr); return self end
178
189
 
179
190
  # @group Miscelaneous methods
180
191
 
181
192
  # Reverse the order of elements
182
- def reverse!; GSLng.backend::gsl_vector_reverse(self.ptr); return self end
193
+ def reverse!; @backend.gsl_vector_reverse(@ptr); return self end
183
194
 
184
195
  # Swap the i-th element with the j-th element
185
- def swap(i,j); GSLng.backend::gsl_vector_swap_elements(self.ptr, i, j); return self end
196
+ def swap(i,j); @backend.gsl_vector_swap_elements(@ptr, i, j); return self end
186
197
 
187
- def sort!; GSLng.backend::gsl_sort_vector(self.ptr); return self end
198
+ def sort!; @backend.gsl_sort_vector(@ptr); return self end
188
199
  def sort; self.dup.sort! end
189
200
 
190
201
  # Copy other's values into self
191
- def copy(other); GSLng.backend::gsl_vector_memcpy(self.ptr, other.ptr); return self end
202
+ def copy(other); @backend.gsl_vector_memcpy(@ptr, other.ptr); return self end
192
203
 
193
- # Wraps self into the interval [min,max) by adding or substracting (max-min) to each component as necessary.
194
- # Note that wrapping is done only with a single addition/substraction.
195
- # @param [Vector,Numeric] min
196
- # @param [Vector,Numeric] max
204
+ # Wraps self into the interval [0,up_to). NOTE: this value must be > 0
205
+ # @param [Vector,Numeric] up_to
197
206
  # @return [Vector] a vector of values -1, 1 or 0, if (max-min) was substracted, added to the coordinate,
198
207
  # or not modified, respectively.
199
208
  # @example Assuming that +v = Vector[-8,2,8]+
200
- # v.wrap(0, 5) => [1.0 0.0 -1.0]:Vector
209
+ # v.wrap(5) => [1.0 0.0 -1.0]:Vector
201
210
  # v => [-3.0 2.0 3.0]:Vector
202
- def wrap!(min, max)
203
- min,other = self.coerce(min)
204
- max,other = self.coerce(max)
211
+ def wrap!(up_to)
205
212
  delta = Vector.new(self.size)
206
- range = max - min
207
-
208
213
  self.map_index! do |i|
209
- if (self[i] < min[i]) then delta[i] = 1; self[i] + range[i]
210
- elsif (self[i] >= max[i]) then delta[i] = -1; self[i] - range[i]
211
- else delta[i] = 0; self[i] end
214
+ a,b = self[i].divmod(up_to)
215
+ delta[i] = -a
216
+ b
212
217
  end
213
218
  return delta
214
219
  end
220
+
221
+ # Compute hash value for this Vector.
222
+ # Note: this may be a bit inefficient for now
223
+ def hash
224
+ self.to_a.hash
225
+ end
215
226
 
216
227
  # @group Setting/getting values
217
228
 
@@ -220,7 +231,7 @@ module GSLng
220
231
  # @raise [RuntimeError] if out-of-bounds
221
232
  # @todo support ranges
222
233
  def [](index)
223
- GSLng.backend.gsl_vector_get_operator(self.ptr.to_i, index)
234
+ @backend.gsl_vector_get_operator(@ptr_value, index)
224
235
  end
225
236
 
226
237
  # Set the i-th element.
@@ -228,7 +239,8 @@ module GSLng
228
239
  # @raise [RuntimeError] if out-of-bounds
229
240
  # @todo support ranges
230
241
  def []=(index, value)
231
- GSLng.backend::gsl_vector_set(self.ptr, (index < 0 ? @size + index : index), value.to_f)
242
+ @backend.gsl_vector_set_operator(@ptr_value, index, value.to_f)
243
+ #@backend.gsl_vector_set(@ptr, (index < 0 ? @size + index : index), value.to_f)
232
244
  end
233
245
 
234
246
  # @group Views
@@ -244,8 +256,8 @@ module GSLng
244
256
  size = k + (m == 0 ? 0 : 1)
245
257
  end
246
258
 
247
- if (stride == 1) then ptr = GSLng.backend::gsl_vector_subvector2(self.ptr, offset, size)
248
- else ptr = GSLng.backend::gsl_vector_subvector_with_stride2(self.ptr, offset, stride, size) end
259
+ if (stride == 1) then ptr = @backend.gsl_vector_subvector2(@ptr, offset, size)
260
+ else ptr = @backend.gsl_vector_subvector_with_stride2(@ptr, offset, stride, size) end
249
261
  View.new(ptr, self, size, stride)
250
262
  end
251
263
  alias_method :subvector_view, :view
@@ -254,49 +266,49 @@ module GSLng
254
266
  def subvector(*args); subvector_view(*args).to_vector end
255
267
 
256
268
  # Set all values to v
257
- def all!(v); GSLng.backend::gsl_vector_set_all(self.ptr, v); return self end
269
+ def all!(v); @backend.gsl_vector_set_all(@ptr, v); return self end
258
270
  alias_method :set!, :all!
259
271
  alias_method :fill!, :all!
260
272
 
261
273
  # Set all values to zero
262
- def zero!; GSLng.backend::gsl_vector_set_zero(self.ptr); return self end
274
+ def zero!; @backend.gsl_vector_set_zero(@ptr); return self end
263
275
 
264
276
  # Set all values to zero, except the i-th element, which is set to 1
265
- def basis!(i); GSLng.backend::gsl_vector_set_basis(self.ptr, i); return self end
277
+ def basis!(i); @backend.gsl_vector_set_basis(@ptr, i); return self end
266
278
 
267
279
  # @group 2D/3D/4D utility vectors
268
280
 
269
281
  # Same as Vector#[0]
270
- def x; GSLng.backend::gsl_vector_get(self.ptr, 0) end
282
+ def x; @backend.gsl_vector_get(@ptr, 0) end
271
283
  # Same as Vector#[1]
272
- def y; GSLng.backend::gsl_vector_get(self.ptr, 1) end
284
+ def y; @backend.gsl_vector_get(@ptr, 1) end
273
285
  # Same as Vector#[2]
274
- def z; GSLng.backend::gsl_vector_get(self.ptr, 2) end
286
+ def z; @backend.gsl_vector_get(@ptr, 2) end
275
287
  # Same as Vector#[3]
276
- def w; GSLng.backend::gsl_vector_get(self.ptr, 3) end
288
+ def w; @backend.gsl_vector_get(@ptr, 3) end
277
289
 
278
290
  # Same as Vector#[0]=
279
- def x=(v); GSLng.backend::gsl_vector_set(self.ptr, 0, v.to_f) end
291
+ def x=(v); @backend.gsl_vector_set(@ptr, 0, v.to_f) end
280
292
  # Same as Vector#[1]=
281
- def y=(v); GSLng.backend::gsl_vector_set(self.ptr, 1, v.to_f) end
293
+ def y=(v); @backend.gsl_vector_set(@ptr, 1, v.to_f) end
282
294
  # Same as Vector#[2]=
283
- def z=(v); GSLng.backend::gsl_vector_set(self.ptr, 2, v.to_f) end
295
+ def z=(v); @backend.gsl_vector_set(@ptr, 2, v.to_f) end
284
296
  # Same as Vector#[3]=
285
- def w=(v); GSLng.backend::gsl_vector_set(self.ptr, 3, v.to_f) end
297
+ def w=(v); @backend.gsl_vector_set(@ptr, 3, v.to_f) end
286
298
 
287
299
  # @group Predicate methods
288
300
 
289
301
  # if all elements are zero
290
- def zero?; GSLng.backend::gsl_vector_isnull(self.ptr) == 1 ? true : false end
302
+ def zero?; @backend.gsl_vector_isnull(@ptr) == 1 ? true : false end
291
303
 
292
304
  # if all elements are strictly positive (>0)
293
- def positive?; GSLng.backend::gsl_vector_ispos(self.ptr) == 1 ? true : false end
305
+ def positive?; @backend.gsl_vector_ispos(@ptr) == 1 ? true : false end
294
306
 
295
307
  #if all elements are strictly negative (<0)
296
- def negative?; GSLng.backend::gsl_vector_isneg(self.ptr) == 1 ? true : false end
308
+ def negative?; @backend.gsl_vector_isneg(@ptr) == 1 ? true : false end
297
309
 
298
310
  # if all elements are non-negative (>=0)
299
- def nonnegative?; GSLng.backend::gsl_vector_isnonneg(self.ptr) == 1 ? true : false end
311
+ def nonnegative?; @backend.gsl_vector_isnonneg(@ptr) == 1 ? true : false end
300
312
 
301
313
  # If each element of self is less than other's elements
302
314
  def <(other); (other - self).positive? end
@@ -313,16 +325,16 @@ module GSLng
313
325
  # @group Minimum/Maximum
314
326
 
315
327
  # Return maximum element of vector
316
- def max; GSLng.backend::gsl_vector_max(self.ptr) end
328
+ def max; @backend.gsl_vector_max(@ptr) end
317
329
 
318
330
  # Return minimum element of vector
319
- def min; GSLng.backend::gsl_vector_min(self.ptr) end
331
+ def min; @backend.gsl_vector_min(@ptr) end
320
332
 
321
333
  # Same as {Array#minmax}
322
334
  def minmax
323
335
  min = FFI::Buffer.new(:double)
324
336
  max = FFI::Buffer.new(:double)
325
- GSLng.backend::gsl_vector_minmax(self.ptr, min, max)
337
+ @backend.gsl_vector_minmax(@ptr, min, max)
326
338
  return [min[0].get_float64(0),max[0].get_float64(0)]
327
339
  end
328
340
 
@@ -330,108 +342,117 @@ module GSLng
330
342
  def minmax_index
331
343
  min = FFI::Buffer.new(:size_t)
332
344
  max = FFI::Buffer.new(:size_t)
333
- GSLng.backend::gsl_vector_minmax_index(self.ptr, min, max)
345
+ @backend.gsl_vector_minmax_index(@ptr, min, max)
334
346
  #return [min[0].get_size_t(0),max[0].get_size_t(0)]
335
347
  return [min[0].get_ulong(0),max[0].get_ulong(0)]
336
348
  end
337
349
 
338
350
  # Same as {#min}, but returns the index to the element
339
- def min_index; GSLng.backend::gsl_vector_min_index(self.ptr) end
351
+ def min_index; @backend.gsl_vector_min_index(@ptr) end
340
352
 
341
353
  # Same as {#max}, but returns the index to the element
342
- def max_index; GSLng.backend::gsl_vector_max_index(self.ptr) end
354
+ def max_index; @backend.gsl_vector_max_index(@ptr) end
343
355
 
344
356
  # @group Statistics
345
357
 
346
358
  # Compute the mean of the vector
347
- def mean; GSLng.backend.gsl_stats_mean(self.as_array, self.stride, self.size) end
359
+ def mean; @backend.gsl_stats_mean(self.as_array, self.stride, self.size) end
348
360
 
361
+ # Compute the median of the vector
362
+ # *Note* it assumes sorted data!
363
+ def median; @backend.gsl_stats_median_from_sorted_data(self.as_array, self.stride, self.size) end
364
+
365
+ # Compute the median of the vector
366
+ # *Note* it assumes sorted data!
367
+ # @param [Float] f A number between 0 and 1 indicating the percentile
368
+ def quantile(f); @backend.gsl_stats_quantile_from_sorted_data(self.as_array, self.stride, self.size, f) end
369
+
349
370
  # Compute the variance of the vector
350
371
  # @param [Float] mean Optionally supply the mean if you already computed it previously with {self#mean}
351
372
  # @param [Boolean] fixed_mean If true, the passed mean is taken to be known a priori (see GSL documentation)
352
373
  def variance(mean = nil, fixed_mean = false)
353
- if (mean.nil?) then GSLng.backend.gsl_stats_variance(self.as_array, self.stride, self.size)
374
+ if (mean.nil?) then @backend.gsl_stats_variance(self.as_array, self.stride, self.size)
354
375
  else
355
- if (fixed_mean) then GSLng.backend.gsl_stats_variance_with_fixed_mean(self.as_array, self.stride, self.size, mean)
356
- else GSLng.backend.gsl_stats_variance_m(self.as_array, self.stride, self.size, mean) end
376
+ if (fixed_mean) then @backend.gsl_stats_variance_with_fixed_mean(self.as_array, self.stride, self.size, mean)
377
+ else @backend.gsl_stats_variance_m(self.as_array, self.stride, self.size, mean) end
357
378
  end
358
379
  end
359
380
 
360
381
  # Compute the standard deviation of the vector
361
382
  # @see #variance
362
383
  def standard_deviation(mean = nil, fixed_mean = false)
363
- if (mean.nil?) then GSLng.backend.gsl_stats_sd(self.as_array, self.stride, self.size)
384
+ if (mean.nil?) then @backend.gsl_stats_sd(self.as_array, self.stride, self.size)
364
385
  else
365
- if (fixed_mean) then GSLng.backend.gsl_stats_sd_with_fixed_mean(self.as_array, self.stride, self.size, mean)
366
- else GSLng.backend.gsl_stats_sd_m(self.as_array, self.stride, self.size, mean) end
386
+ if (fixed_mean) then @backend.gsl_stats_sd_with_fixed_mean(self.as_array, self.stride, self.size, mean)
387
+ else @backend.gsl_stats_sd_m(self.as_array, self.stride, self.size, mean) end
367
388
  end
368
389
  end
369
390
 
370
391
  # Compute the total sum of squares of the vector
371
392
  # @see #variance
372
393
  def total_sum_squares(mean = nil)
373
- if (mean.nil?) then GSLng.backend.gsl_stats_tss(self.as_array, self.stride, self.size)
374
- else GSLng.backend.gsl_stats_tss_m(self.as_array, self.stride, self.size, mean) end
394
+ if (mean.nil?) then @backend.gsl_stats_tss(self.as_array, self.stride, self.size)
395
+ else @backend.gsl_stats_tss_m(self.as_array, self.stride, self.size, mean) end
375
396
  end
376
397
 
377
398
  # Compute the absolute deviation of the vector
378
399
  # @see #variance
379
400
  def absolute_deviation(mean = nil)
380
- if (mean.nil?) then GSLng.backend.gsl_stats_absdev(self.as_array, self.stride, self.size)
381
- else GSLng.backend.gsl_stats_absdev_m(self.as_array, self.stride, self.size, mean) end
401
+ if (mean.nil?) then @backend.gsl_stats_absdev(self.as_array, self.stride, self.size)
402
+ else @backend.gsl_stats_absdev_m(self.as_array, self.stride, self.size, mean) end
382
403
  end
383
404
 
384
- # Compute the skew of the vector. You can optionally provide the mean *and* the standard deviation if you already computed them
405
+ # Compute the skewness of the vector. You can optionally provide the mean *and* the standard deviation if you already computed them
385
406
  def skew(mean = nil, sd = nil)
386
- if (mean.nil? || sd.nil?) then GSLng.backend.gsl_stats_skew(self.as_array, self.stride, self.size)
387
- else GSLng.backend.gsl_stats_skew_sd_m(self.as_array, self.stride, self.size, mean, sd) end
407
+ if (mean.nil? || sd.nil?) then @backend.gsl_stats_skew(self.as_array, self.stride, self.size)
408
+ else @backend.gsl_stats_skew_sd_m(self.as_array, self.stride, self.size, mean, sd) end
388
409
  end
389
410
 
390
411
  # Compute the kurtosis of the vector
391
412
  # @see #skew
392
413
  def kurtosis(mean = nil, sd = nil)
393
- if (mean.nil? || sd.nil?) then GSLng.backend.gsl_stats_kurtosis(self.as_array, self.stride, self.size)
394
- else GSLng.backend.gsl_stats_kurtosis_sd_m(self.as_array, self.stride, self.size, mean, sd) end
414
+ if (mean.nil? || sd.nil?) then @backend.gsl_stats_kurtosis(self.as_array, self.stride, self.size)
415
+ else @backend.gsl_stats_kurtosis_sd_m(self.as_array, self.stride, self.size, mean, sd) end
395
416
  end
396
417
 
397
418
  # Compute the autocorrelation of the vector
398
419
  # @see #variance
399
420
  def autocorrelation(mean = nil)
400
- if (mean.nil?) then GSLng.backend.gsl_stats_lag1_autocorrelation(self.as_array, self.stride, self.size)
401
- else GSLng.backend.gsl_stats_lag1_autocorrelation(self.as_array, self.stride, self.size, mean) end
421
+ if (mean.nil?) then @backend.gsl_stats_lag1_autocorrelation(self.as_array, self.stride, self.size)
422
+ else @backend.gsl_stats_lag1_autocorrelation(self.as_array, self.stride, self.size, mean) end
402
423
  end
403
424
 
404
425
  # Compute the covariance between self and other. You can optionally pass the mean of both vectors if you already computed them
405
426
  # @see #variance
406
427
  def covariance(other, mean1 = nil, mean2 = nil)
407
- if (mean1.nil? || mean2.nil?) then GSLng.backend.gsl_stats_covariance(self.as_array, self.stride, other.as_array, other.stride, self.size)
408
- else GSLng.backend.gsl_stats_covariance(self.as_array, self.stride, other.as_array, other.stride, self.size, mean1, mean2) end
428
+ if (mean1.nil? || mean2.nil?) then @backend.gsl_stats_covariance(self.as_array, self.stride, other.as_array, other.stride, self.size)
429
+ else @backend.gsl_stats_covariance(self.as_array, self.stride, other.as_array, other.stride, self.size, mean1, mean2) end
409
430
  end
410
431
 
411
432
  # Compute the correlation between self and other
412
433
  def correlation(other)
413
- GSLng.backend.gsl_stats_correlation(self.as_array, self.stride, other.as_array, other.stride, self.size)
434
+ @backend.gsl_stats_correlation(self.as_array, self.stride, other.as_array, other.stride, self.size)
414
435
  end
415
436
 
416
437
  # @group High-order methods
417
438
 
418
439
  # @yield [elem]
419
440
  def each(block = Proc.new)
420
- GSLng.backend::gsl_vector_each(self.ptr.to_i, &block)
441
+ @backend.gsl_vector_each(@ptr_value, &block)
421
442
  end
422
443
 
423
444
  # @see #each
424
445
  # @yield [elem,i]
425
446
  def each_with_index(block = Proc.new)
426
- GSLng.backend::gsl_vector_each_with_index(self.ptr.to_i, &block)
447
+ @backend.gsl_vector_each_with_index(@ptr_value, &block)
427
448
  end
428
449
 
429
450
  # @see #map
430
- def map!(block = Proc.new); GSLng.backend::gsl_vector_map!(self.ptr.to_i, &block); return self end
451
+ def map!(block = Proc.new); @backend.gsl_vector_map!(@ptr_value, &block); return self end
431
452
 
432
453
  # Similar to {#map!}, but passes the index to the element instead.
433
454
  # @yield [i]
434
- def map_index!(block = Proc.new); GSLng.backend::gsl_vector_map_index!(self.ptr.to_i, &block); return self end
455
+ def map_index!(block = Proc.new); @backend.gsl_vector_map_index!(@ptr_value, &block); return self end
435
456
 
436
457
  # @return [Vector]
437
458
  # @see #map_index!
@@ -489,18 +510,18 @@ module GSLng
489
510
 
490
511
  # @return [Array]
491
512
  def to_a
492
- GSLng.backend.gsl_vector_to_a(self.ptr.to_i)
513
+ @backend.gsl_vector_to_a(@ptr_value)
493
514
  end
494
515
 
495
516
  def as_array # @private
496
- GSLng.backend.gsl_vector_as_array(self.ptr)
517
+ @backend.gsl_vector_as_array(@ptr)
497
518
  end
498
519
 
499
520
  # Create a row matrix from this vector
500
521
  # @return [Matrix]
501
522
  def to_matrix
502
523
  m = Matrix.new(1, @size)
503
- GSLng.backend::gsl_matrix_set_row(m.ptr, 0, self.ptr)
524
+ @backend.gsl_matrix_set_row(m.ptr, 0, @ptr)
504
525
  return m
505
526
  end
506
527
  alias_method :to_row, :to_matrix
@@ -509,7 +530,7 @@ module GSLng
509
530
  # @return [Matrix]
510
531
  def transpose
511
532
  m = Matrix.new(@size, 1)
512
- GSLng.backend::gsl_matrix_set_col(m.ptr, 0, self.ptr)
533
+ @backend.gsl_matrix_set_col(m.ptr, 0, @ptr)
513
534
  return m
514
535
  end
515
536
  alias_method :to_column, :transpose
@@ -524,5 +545,9 @@ module GSLng
524
545
  end
525
546
  return true
526
547
  end
548
+
549
+ def eql?(other)
550
+ @backend.gsl_vector_eql?(@ptr_value, other.ptr_value)
551
+ end
527
552
  end
528
553
  end