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.

Note also that Views are not meant to be created explicitly, but through methods of the Vector/Matrix classes

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

#*, #+, #-, #[email protected], #/, #<, #<=, #==, #>, #>=, #[], [], #[]=, #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(owner, view_ptr, size, stride) ⇒ View

Returns a new instance of View.


15
16
17
18
19
20
21
# File 'lib/gslng/vector_view.rb', line 15

def initialize(owner, view_ptr, size, stride)
  @backend = GSLng.backend
  @owner,@size,@stride = owner,size,stride
  @view_ptr = FFI::AutoPointer.new(view_ptr, View.method(:release))
  @ptr = GSLng.backend.gsl_vector_view_get_vector(@view_ptr)
  @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


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

def owner
  @owner
end

Class Method Details

.release(ptr) ⇒ Object


23
24
25
# File 'lib/gslng/vector_view.rb', line 23

def View.release(ptr)
  GSLng.backend.gsl_vector_view_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:


30
31
32
33
34
# File 'lib/gslng/vector_view.rb', line 30

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

#inspectObject


42
43
44
# File 'lib/gslng/vector_view.rb', line 42

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

#viewObject


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

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