Changeset fed143 in git
- Timestamp:
- Sep 20, 2010, 10:11:03 AM (13 years ago)
- Branches:
- (u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
- Children:
- cfd2e6ba5e3f99f46e106336cafaef280361dd61
- Parents:
- 73f78da968d3bf51d9cad24fb4ecf386e3c13276
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/iparith.cc
r73f78d rfed143 412 412 { "quotient", 0, QUOTIENT_CMD , CMD_2}, 413 413 { "random", 0, RANDOM_CMD , CMD_23}, 414 { "rank", 0, RANK_CMD , CMD_12}, 414 415 { "read", 0, READ_CMD , CMD_12}, 415 416 { "reduce", 0, REDUCE_CMD , CMD_M}, … … 2960 2961 res->data =(char *)(long)((i > j) ? i : (rand() % (j-i+1)) + i); 2961 2962 #endif /* buildin_rand */ 2963 return FALSE; 2964 } 2965 static BOOLEAN jjRANK2(leftv res, leftv u, leftv v) 2966 { 2967 matrix m =(matrix)u->Data(); 2968 int isRowEchelon = (int)(long)v->Data(); 2969 if (isRowEchelon != 1) isRowEchelon = 0; 2970 int rank = luRank(m, isRowEchelon); 2971 res->data =(char *)(long)rank; 2962 2972 return FALSE; 2963 2973 } … … 3977 3987 ,{jjQUOT, QUOTIENT_CMD, IDEAL_CMD, MODUL_CMD, MODUL_CMD, ALLOW_PLURAL |ALLOW_RING} 3978 3988 ,{jjRANDOM, RANDOM_CMD, INT_CMD, INT_CMD, INT_CMD, ALLOW_PLURAL |ALLOW_RING} 3989 ,{jjRANK2, RANK_CMD, INT_CMD, MATRIX_CMD, INT_CMD, ALLOW_PLURAL |ALLOW_RING} 3979 3990 ,{jjREAD2, READ_CMD, STRING_CMD, LINK_CMD, STRING_CMD, ALLOW_PLURAL |ALLOW_RING} 3980 3991 ,{jjREDUCE_P, REDUCE_CMD, POLY_CMD, POLY_CMD, IDEAL_CMD, ALLOW_PLURAL |ALLOW_RING} … … 5043 5054 } 5044 5055 //res->data = (char *)0; 5056 return FALSE; 5057 } 5058 static BOOLEAN jjRANK1(leftv res, leftv v) 5059 { 5060 matrix m =(matrix)v->Data(); 5061 int rank = luRank(m, 0); 5062 res->data =(char *)(long)rank; 5045 5063 return FALSE; 5046 5064 } … … 5971 5989 ,{kQHWeight, QHWEIGHT_CMD, INTVEC_CMD, MODUL_CMD , ALLOW_PLURAL |ALLOW_RING} 5972 5990 ,{jjWRONG, QRING_CMD, 0, ANY_TYPE , ALLOW_PLURAL |ALLOW_RING} 5991 ,{jjRANK1, RANK_CMD, INT_CMD, MATRIX_CMD , ALLOW_PLURAL |ALLOW_RING} 5973 5992 ,{jjREAD, READ_CMD, STRING_CMD, LINK_CMD , ALLOW_PLURAL |ALLOW_RING} 5974 5993 ,{jjREGULARITY, REGULARITY_CMD, INT_CMD, LIST_CMD , NO_PLURAL |ALLOW_RING} -
Singular/tok.h
r73f78d rfed143 148 148 QRING_CMD, 149 149 RANDOM_CMD, 150 RANK_CMD, 150 151 READ_CMD, 151 152 REPART_CMD, -
kernel/linearAlgebra.cc
r73f78d rfed143 148 148 { 149 149 n = nDiv(pGetCoeff(p), pivotElement); 150 nNormalize(n); 150 151 151 152 /* filling lMat; … … 157 158 n = nNeg(n); 158 159 for (int cGauss = r + cOffset + 1; cGauss <= cc; cGauss++) 160 { 159 161 MATELEM(uMat, rGauss, cGauss) 160 162 = pAdd(MATELEM(uMat, rGauss, cGauss), 161 163 ppMult_nn(MATELEM(uMat, r, cGauss), n)); 164 pNormalize(MATELEM(uMat, rGauss, cGauss)); 165 } 162 166 163 167 nDelete(&n); /* clean up n */ … … 182 186 bool luInverse(const matrix aMat, matrix &iMat) 183 187 { /* aMat is guaranteed to be an (n x n)-matrix */ 184 int d = aMat->rows();185 186 188 matrix pMat; 187 189 matrix lMat; … … 196 198 197 199 return result; 200 } 201 202 /* Assumes that aMat is already in row echelon form */ 203 int rankFromRowEchelonForm(const matrix aMat) 204 { 205 int rank = 0; 206 int rr = aMat->rows(); int cc = aMat->cols(); 207 int r = 1; int c = 1; 208 while ((r <= rr) && (c <= cc)) 209 { 210 if (MATELEM(aMat, r, c) == NULL) c++; 211 else { rank++; r++; } 212 } 213 return rank; 214 } 215 216 int luRank(const matrix aMat, const bool isRowEchelon) 217 { 218 if (isRowEchelon) return rankFromRowEchelonForm(aMat); 219 else 220 { /* compute the LU-decomposition and read off the rank from 221 the upper triangular matrix of that decomposition */ 222 matrix pMat; 223 matrix lMat; 224 matrix uMat; 225 luDecomp(aMat, pMat, lMat, uMat); 226 int result = rankFromRowEchelonForm(uMat); 227 228 /* clean-up */ 229 idDelete((ideal*)&pMat); 230 idDelete((ideal*)&lMat); 231 idDelete((ideal*)&uMat); 232 233 return result; 234 } 198 235 } 199 236 … … 238 275 p = pNeg(p); 239 276 p = pMult(p, pCopy(MATELEM(iMat, r, r))); 277 pNormalize(p); 240 278 MATELEM(iMat, r, c) = p; 241 279 } … … 285 323 p = pNeg(p); 286 324 p = pMult(p, pCopy(MATELEM(iMat, c, c))); 325 pNormalize(p); 287 326 MATELEM(iMat, r, c) = p; 288 327 } … … 349 388 p = pAdd(p, ppMult_qq(MATELEM(lMat, r, c), MATELEM(yVec, c, 1) )); 350 389 MATELEM(yVec, r, 1) = pNeg(p); 390 pNormalize(MATELEM(yVec, r, 1)); 351 391 } 352 392 … … 383 423 poly q = pNSet(nInvers(pGetCoeff(MATELEM(uMat, r, nonZeroC)))); 384 424 MATELEM(xVec, nonZeroC, 1) = pMult(pNeg(p), q); 425 pNormalize(MATELEM(xVec, nonZeroC, 1)); 385 426 lastNonZeroC = nonZeroC; 386 427 } -
kernel/linearAlgebra.h
r73f78d rfed143 198 198 matrix &iMat /**< [out] inverse of A if invertible */ 199 199 ); 200 200 201 /** 202 * Computes the rank of a given (m x n)-matrix. 203 * 204 * The matrix may already be given in row echelon form, e.g., when 205 * the user has before called luDecomp and passes the upper triangular 206 * matrix U to luRank. In this case, the second argument can be set to 207 * true in order to pass this piece of information to the method. 208 * Otherwise, luDecomp will be called first to compute the matrix U. 209 * The rank is then read off the matrix U. 210 * 211 * @return the rank as an int 212 * @sa luDecomp(const matrix aMat, matrix &pMat, matrix &lMat, matrix &uMat) 213 **/ 214 int luRank( 215 const matrix aMat, /**< [in] input matrix */ 216 const bool isRowEchelon /**< [in] if true then aMat is assumed to be 217 already in row echelon form */ 218 ); 219 201 220 /** 202 221 * Solves the linear system A*x = b, where A is an (n x n)-matrix
Note: See TracChangeset
for help on using the changeset viewer.