Class: GSLng::Matrix::View

Inherits:
GSLng::Matrix show all
Defined in:
lib/gslng/matrix_view.rb

Overview

A View of a Matrix.

Views reference an existing Matrix and can be used to access parts of it without having to copy it entirely. You can treat a View just like a Matrix. But note that modifying elements of a View will modify the elements of the original matrix.

Instance Attribute Summary collapse

Attributes inherited from GSLng::Matrix

#m, #n, #ptr, #ptr_value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GSLng::Matrix

#*, #+, #-, #/, #==, #[], [], #[]=, #^, #add!, #all!, #coerce, #column, #column?, #column_vecview, #column_view, #define_plot, #divide!, #each, #each_column, #each_row, #each_vec_column, #each_vec_row, #each_with_index, from_array, #identity, #initialize_copy, #join, #map, #map!, #map_array, #map_index!, #map_with_index!, #max, #max_index, #min, #min_index, #minmax, #minmax_index, #multiply!, #negative?, #nonnegative?, #plot, #positive?, random, #row, #row_vecview, #row_view, #set, #size, #slide, #submatrix, #substract!, #swap_columns, #swap_rowcol, #swap_rows, #to_a, #to_s, #transpose, #transpose!, zero, #zero!, #zero?

Constructor Details

#initialize(owner, x, y, m, n) ⇒ View

Create a Matrix::View of the sub-matrix starting at (x,y), of size (m,n)


13
14
15
16
17
18
19
20
21
22
# File 'lib/gslng/matrix_view.rb', line 13

def initialize(owner, x, y, m, n) # @private
  @owner = owner
  @m,@n = m,n

  @backend = GSLng.backend
  ptr = GSLng.backend::gsl_matrix_submatrix2(owner.ptr, x, y, m, n)
  @view_ptr = FFI::AutoPointer.new(ptr, View.method(:release))
  @ptr = GSLng.backend::gsl_matrix_view_get_matrix(@view_ptr)
  @ptr_value = @ptr.to_i
end

Instance Attribute Details

#ownerObject (readonly)

The Matrix owning the data this View uses


10
11
12
# File 'lib/gslng/matrix_view.rb', line 10

def owner
  @owner
end

Class Method Details

.release(ptr) ⇒ Object


24
25
26
# File 'lib/gslng/matrix_view.rb', line 24

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

Instance Method Details

#dupMatrix Also known as: clone, to_matrix

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

Returns:


31
32
33
34
35
# File 'lib/gslng/matrix_view.rb', line 31

def dup
  matrix = Matrix.new(@m, @n)
  GSLng.backend::gsl_matrix_memcpy(matrix.ptr, @ptr)
  return matrix
end

#inspectObject


43
44
45
# File 'lib/gslng/matrix_view.rb', line 43

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

#viewObject


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

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