Class: MDS::LinalgInterface

Inherits:
MatrixInterface show all
Defined in:
lib/mds/interfaces/linalg_interface.rb

Overview

Common matrix interface for Linalg - Ruby Bindings for LAPACK.

To succesfully use this interface ‘Linalg’ bindings for LAPCK/BLAS are required. For more information and installation instructions see rubyforge.org/projects/linalg/

Compatible with ‘Linalg >= 1.0.0’

Class Method Summary collapse

Methods inherited from MatrixInterface

columns, create_block, create_diagonal, create_identity, create_random, create_rows, diagonals, inherited, rows, #to_s, trace

Class Method Details

.add(m, n) ⇒ Object

Componentwise addition of two matrices.



106
107
108
# File 'lib/mds/interfaces/linalg_interface.rb', line 106

def LinalgInterface.add(m, n)
  m + n
end

.create(n, m, s) ⇒ Object

Create a new matrix with equal elements.



36
37
38
# File 'lib/mds/interfaces/linalg_interface.rb', line 36

def LinalgInterface.create(n, m, s)
  ::Linalg::DMatrix.new(n, m, s)
end

.ed(m) ⇒ Object

Compute the eigen-decomposition of a real symmetric matrix.



126
127
128
129
# File 'lib/mds/interfaces/linalg_interface.rb', line 126

def LinalgInterface.ed(m)
  evecs, real, img = m.eigensystem         
  [Linalg::DMatrix.diagonal(real), evecs]
end

.get(m, i, j) ⇒ Object

Get matrix element.



75
76
77
# File 'lib/mds/interfaces/linalg_interface.rb', line 75

def LinalgInterface.get(m, i, j)
  m[i,j]
end

.minor(m, row_range, col_range) ⇒ Object

Calculate minor matrix.



142
143
144
145
146
# File 'lib/mds/interfaces/linalg_interface.rb', line 142

def LinalgInterface.minor(m, row_range, col_range)
  nrows = (row_range.last - row_range.first) + 1
  ncols = (col_range.last - col_range.first) + 1
  m.minor(row_range.first, col_range.first, nrows, ncols)
end

.ncols(m) ⇒ Object

Return the number of matrix columns



56
57
58
# File 'lib/mds/interfaces/linalg_interface.rb', line 56

def LinalgInterface.ncols(m)
  m.num_columns
end

.nrows(m) ⇒ Object

Return the number of matrix rows



46
47
48
# File 'lib/mds/interfaces/linalg_interface.rb', line 46

def LinalgInterface.nrows(m)
  m.num_rows
end

.prod(m, n) ⇒ Object

Calculate the product of two matrices or the product of a matrix and a scalar.



86
87
88
# File 'lib/mds/interfaces/linalg_interface.rb', line 86

def LinalgInterface.prod(m, n)
  m * n
end

.set(m, i, j, s) ⇒ Object

Set matrix element.



65
66
67
# File 'lib/mds/interfaces/linalg_interface.rb', line 65

def LinalgInterface.set(m, i, j, s)
  m[i,j] = s
end

.sub(m, n) ⇒ Object

Componentwise subtraction of two matrices.



116
117
118
# File 'lib/mds/interfaces/linalg_interface.rb', line 116

def LinalgInterface.sub(m, n)
  m - n
end

.t(m) ⇒ Object

Transpose a matrix.



96
97
98
# File 'lib/mds/interfaces/linalg_interface.rb', line 96

def LinalgInterface.t(m)
  m.transpose
end