Class: Octave::Matrix
- Inherits:
-
Object
- Object
- Octave::Matrix
- Includes:
- Comparable
- Defined in:
- lib/octave/matrix.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#m ⇒ Object
readonly
Rows.
-
#n ⇒ Object
readonly
Columns.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Enables comparisons of matrices to each other.
-
#[](m, n) ⇒ Object
Gets the value at the given row and column position.
-
#[]=(m, n, value) ⇒ Object
Sets the given value at the row and column position.
-
#initialize(m, n) ⇒ Matrix
constructor
Creates a new Matrix with the given dimensions for row and column size.
-
#to_a ⇒ Object
Returns flattened cells.
Constructor Details
#initialize(m, n) ⇒ Matrix
Creates a new Matrix with the given dimensions for row and column size
20 21 22 23 |
# File 'lib/octave/matrix.rb', line 20 def initialize(m, n) @m, @n = m, n @cells = Array.new(m) { Array.new(n) } end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
17 18 19 |
# File 'lib/octave/matrix.rb', line 17 def cells @cells end |
#m ⇒ Object (readonly)
Rows
15 16 17 |
# File 'lib/octave/matrix.rb', line 15 def m @m end |
#n ⇒ Object (readonly)
Columns
16 17 18 |
# File 'lib/octave/matrix.rb', line 16 def n @n end |
Instance Method Details
#==(other) ⇒ Object
Enables comparisons of matrices to each other
36 37 38 |
# File 'lib/octave/matrix.rb', line 36 def ==(other) @cells == other.cells end |
#[](m, n) ⇒ Object
Gets the value at the given row and column position
26 27 28 |
# File 'lib/octave/matrix.rb', line 26 def [](m, n) @cells[m][n] end |
#[]=(m, n, value) ⇒ Object
Sets the given value at the row and column position
31 32 33 |
# File 'lib/octave/matrix.rb', line 31 def []=(m, n, value) @cells[m][n] = value end |
#to_a ⇒ Object
Returns flattened cells
41 42 43 |
# File 'lib/octave/matrix.rb', line 41 def to_a @cells.flatten end |