Changeset dffcf2d in git
 Timestamp:
 Aug 2, 2011, 3:17:25 PM (13 years ago)
 Branches:
 (u'fiekerDuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '45e267b9942dec9429fe249ce3e5e44ab80a6a3a')
 Children:
 47417bfd93377bd8db51a2eb289b7eaec8ae7b08
 Parents:
 0a80331a686854fd8c674703b79f6fab0608d93a
 gitauthor:
 Hans Schoenemann <hannes@mathematik.unikl.de>20110802 15:17:25+02:00
 gitcommitter:
 Mohamed Barakat <mohamed.barakat@rwthaachen.de>20111109 13:01:21+01:00
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

kernel/fglmvec.cc
r0a8033 rdffcf2d 31 31 { 32 32 private: 33 34 35 number *elems;33 int ref_count; 34 int N; 35 number *elems; 36 36 public: 37 fglmVectorRep() : ref_count(1), N(0), elems(0) {} 38 fglmVectorRep( int n, number * e ) : ref_count(1), N(n), elems(e) {} 39 fglmVectorRep( int n ) : ref_count(1), N(n) 40 { 41 fglmASSERT( N >= 0, "illegal Vector representation" ); 42 if ( N == 0 ) 43 elems= 0; 44 else { 45 elems= (number *)omAlloc( N*sizeof( number ) ); 46 for ( int i= N1; i >= 0; i ) 47 elems[i]= nInit( 0 ); 48 } 49 } 50 ~fglmVectorRep() 51 { 52 if ( N > 0 ) { 53 for ( int i= N1; i >= 0; i ) 54 nDelete( elems + i ); 55 omFreeSize( (ADDRESS)elems, N*sizeof( number ) ); 56 } 57 } 58 59 fglmVectorRep* clone() const 60 { 61 if ( N > 0 ) { 62 number * elems_clone; 63 elems_clone= (number *)omAlloc( N*sizeof( number ) ); 64 for ( int i= N1; i >= 0; i ) 65 elems_clone[i] = nCopy( elems[i] ); 66 return new fglmVectorRep( N, elems_clone ); 67 } else 68 return new fglmVectorRep( N, 0 ); 69 } 70 BOOLEAN deleteObject() { return ref_count == 0; } 71 fglmVectorRep * copyObject() { ref_count++; return this; } 72 int refcount() const { return ref_count; } 73 BOOLEAN isUnique() const { return ref_count == 1; } 74 75 int size() const { return N; } 76 int isZero() const 77 { 78 int k; 79 for ( k= N; k > 0; k ) 80 if ( ! nIsZero( getconstelem( k ) ) ) 81 return 0; 82 return 1; 83 } 84 int numNonZeroElems() const 85 { 86 int num = 0; 87 int k; 88 for ( k= N; k > 0; k ) 89 if ( ! nIsZero( getconstelem( k ) ) ) num++; 90 return num; 91 } 92 void setelem( int i, number n ) 93 { 94 fglmASSERT( 0 < i && i <= N, "setelem: wrong index" ); 95 nDelete( elems + i1 ); 96 elems[i1]= n; 97 } 98 number ejectelem( int i, number n ) 99 { 100 fglmASSERT( isUnique(), "should only be called if unique!" ); 101 number temp= elems[i1]; 102 elems[i1]= n; 103 return temp; 104 } 105 number & getelem( int i ) 106 { 107 fglmASSERT( 0 < i && i <= N, "getelem: wrong index" ); 108 return elems[i1]; 109 } 110 const number getconstelem( int i) const 111 { 112 fglmASSERT( 0 < i && i <= N, "getconstelem: wrong index" ); 113 return elems[i1]; 114 } 115 friend class fglmVector; 37 fglmVectorRep ():ref_count (1), N (0), elems (0) 38 { 39 } 40 fglmVectorRep (int n, number * e):ref_count (1), N (n), elems (e) 41 { 42 } 43 fglmVectorRep (int n):ref_count (1), N (n) 44 { 45 fglmASSERT (N >= 0, "illegal Vector representation"); 46 if(N == 0) 47 elems = 0; 48 else 49 { 50 elems = (number *) omAlloc (N * sizeof (number)); 51 for(int i = N  1; i >= 0; i) 52 elems[i] = nInit (0); 53 } 54 } 55 ~fglmVectorRep () 56 { 57 if(N > 0) 58 { 59 for(int i = N  1; i >= 0; i) 60 nDelete (elems + i); 61 omFreeSize ((ADDRESS) elems, N * sizeof (number)); 62 } 63 } 64 65 fglmVectorRep *clone () const 66 { 67 if(N > 0) 68 { 69 number *elems_clone; 70 elems_clone = (number *) omAlloc (N * sizeof (number)); 71 for(int i = N  1; i >= 0; i) 72 elems_clone[i] = nCopy (elems[i]); 73 return new fglmVectorRep (N, elems_clone); 74 } 75 else 76 return new fglmVectorRep (N, 0); 77 } 78 BOOLEAN deleteObject () 79 { 80 return ref_count == 0; 81 } 82 fglmVectorRep *copyObject () 83 { 84 ref_count++; 85 return this; 86 } 87 int refcount () const 88 { 89 return ref_count; 90 } 91 BOOLEAN isUnique () const 92 { 93 return ref_count == 1; 94 } 95 96 int size () const 97 { 98 return N; 99 } 100 int isZero () const 101 { 102 int k; 103 for(k = N; k > 0; k) 104 if(!nIsZero (getconstelem (k))) 105 return 0; 106 return 1; 107 } 108 int numNonZeroElems () const 109 { 110 int num = 0; 111 int k; 112 for(k = N; k > 0; k) 113 if(!nIsZero (getconstelem (k))) 114 num++; 115 return num; 116 } 117 void setelem (int i, number n) 118 { 119 fglmASSERT (0 < i && i <= N, "setelem: wrong index"); 120 nDelete (elems + i  1); 121 elems[i  1] = n; 122 } 123 number ejectelem (int i, number n) 124 { 125 fglmASSERT (isUnique (), "should only be called if unique!"); 126 number temp = elems[i  1]; 127 elems[i  1] = n; 128 return temp; 129 } 130 number & getelem (int i) 131 { 132 fglmASSERT (0 < i && i <= N, "getelem: wrong index"); 133 return elems[i  1]; 134 } 135 const number getconstelem (int i) const 136 { 137 fglmASSERT (0 < i && i <= N, "getconstelem: wrong index"); 138 return elems[i  1]; 139 } 140 friend class fglmVector; 116 141 }; 117 142 … … 121 146 /// 122 147 123 fglmVector::fglmVector( fglmVectorRep * r ) : rep(r) {} 124 125 fglmVector::fglmVector() : rep( new fglmVectorRep() ) {} 126 127 fglmVector::fglmVector( int size ) : rep( new fglmVectorRep( size ) ) {} 128 129 fglmVector::fglmVector( int size, int basis ) : rep( new fglmVectorRep( size ) ) 130 { 131 rep>setelem( basis, nInit( 1 ) ); 132 } 133 134 fglmVector::fglmVector( const fglmVector & v ) 135 { 136 rep= v.rep>copyObject(); 137 } 138 139 fglmVector::~fglmVector() 140 { 141 if ( rep>deleteObject() ) 142 delete rep; 148 fglmVector::fglmVector (fglmVectorRep * r):rep (r) 149 { 150 } 151 152 fglmVector::fglmVector ():rep (new fglmVectorRep ()) 153 { 154 } 155 156 fglmVector::fglmVector (int size):rep (new fglmVectorRep (size)) 157 { 158 } 159 160 fglmVector::fglmVector (int size, int basis):rep (new fglmVectorRep (size)) 161 { 162 rep>setelem (basis, nInit (1)); 163 } 164 165 fglmVector::fglmVector (const fglmVector & v) 166 { 167 rep = v.rep>copyObject (); 168 } 169 170 fglmVector::~fglmVector () 171 { 172 if(rep>deleteObject ()) 173 delete rep; 143 174 } 144 175 145 176 #ifndef HAVE_EXPLICIT_CONSTR 177 void fglmVector::mac_constr (const fglmVector & v) 178 { 179 rep = v.rep>copyObject (); 180 } 181 182 void fglmVector::mac_constr_i (int size) 183 { 184 rep = new fglmVectorRep (size); 185 } 186 187 void fglmVector::clearelems () 188 { 189 if(rep>deleteObject ()) 190 delete rep; 191 } 192 #endif 193 194 void fglmVector::makeUnique () 195 { 196 if(rep>refcount () != 1) 197 { 198 rep>deleteObject (); 199 rep = rep>clone (); 200 } 201 } 202 203 int fglmVector::size () const 204 { 205 return rep>size (); 206 } 207 208 int fglmVector::numNonZeroElems () const 209 { 210 return rep>numNonZeroElems (); 211 } 212 146 213 void 147 fglmVector::mac_constr( const fglmVector & v) 148 { 149 rep= v.rep>copyObject(); 150 } 151 152 void 153 fglmVector::mac_constr_i( int size ) 154 { 155 rep= new fglmVectorRep( size ); 156 } 157 158 void 159 fglmVector::clearelems() 160 { 161 if ( rep>deleteObject() ) 214 fglmVector::nihilate (const number fac1, const number fac2, 215 const fglmVector v) 216 { 217 int i; 218 int vsize = v.size (); 219 number term1, term2; 220 fglmASSERT (vsize <= rep>size (), "v has to be smaller oder equal"); 221 if(rep>isUnique ()) 222 { 223 for(i = vsize; i > 0; i) 224 { 225 term1 = nMult (fac1, rep>getconstelem (i)); 226 term2 = nMult (fac2, v.rep>getconstelem (i)); 227 rep>setelem (i, nSub (term1, term2)); 228 nDelete (&term1); 229 nDelete (&term2); 230 } 231 for(i = rep>size (); i > vsize; i) 232 { 233 rep>setelem (i, nMult (fac1, rep>getconstelem (i))); 234 } 235 } 236 else 237 { 238 number *newelems; 239 newelems = (number *) omAlloc (rep>size () * sizeof (number)); 240 for(i = vsize; i > 0; i) 241 { 242 term1 = nMult (fac1, rep>getconstelem (i)); 243 term2 = nMult (fac2, v.rep>getconstelem (i)); 244 newelems[i  1] = nSub (term1, term2); 245 nDelete (&term1); 246 nDelete (&term2); 247 } 248 for(i = rep>size (); i > vsize; i) 249 { 250 newelems[i  1] = nMult (fac1, rep>getconstelem (i)); 251 } 252 rep>deleteObject (); 253 rep = new fglmVectorRep (rep>size (), newelems); 254 } 255 } 256 257 fglmVector & fglmVector::operator = (const fglmVector & v) 258 { 259 if(this != &v) 260 { 261 if(rep>deleteObject ()) 162 262 delete rep; 163 } 164 #endif 165 166 void 167 fglmVector::makeUnique() 168 { 169 if ( rep>refcount() != 1 ) { 170 rep>deleteObject(); 171 rep= rep>clone(); 172 } 173 } 174 175 int 176 fglmVector::size() const 177 { 178 return rep>size(); 179 } 180 181 int 182 fglmVector::numNonZeroElems() const 183 { 184 return rep>numNonZeroElems(); 185 } 186 187 void 188 fglmVector::nihilate( const number fac1, const number fac2, const fglmVector v ) 189 { 190 int i; 191 int vsize= v.size(); 192 number term1, term2; 193 fglmASSERT( vsize <= rep>size(), "v has to be smaller oder equal" ); 194 if ( rep>isUnique() ) { 195 for ( i= vsize; i > 0; i ) { 196 term1= nMult( fac1, rep>getconstelem( i ) ); 197 term2= nMult( fac2, v.rep>getconstelem( i ) ); 198 rep>setelem( i, nSub( term1, term2 ) ); 199 nDelete( &term1 ); 200 nDelete( &term2 ); 201 } 202 for ( i= rep>size(); i > vsize; i ) { 203 rep>setelem( i, nMult( fac1, rep>getconstelem( i ) ) ); 204 } 205 } 263 rep = v.rep>copyObject (); 264 } 265 return *this; 266 } 267 268 int fglmVector::operator == (const fglmVector & v) 269 { 270 if(rep>size () == v.rep>size ()) 271 { 272 if(rep == v.rep) 273 return 1; 206 274 else 207 275 { 208 number* newelems; 209 newelems= (number *)omAlloc( rep>size()*sizeof( number ) ); 210 for ( i= vsize; i > 0; i ) { 211 term1= nMult( fac1, rep>getconstelem( i ) ); 212 term2= nMult( fac2, v.rep>getconstelem( i ) ); 213 newelems[i1]= nSub( term1, term2 ); 214 nDelete( &term1 ); 215 nDelete( &term2 ); 216 } 217 for ( i= rep>size(); i > vsize; i ) { 218 newelems[i1]= nMult( fac1, rep>getconstelem( i ) ); 219 } 220 rep>deleteObject(); 221 rep= new fglmVectorRep( rep>size(), newelems ); 222 } 223 } 224 225 fglmVector & 226 fglmVector::operator = ( const fglmVector & v ) 227 { 228 if ( this != &v ) { 229 if ( rep>deleteObject() ) 230 delete rep; 231 rep = v.rep>copyObject(); 232 } 233 return *this; 234 } 235 236 int 237 fglmVector::operator == ( const fglmVector & v ) 238 { 239 if ( rep>size() == v.rep>size() ) { 240 if ( rep == v.rep ) return 1; 241 else { 242 int i; 243 for ( i= rep>size(); i > 0; i ) 244 if ( ! nEqual( rep>getconstelem( i ), v.rep>getconstelem( i ) ) ) 245 return 0; 246 return 1; 247 } 248 } 249 return 0; 250 } 251 252 int 253 fglmVector::operator != ( const fglmVector & v ) 254 { 255 return !( *this == v ); 256 } 257 258 int 259 fglmVector::isZero() 260 { 261 return rep>isZero(); 262 } 263 264 int 265 fglmVector::elemIsZero( int i ) 266 { 267 return nIsZero( rep>getconstelem( i ) ); 268 } 269 270 fglmVector & 271 fglmVector::operator += ( const fglmVector & v ) 272 { 273 fglmASSERT( size() == v.size(), "incompatible vectors" ); 274 // ACHTUNG : Das Verhalten hier mit gcd genau ueberpruefen! 275 int i; 276 if ( rep>isUnique() ) { 277 for ( i= rep>size(); i > 0; i ) 278 rep>setelem( i, nAdd( rep>getconstelem( i ), v.rep>getconstelem( i ) ) ); 279 } 280 else 281 { 282 int n = rep>size(); 283 number* newelems; 284 newelems= (number *)omAlloc( n*sizeof( number ) ); 285 for ( i= n; i > 0; i ) 286 newelems[i1]= nAdd( rep>getconstelem( i ), v.rep>getconstelem( i ) ); 287 rep>deleteObject(); 288 rep= new fglmVectorRep( n, newelems ); 289 } 290 return *this; 291 } 292 293 fglmVector & 294 fglmVector::operator = ( const fglmVector & v ) 295 { 296 fglmASSERT( size() == v.size(), "incompatible vectors" ); 297 int i; 298 if ( rep>isUnique() ) { 299 for ( i= rep>size(); i > 0; i ) 300 rep>setelem( i, nSub( rep>getconstelem( i ), v.rep>getconstelem( i ) ) ); 301 } 302 else 303 { 304 int n = rep>size(); 305 number* newelems; 306 newelems= (number *)omAlloc( n*sizeof( number ) ); 307 for ( i= n; i > 0; i ) 308 newelems[i1]= nSub( rep>getconstelem( i ), v.rep>getconstelem( i ) ); 309 rep>deleteObject(); 310 rep= new fglmVectorRep( n, newelems ); 311 } 312 return *this; 313 } 314 315 fglmVector & 316 fglmVector::operator *= ( const number & n ) 317 { 318 int s= rep>size(); 319 int i; 320 if ( ! rep>isUnique() ) { 321 number * temp; 322 temp= (number *)omAlloc( s*sizeof( number ) ); 323 for ( i= s; i > 0; i ) 324 temp[i1]= nMult( rep>getconstelem( i ), n ); 325 rep>deleteObject(); 326 rep= new fglmVectorRep( s, temp ); 327 } 328 else 329 { 330 for (i= s; i > 0; i ) 331 rep>setelem( i, nMult( rep>getconstelem( i ), n ) ); 332 } 333 return *this; 334 } 335 336 fglmVector & 337 fglmVector::operator /= ( const number & n ) 338 { 339 int s= rep>size(); 340 int i; 341 if ( ! rep>isUnique() ) { 342 number * temp; 343 temp= (number *)omAlloc( s*sizeof( number ) ); 344 for ( i= s; i > 0; i ) { 345 temp[i1]= nDiv( rep>getconstelem( i ), n ); 346 nNormalize( temp[i1] ); 347 } 348 rep>deleteObject(); 349 rep= new fglmVectorRep( s, temp ); 350 } 351 else 352 { 353 for (i= s; i > 0; i ) { 354 rep>setelem( i, nDiv( rep>getconstelem( i ), n ) ); 355 nNormalize( rep>getelem( i ) ); 356 } 357 } 358 return *this; 359 } 360 361 fglmVector 362 operator  ( const fglmVector & v ) 363 { 364 fglmVector temp( v.size() ); 365 int i; 366 number n ; 367 for ( i= v.size(); i > 0; i ) { 368 n= nCopy( v.getconstelem( i ) ); 369 n= nNeg( n ); 370 temp.setelem( i, n ); 371 } 372 return temp; 373 } 374 375 fglmVector 376 operator + ( const fglmVector & lhs, const fglmVector & rhs ) 377 { 378 fglmVector temp= lhs; 379 temp+= rhs; 380 return temp; 381 } 382 383 fglmVector 384 operator  ( const fglmVector & lhs, const fglmVector & rhs ) 385 { 386 fglmVector temp= lhs; 387 temp= rhs; 388 return temp; 389 } 390 391 fglmVector 392 operator * ( const fglmVector & v, const number n ) 393 { 394 fglmVector temp= v; 395 temp*= n; 396 return temp; 397 } 398 399 fglmVector 400 operator * ( const number n, const fglmVector & v ) 401 { 402 fglmVector temp= v; 403 temp*= n; 404 return temp; 405 } 406 407 number & 408 fglmVector::getelem( int i ) 409 { 410 makeUnique(); 411 return rep>getelem( i ); 412 } 413 414 const number 415 fglmVector::getconstelem( int i ) const 416 { 417 return rep>getconstelem( i ); 418 } 419 420 void 421 fglmVector::setelem( int i, number & n ) 422 { 423 makeUnique(); 424 rep>setelem( i, n ); 425 n= nNULL; 426 } 427 428 number 429 fglmVector::gcd() const 430 { 431 int i= rep>size(); 432 BOOLEAN found = FALSE; 433 BOOLEAN gcdIsOne = FALSE; 434 number theGcd; 435 number current; 436 while( i > 0 && ! found ) { 437 current= rep>getconstelem( i ); 438 if ( ! nIsZero( current ) ) { 439 theGcd= nCopy( current ); 440 found= TRUE; 441 if ( ! nGreaterZero( theGcd ) ) { 442 theGcd= nNeg( theGcd ); 443 } 444 if ( nIsOne( theGcd ) ) gcdIsOne= TRUE; 445 } 446 i; 447 } 448 if ( found ) { 449 while ( i > 0 && ! gcdIsOne ) { 450 current= rep>getconstelem( i ); 451 if ( ! nIsZero( current ) ) { 452 number temp= nGcd( theGcd, current, currRing ); 453 nDelete( &theGcd ); 454 theGcd= temp; 455 if ( nIsOne( theGcd ) ) gcdIsOne= TRUE; 456 } 457 i; 458 } 459 } 460 else 461 theGcd= nInit( 0 ); 462 return theGcd; 463 } 464 465 number 466 fglmVector::clearDenom() 467 { 468 number theLcm = nInit( 1 ); 469 number current; 470 BOOLEAN isZero = TRUE; 471 int i; 472 for ( i= size(); i > 0; i ) { 473 if ( ! nIsZero( rep>getconstelem(i) ) ) { 474 isZero= FALSE; 475 number temp= nLcm( theLcm, rep>getconstelem( i ), currRing ); 476 nDelete( &theLcm ); 477 theLcm= temp; 478 } 479 } 480 if ( isZero ) { 481 nDelete( &theLcm ); 482 theLcm= nInit( 0 ); 483 } 484 else { 485 if ( ! nIsOne( theLcm ) ) { 486 *this *= theLcm; 487 for ( i= size(); i > 0; i ) { 488 nNormalize( rep>getelem( i ) ); 489 } 490 } 491 } 492 return theLcm; 276 int i; 277 for(i = rep>size (); i > 0; i) 278 if(!nEqual (rep>getconstelem (i), v.rep>getconstelem (i))) 279 return 0; 280 return 1; 281 } 282 } 283 return 0; 284 } 285 286 int fglmVector::operator != (const fglmVector & v) 287 { 288 return !(*this == v); 289 } 290 291 int fglmVector::isZero () 292 { 293 return rep>isZero (); 294 } 295 296 int fglmVector::elemIsZero (int i) 297 { 298 return nIsZero (rep>getconstelem (i)); 299 } 300 301 fglmVector & fglmVector::operator += (const fglmVector & v) 302 { 303 fglmASSERT (size () == v.size (), "incompatible vectors"); 304 // ACHTUNG : Das Verhalten hier mit gcd genau ueberpruefen! 305 int i; 306 if(rep>isUnique ()) 307 { 308 for(i = rep>size (); i > 0; i) 309 rep>setelem (i, nAdd (rep>getconstelem (i), v.rep>getconstelem (i))); 310 } 311 else 312 { 313 int n = rep>size (); 314 number *newelems; 315 newelems = (number *) omAlloc (n * sizeof (number)); 316 for(i = n; i > 0; i) 317 newelems[i  1] = nAdd (rep>getconstelem (i), v.rep>getconstelem (i)); 318 rep>deleteObject (); 319 rep = new fglmVectorRep (n, newelems); 320 } 321 return *this; 322 } 323 324 fglmVector & fglmVector::operator = (const fglmVector & v) 325 { 326 fglmASSERT (size () == v.size (), "incompatible vectors"); 327 int i; 328 if(rep>isUnique ()) 329 { 330 for(i = rep>size (); i > 0; i) 331 rep>setelem (i, nSub (rep>getconstelem (i), v.rep>getconstelem (i))); 332 } 333 else 334 { 335 int n = rep>size (); 336 number *newelems; 337 newelems = (number *) omAlloc (n * sizeof (number)); 338 for(i = n; i > 0; i) 339 newelems[i  1] = nSub (rep>getconstelem (i), v.rep>getconstelem (i)); 340 rep>deleteObject (); 341 rep = new fglmVectorRep (n, newelems); 342 } 343 return *this; 344 } 345 346 fglmVector & fglmVector::operator *= (const number & n) 347 { 348 int s = rep>size (); 349 int i; 350 if(!rep>isUnique ()) 351 { 352 number *temp; 353 temp = (number *) omAlloc (s * sizeof (number)); 354 for(i = s; i > 0; i) 355 temp[i  1] = nMult (rep>getconstelem (i), n); 356 rep>deleteObject (); 357 rep = new fglmVectorRep (s, temp); 358 } 359 else 360 { 361 for(i = s; i > 0; i) 362 rep>setelem (i, nMult (rep>getconstelem (i), n)); 363 } 364 return *this; 365 } 366 367 fglmVector & fglmVector::operator /= (const number & n) 368 { 369 int s = rep>size (); 370 int i; 371 if(!rep>isUnique ()) 372 { 373 number *temp; 374 temp = (number *) omAlloc (s * sizeof (number)); 375 for(i = s; i > 0; i) 376 { 377 temp[i  1] = nDiv (rep>getconstelem (i), n); 378 nNormalize (temp[i  1]); 379 } 380 rep>deleteObject (); 381 rep = new fglmVectorRep (s, temp); 382 } 383 else 384 { 385 for(i = s; i > 0; i) 386 { 387 rep>setelem (i, nDiv (rep>getconstelem (i), n)); 388 nNormalize (rep>getelem (i)); 389 } 390 } 391 return *this; 392 } 393 394 fglmVector operator  (const fglmVector & v) 395 { 396 fglmVector temp (v.size ()); 397 int i; 398 number n; 399 for(i = v.size (); i > 0; i) 400 { 401 n = nCopy (v.getconstelem (i)); 402 n = nNeg (n); 403 temp.setelem (i, n); 404 } 405 return temp; 406 } 407 408 fglmVector operator + (const fglmVector & lhs, const fglmVector & rhs) 409 { 410 fglmVector temp = lhs; 411 temp += rhs; 412 return temp; 413 } 414 415 fglmVector operator  (const fglmVector & lhs, const fglmVector & rhs) 416 { 417 fglmVector temp = lhs; 418 temp = rhs; 419 return temp; 420 } 421 422 fglmVector operator * (const fglmVector & v, const number n) 423 { 424 fglmVector temp = v; 425 temp *= n; 426 return temp; 427 } 428 429 fglmVector operator * (const number n, const fglmVector & v) 430 { 431 fglmVector temp = v; 432 temp *= n; 433 return temp; 434 } 435 436 number & fglmVector::getelem (int i) 437 { 438 makeUnique (); 439 return rep>getelem (i); 440 } 441 442 const number fglmVector::getconstelem (int i) const 443 { 444 return rep>getconstelem (i); 445 } 446 447 void fglmVector::setelem (int i, number & n) 448 { 449 makeUnique (); 450 rep>setelem (i, n); 451 n = n_Init (0, currRing>cf); 452 } 453 454 number fglmVector::gcd () const 455 { 456 int i = rep>size (); 457 BOOLEAN found = FALSE; 458 BOOLEAN gcdIsOne = FALSE; 459 number theGcd; 460 number current; 461 while(i > 0 && !found) 462 { 463 current = rep>getconstelem (i); 464 if(!nIsZero (current)) 465 { 466 theGcd = nCopy (current); 467 found = TRUE; 468 if(!nGreaterZero (theGcd)) 469 { 470 theGcd = nNeg (theGcd); 471 } 472 if(nIsOne (theGcd)) 473 gcdIsOne = TRUE; 474 } 475 i; 476 } 477 if(found) 478 { 479 while(i > 0 && !gcdIsOne) 480 { 481 current = rep>getconstelem (i); 482 if(!nIsZero (current)) 483 { 484 number temp = nGcd (theGcd, current, currRing); 485 nDelete (&theGcd); 486 theGcd = temp; 487 if(nIsOne (theGcd)) 488 gcdIsOne = TRUE; 489 } 490 i; 491 } 492 } 493 else 494 theGcd = nInit (0); 495 return theGcd; 496 } 497 498 number fglmVector::clearDenom () 499 { 500 number theLcm = nInit (1); 501 BOOLEAN isZero = TRUE; 502 int i; 503 for(i = size (); i > 0; i) 504 { 505 if(!nIsZero (rep>getconstelem (i))) 506 { 507 isZero = FALSE; 508 number temp = n_Lcm (theLcm, rep>getconstelem (i), currRing>cf); 509 nDelete (&theLcm); 510 theLcm = temp; 511 } 512 } 513 if(isZero) 514 { 515 nDelete (&theLcm); 516 theLcm = nInit (0); 517 } 518 else 519 { 520 if(!nIsOne (theLcm)) 521 { 522 *this *= theLcm; 523 for(i = size (); i > 0; i) 524 { 525 nNormalize (rep>getelem (i)); 526 } 527 } 528 } 529 return theLcm; 493 530 } 494 531
Note: See TracChangeset
for help on using the changeset viewer.