Class: GSLng::Vector::View

Inherits:
GSLng::Vector show all
Defined in:
lib/gslng/vector_view.rb

Overview

A View of a Vector.

Views reference an existing Vector (or a row/column from a Matrix) and can be used to access parts of it without having to copy it entirely. You can treat a View just like a Vector. But note that modifying elements of a View will modify the elements of the original Vector/Matrix.

Instance Attribute Summary collapse

Attributes inherited from GSLng::Vector

#ptr, #ptr_value, #size, #stride

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GSLng::Vector

#*, #+, #-, #-@, #/, #<, #<=, #==, #>, #>=, #[], [], #[]=, #absolute_deviation, #add!, #all!, #as_array, #autocorrelation, #basis!, #coerce, #copy, #correlation, #covariance, #divide!, #dot, #each, #each_with_index, #eql?, from_array, #hash, #initialize_copy, #join, #kurtosis, linspace, #map, #map!, #map_array, #map_index, #map_index!, #map_old, #max, #max_index, #mean, #median, #min, #min_index, #minmax, #minmax_index, #mul_add, #multiply!, #negative?, #nonnegative?, #norm, #positive?, #quantile, random, #reverse!, #skew, #sort, #sort!, #standard_deviation, #substract!, #subvector, #sum, #swap, #to_a, #to_matrix, #to_s, #total_sum_squares, #transpose, #variance, #w, #w=, #wrap!, #x, #x=, #y, #y=, #z, #z=, zero, #zero!, #zero?

Constructor Details

#initialize(ptr, owner, size, stride = 1) ⇒ View

Returns a new instance of View.



13
14
15
16
17
18
# File 'lib/gslng/vector_view.rb', line 13

def initialize(ptr, owner, size, stride = 1) # @private
  @backend = GSLng.backend
  @owner,@size,@stride = owner,size,stride
  @ptr = FFI::AutoPointer.new(ptr, View.method(:release))
  @ptr_value = @ptr.to_i
end

Instance Attribute Details

#ownerVector, Matrix (readonly)

Returns The owner of the data this view accesses.

Returns:

  • (Vector, Matrix)

    The owner of the data this view accesses



11
12
13
# File 'lib/gslng/vector_view.rb', line 11

def owner
  @owner
end

Class Method Details

.release(ptr) ⇒ Object



20
21
22
# File 'lib/gslng/vector_view.rb', line 20

def View.release(ptr)
  GSLng.backend.gsl_vector_free(ptr)
end

Instance Method Details

#dupVector Also known as: clone, to_vector

Returns a Vector (NOT a View) copied from this view. In other words, you’ll get a Vector which you can modify without modifying #owner‘s elements

Returns:



27
28
29
30
31
# File 'lib/gslng/vector_view.rb', line 27

def dup
  v = Vector.new(@size)
  @backend.gsl_vector_memcpy(v.ptr, @ptr)
  return v
end

#inspectObject



39
40
41
# File 'lib/gslng/vector_view.rb', line 39

def inspect # @private
  "#{self}:VectorView"
end

#viewObject



35
36
37
# File 'lib/gslng/vector_view.rb', line 35

def view # @private
  raise "Can't create a View from a View"
end