Class: MDS::GSLInterface

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

Overview

Matrix interface for the Gnu Scientific Library.

To succesfully use this interface ‘rbgsl’ bindings for GSL are required. For more information and installation instructions see rb-gsl.rubyforge.org/

Compatible with ‘rb-gsl >= 1.14.3’

Class Method Summary collapse

Methods inherited from MatrixInterface

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

Class Method Details

.add(m, n) ⇒ Object

Componentwise addition of two matrices.



108
109
110
# File 'lib/mds/interfaces/gsl_interface.rb', line 108

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

.create(n, m, s) ⇒ Object

Create a new matrix with equal elements.



36
37
38
39
40
# File 'lib/mds/interfaces/gsl_interface.rb', line 36

def GSLInterface.create(n, m, s)
  mat = ::GSL::Matrix.alloc(n, m)
  mat.set_all(s)
  mat
end

.ed(m) ⇒ Object

Compute the eigen-decomposition of a real symmetric matrix.



128
129
130
131
132
133
134
135
136
137
# File 'lib/mds/interfaces/gsl_interface.rb', line 128

def GSLInterface.ed(m)
  eigen_values, eigen_vectors = ::GSL::Eigen::symmv(m)
  ::GSL::Eigen::Symmv::sort(
    eigen_values, 
    eigen_vectors, 
    ::GSL::Eigen::SORT_VAL_DESC
  )
  
  [eigen_values.to_m_diagonal, eigen_vectors]
end

.get(m, i, j) ⇒ Object

Get matrix element.



77
78
79
# File 'lib/mds/interfaces/gsl_interface.rb', line 77

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

.ncols(m) ⇒ Object

Return the number of matrix columns



58
59
60
# File 'lib/mds/interfaces/gsl_interface.rb', line 58

def GSLInterface.ncols(m)
  m.size2
end

.nrows(m) ⇒ Object

Return the number of matrix rows



48
49
50
# File 'lib/mds/interfaces/gsl_interface.rb', line 48

def GSLInterface.nrows(m)
  m.size1
end

.prod(m, n) ⇒ Object

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



88
89
90
# File 'lib/mds/interfaces/gsl_interface.rb', line 88

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

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

Set matrix element.



67
68
69
# File 'lib/mds/interfaces/gsl_interface.rb', line 67

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

.sub(m, n) ⇒ Object

Componentwise subtraction of two matrices.



118
119
120
# File 'lib/mds/interfaces/gsl_interface.rb', line 118

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

.t(m) ⇒ Object

Transpose a matrix.



98
99
100
# File 'lib/mds/interfaces/gsl_interface.rb', line 98

def GSLInterface.t(m)
  m.transpose
end