lib/csrmatrix/functions.rb in csrmatrix-1.0.0 vs lib/csrmatrix/functions.rb in csrmatrix-1.0.1

- old
+ new

@@ -1,33 +1,69 @@ module CsrMatrix module Functions - + include Contracts::Core + include Contracts::Builtin + C = Contracts + + def self.included(exceptions) + exceptions.send :include, Exceptions + end + + Contract C::None => C::Num 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) - m.det() - end + return m.det() + end # determinant + Contract C::None => C::Num def det() - self.determinant() - end + # alias for determinant + # identifies the determinant of a matrix + is_invariant? + return self.determinant() + end # det + Contract C::None => C::Num def rank() + # identifies the rank of a matrix + is_invariant? m = Matrix.rows(self.decompose) - m.rank() - end + return m.rank() + end # rank + #FIXME: I'm not sure whats going on here? def round(ndig = 0) - m = Matrix.rows(self.decompose) - self.build_from_array(m.round(ndig).to_a()) - end + # 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 # round + Contract C::None => Contracts::Num def trace() + # identifies the trace of the matrix + is_invariant? m = Matrix.rows(self.decompose) - m.trace() - end + return m.trace() + end # trace + Contract C::None => Contracts::Num def tr() - self.trace() - end + # alias for trace + # identifies the trace of the matrix + is_invariant? + return self.trace() + end # tr - end -end \ No newline at end of file + end # Functions +end # CsrMatrix