Sha256: bed9aaed0c8112577065785b4a7940434ef3c14149e66316995b2ebb61e5ea1a

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

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)
            return m.det()
        end # determinant

        Contract C::None => C::Num
        def det()
            # 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)
            return m.rank()
        end # rank

        #FIXME: I'm not sure whats going on here?
        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 # round

        Contract C::None => Contracts::Num
        def trace()
            # identifies the trace of the matrix
            is_invariant?
            m = Matrix.rows(self.decompose)
            return m.trace()
        end # trace

        Contract C::None => Contracts::Num
        def tr()
            # alias for trace
            # identifies the trace of the matrix
            is_invariant?
            return self.trace()
        end # tr

    end # Functions
end # CsrMatrix

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csrmatrix-1.0.1 lib/csrmatrix/functions.rb