Class: GSLng::Vector::View
- Inherits:
-
GSLng::Vector
- Object
- GSLng::Vector
- GSLng::Vector::View
- 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
-
#owner ⇒ Vector, Matrix
readonly
The owner of the data this view accesses.
Attributes inherited from GSLng::Vector
#ptr, #ptr_value, #size, #stride
Class Method Summary collapse
Instance Method Summary collapse
-
#dup ⇒ Vector
(also: #clone, #to_vector)
Returns a Vector (NOT a View) copied from this view.
-
#initialize(ptr, owner, size, stride = 1) ⇒ View
constructor
A new instance of View.
- #inspect ⇒ Object
- #view ⇒ Object
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
Class Method Details
Instance Method Details
#dup ⇒ Vector 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
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 |
#inspect ⇒ Object
39 40 41 |
# File 'lib/gslng/vector_view.rb', line 39 def inspect # @private "#{self}:VectorView" end |
#view ⇒ Object
35 36 37 |
# File 'lib/gslng/vector_view.rb', line 35 def view # @private raise "Can't create a View from a View" end |