Module: CsrMatrix::Properties
Constant Summary collapse
- C =
Contracts
Class Method Summary collapse
Instance Method Summary collapse
- #diagonal? ⇒ Boolean
- #empty? ⇒ Boolean
- #lower_triangular? ⇒ Boolean
- #nonsingular? ⇒ Boolean
- #normal? ⇒ Boolean
- #not_null? ⇒ Boolean
- #orthogonal? ⇒ Boolean
- #permutation? ⇒ Boolean
- #real? ⇒ Boolean
- #singular? ⇒ Boolean
- #symmetric? ⇒ Boolean
- #unitary? ⇒ Boolean
- #upper_triangular? ⇒ Boolean
- #zero? ⇒ Boolean
Class Method Details
.included(exceptions) ⇒ Object
10 11 12 |
# File 'lib/csrmatrix/properties.rb', line 10 def self.included(exceptions) exceptions.send :include, Exceptions end |
Instance Method Details
#diagonal? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/csrmatrix/properties.rb', line 15 def diagonal? # Determines if the matrix is diagonal; wherein the values outside the main diagonal are all zero. is_invariant? for i in 0..self.columns-1 if (self.col_ind[i] != i) || (self.row_ptr[i] != i) return false end end return true end |
#empty? ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/csrmatrix/properties.rb', line 27 def empty? # Determines if the matrix is empty; wherein all the values are zero. is_invariant? if self.val.count() == 0 return true end return false end |
#lower_triangular? ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/csrmatrix/properties.rb', line 37 def lower_triangular? # Determines if the matrix is lower-diagonal; wherein all the values only exist on and below the diagonal line. is_invariant? for i in 0..self.columns-1 for column_index in row_ptr[i]..row_ptr[i+1]-1 if (self.col_ind[column_index] > i) return false end end end return true end |
#nonsingular? ⇒ Boolean
143 144 145 146 147 |
# File 'lib/csrmatrix/properties.rb', line 143 def nonsingular? # Determines if the matrix is nonsingular ; simply the inverse of the singular function is_invariant? return !self.singular? end |
#normal? ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/csrmatrix/properties.rb', line 52 def normal? # Determines if the matrix is normal is_invariant? if !self.square? raise Exceptions::MatrixDimException.new, "Matrix is not square." return false end m = Matrix.rows(self.decompose) return m.normal? end |
#not_null? ⇒ Boolean
135 136 137 138 139 140 |
# File 'lib/csrmatrix/properties.rb', line 135 def not_null? if @val == nil return false end return true end |
#orthogonal? ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/csrmatrix/properties.rb', line 65 def orthogonal? # Determines if the matrix is orthogonal; wherein the rows and columns are orthogonal unit vectors. is_invariant? if !self.square? raise Exceptions::MatrixDimException.new, "Matrix is not square." return false end # transpose the existing matrix @matrix_transpose = TwoDMatrix.new @matrix_transpose.build_from_csr(self.row_ptr, self.col_ind, self.val, self.columns, self.rows) @matrix_transpose.transpose() # build an orthogonal matrix @matrix_orthogonal = TwoDMatrix.new @matrix_orthogonal.build_from_array(self.multiply_csr(@matrix_transpose)) # test the values in the orthogonal matrix for i in 0..@matrix_orthogonal.val.count()-1 if @matrix_orthogonal.val[i] != 1 return false end end return true end |
#permutation? ⇒ Boolean
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/csrmatrix/properties.rb', line 92 def permutation? # Determines if the matrix is a permutation; wherein it is an nxn version of the identity matrix. is_invariant? if !self.square? raise Exceptions::MatrixDimException.new, "Matrix is not square." return false end #Check the proper number of values if self.val.length != self.columns return false end #check for the proper values. ie only 1's for value in self.val if value != 1 return false end end column_ind = self.col_ind for column_index in self.col_ind if column_ind.include?(column_index) column_ind.remove(column_index) else return false end end end |
#real? ⇒ Boolean
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/csrmatrix/properties.rb', line 123 def real? # Determines if the matrix is real; wherein the matrix consists entirely of real numbers. is_invariant? for value in self.val if !value.is_a? Numeric return false end end return true end |
#singular? ⇒ Boolean
150 151 152 153 154 155 156 157 |
# File 'lib/csrmatrix/properties.rb', line 150 def singular? # Determines if the matrix is singular is_invariant? if self.determinant != 0 return false end return true end |
#symmetric? ⇒ Boolean
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/csrmatrix/properties.rb', line 160 def symmetric? # Determines if the matrix is symmetric is_invariant? if !self.square? raise Exceptions::MatrixDimException.new, "Matrix is not square." return false end # transpose the existing matrix @matrix_transpose = TwoDMatrix.new @matrix_transpose.build_from_csr(self.row_ptr, self.col_ind, self.val, self.columns, self.rows) @matrix_transpose.transpose() for i in 0..self.val.count()-1 if self.val[i] != @matrix_transpose.val[i] return false end end return true end |
#unitary? ⇒ Boolean
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/csrmatrix/properties.rb', line 183 def unitary? # Determines if the matrix is unitary is_invariant? if !self.square? raise Exceptions::MatrixDimException.new, "Matrix is not square." return false end m = Matrix.rows(self.decompose) return m.unitary? end |
#upper_triangular? ⇒ Boolean
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/csrmatrix/properties.rb', line 195 def upper_triangular? # Determines if the matrix is upper-triangular is_invariant? for i in 0..self.columns-1 for column_index in row_ptr[i]..row_ptr[i+1]-1 if (self.col_ind[column_index] < i) return false end end end return true end |
#zero? ⇒ Boolean
209 210 211 212 213 214 215 216 217 218 |
# File 'lib/csrmatrix/properties.rb', line 209 def zero? # Determines if the matrix is zero is_invariant? for value in self.val if value != 0 return false end end return true end |