Class: Eigen::MatrixX
- Inherits:
-
Object
- Object
- Eigen::MatrixX
- Defined in:
- lib/eigen/matrixx.rb,
ext/eigen/eigen.cpp
Overview
A variable-size matrix holding floating-point numbers
Class Method Summary collapse
Instance Method Summary collapse
-
#*(v) ⇒ MatrixX
Multiplies by a scalar.
-
#+(m) ⇒ MatrixX
Sums two matrices.
-
#-(m) ⇒ MatrixX
Subtracts two matrices.
-
#-@(v) ⇒ MatrixX
Returns this matrix’ negation.
-
#/(v) ⇒ MatrixX
Divides this matrix by a scalar.
- #==(m) ⇒ Object
-
#[](row, col) ⇒ Numeric
Accesses an element.
-
#[]=(row, col, value) ⇒ Numeric
Sets an element.
-
#_dump(level) ⇒ Object
:nodoc:.
-
#approx?(m, threshold = dummy_precision) ⇒ Boolean
Verifies that two matrices are within threshold of each other, elementwise.
-
#cols ⇒ Numeric
The number of columns.
-
#dotM(m) ⇒ Numeric
Matrix multiplication.
-
#dotV(m) ⇒ Numeric
Matrix/vector multiplication.
- #dup ⇒ Object
-
#from_a(array, nrows = -1,, ncols = -1,, column_major = true) ⇒ Object
sets matrix from a 1d array.
-
#jacobiSvd(flags = 0) ⇒ JacobiSVD
Returns a SVD solver to find V from W in self.dotV(V) = W.
-
#norm ⇒ Numeric
Returns the matrix’ norm.
- #pretty_print(pp) ⇒ Object
-
#resize(rows, cols) ⇒ Object
Resizes the matrix.
-
#rows ⇒ Integer
The number of rows.
-
#setColumn(column, vector) ⇒ Object
Sets a whole matrix column.
-
#setRow(row, vector) ⇒ Object
Sets a whole matrix row.
-
#size ⇒ Numeric
The number of elements.
-
#T ⇒ MatrixX
Returns the transposed matrix.
-
#to_a(column_major = true) ⇒ Object
Returns the array value in a vector.
-
#to_s ⇒ Object
:nodoc:.
Class Method Details
._load(coordinates) ⇒ Object
:nodoc:
97 98 99 100 101 102 |
# File 'lib/eigen/matrixx.rb', line 97 def self._load(coordinates) # :nodoc: o = Marshal.load(coordinates) m = new(o['rows'],o['cols']) m.from_a(o['data'],o['rows'],o['cols']) m end |
.from_a(*args) ⇒ Object
18 19 20 21 22 |
# File 'lib/eigen/matrixx.rb', line 18 def self.from_a(*args) m = new m.from_a(*args) m end |
.Zero(rows, cols) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/eigen/matrixx.rb', line 8 def self.Zero(rows, cols) m = new(rows, cols) rows.times do |r| cols.times do |c| m[r, c] = 0 end end m end |
Instance Method Details
#*(v) ⇒ MatrixX
Multiplies by a scalar
#+(m) ⇒ MatrixX
Sums two matrices
#-(m) ⇒ MatrixX
Subtracts two matrices
#-@(v) ⇒ MatrixX
Returns this matrix’ negation
#/(v) ⇒ MatrixX
Divides this matrix by a scalar
#==(m) ⇒ Object
76 77 78 79 |
# File 'lib/eigen/matrixx.rb', line 76 def ==(m) m.kind_of?(self.class) && __equal__(m) end |
#[](row, col) ⇒ Numeric
Accesses an element
#[]=(row, col, value) ⇒ Numeric
Sets an element
#_dump(level) ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/eigen/matrixx.rb', line 93 def _dump(level) # :nodoc: Marshal.dump({'rows' => rows, 'cols' => cols, 'data' => to_a}) end |
#approx?(m, threshold = dummy_precision) ⇒ Boolean
Verifies that two matrices are within threshold of each other, elementwise
#cols ⇒ Numeric
Returns the number of columns.
#dotM(m) ⇒ Numeric
Matrix multiplication
#dotV(m) ⇒ Numeric
Matrix/vector multiplication
#dup ⇒ Object
4 5 6 |
# File 'lib/eigen/matrixx.rb', line 4 def dup MatrixX.from_a(to_a, rows, cols) end |
#from_a(array, nrows = -1,, ncols = -1,, column_major = true) ⇒ Object
sets matrix from a 1d array
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/eigen/matrixx.rb', line 44 def from_a(array,nrows=-1,ncols=-1,column_major=true) if nrows == -1 && ncols == -1 nrows = rows ncols = cols elsif nrows == -1 nrows = array.size / ncols elsif ncols == -1 ncols = array.size / nrows end resize(nrows,ncols) array.each_index do |i| v = array[i] if !v v = 0.0 end if column_major self[i%nrows,i/nrows] = v else self[i/ncols,i%ncols] = v end end end |
#jacobiSvd(flags = 0) ⇒ JacobiSVD
Returns a SVD solver to find V from W in self.dotV(V) = W
#norm ⇒ Numeric
Returns the matrix’ norm
#pretty_print(pp) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/eigen/matrixx.rb', line 67 def pretty_print(pp) for i in 0..rows()-1 for j in 0..cols()-1 pp.text " #{self[i,j]}" end pp.text "\n" end end |
#resize(rows, cols) ⇒ Object
Resizes the matrix
#rows ⇒ Integer
Returns the number of rows.
#setColumn(column, vector) ⇒ Object
Sets a whole matrix column
#setRow(row, vector) ⇒ Object
Sets a whole matrix row
#size ⇒ Numeric
Returns the number of elements.
#T ⇒ MatrixX
Returns the transposed matrix
#to_a(column_major = true) ⇒ Object
Returns the array value in a vector
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/eigen/matrixx.rb', line 25 def to_a(column_major=true) a = [] if column_major for j in 0..cols()-1 for i in 0..rows()-1 a << self[i,j] end end else for i in 0..rows()-1 for j in 0..cols()-1 a << self[i,j] end end end a end |
#to_s ⇒ Object
:nodoc:
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/eigen/matrixx.rb', line 81 def to_s # :nodoc: str = "MatrixX(\n" for i in 0..rows()-1 for j in 0..cols()-1 str += "#{self[i,j]} " end str[-1] = "\n" end str += ")" str end |