Module: CsrMatrix::Functions
- Includes:
- Contracts::Builtin, Contracts::Core
- Included in:
- TwoDMatrix
- Defined in:
- lib/csrmatrix/functions.rb
Constant Summary collapse
- C =
Contracts
Class Method Summary collapse
Instance Method Summary collapse
- #det ⇒ Object
- #determinant ⇒ Object
- #rank ⇒ Object
-
#round(ndig = 0) ⇒ Object
FIXME: I’m not sure whats going on here?.
- #tr ⇒ Object
- #trace ⇒ Object
Class Method Details
.included(exceptions) ⇒ Object
7 8 9 |
# File 'lib/csrmatrix/functions.rb', line 7 def self.included(exceptions) exceptions.send :include, Exceptions end |
Instance Method Details
#det ⇒ Object
25 26 27 28 29 30 |
# File 'lib/csrmatrix/functions.rb', line 25 def det() # alias for determinant # identifies the determinant of a matrix is_invariant? return self.determinant() end |
#determinant ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/csrmatrix/functions.rb', line 12 def determinant() # identifies the determinant of a matrix is_invariant? if !self.square?() raise Exceptions::MatrixDimException.new, "Matrix is not square." return false end m = Matrix.rows(self.decompose) return m.det() end |
#rank ⇒ Object
33 34 35 36 37 38 |
# File 'lib/csrmatrix/functions.rb', line 33 def rank() # identifies the rank of a matrix is_invariant? m = Matrix.rows(self.decompose) return m.rank() end |
#round(ndig = 0) ⇒ Object
FIXME: I’m not sure whats going on here?
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/csrmatrix/functions.rb', line 41 def round(ndig = 0) # identifies the round of a matrix (that is, each value rounded by a specific degree) # pre integer of degree, existing matrix (matrix.not_null?) is_invariant? # post rounded array for i in 0..self.val.count-1 self.val[i] = self.val[i].round(ndig) end self.val end |
#tr ⇒ Object
69 70 71 72 73 74 |
# File 'lib/csrmatrix/functions.rb', line 69 def tr() # alias for trace # identifies the trace of the matrix is_invariant? return self.trace() end |
#trace ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/csrmatrix/functions.rb', line 53 def trace() # identifies the trace of the matrix is_invariant? sum = 0 for i in 0..self.columns-1 for j in self.row_ptr[i]..self.row_ptr[i+1]-1 if self.col_ind[j] == i sum += self.val[j] break end end end return sum end |