Class: GSLng::Matrix::View
- Inherits:
-
GSLng::Matrix
- Object
- GSLng::Matrix
- GSLng::Matrix::View
- 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
-
#owner ⇒ Object
readonly
The Matrix owning the data this View uses.
Attributes inherited from GSLng::Matrix
#m, #n, #ptr, #ptr_value
Class Method Summary collapse
Instance Method Summary collapse
-
#dup ⇒ Matrix
(also: #clone, #to_matrix)
Returns a Matrix (NOT a View) copied from this view.
-
#initialize(owner, x, y, m, n) ⇒ View
constructor
Create a Matrix::View of the sub-matrix starting at (x,y), of size (m,n).
- #inspect ⇒ Object
- #view ⇒ Object
Methods inherited from GSLng::Matrix
#*, #+, #-, #/, #==, [], #[], #[]=, #^, #add!, #all!, #coerce, #column, #column?, #column_vecview, #column_view, #data_ptr, #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 |
# 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) @ptr = FFI::AutoPointer.new(ptr, View.method(:release)) @ptr_value = @ptr.to_i end |
Instance Attribute Details
#owner ⇒ Object (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
Instance Method Details
#dup ⇒ Matrix 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.
30 31 32 33 34 |
# File 'lib/gslng/matrix_view.rb', line 30 def dup matrix = Matrix.new(@m, @n) GSLng.backend::gsl_matrix_memcpy(matrix.ptr, @ptr) return matrix end |
#inspect ⇒ Object
42 43 44 |
# File 'lib/gslng/matrix_view.rb', line 42 def inspect # @private "#{self}:MatrixView" end |
#view ⇒ Object
38 39 40 |
# File 'lib/gslng/matrix_view.rb', line 38 def view # @private raise "Can't create a View from a View" end |