Changeset 89b59f in git
- Timestamp:
- Feb 7, 2007, 1:40:06 PM (16 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- Children:
- 508937797961aad4ba379a8c5136675e42495d8a
- Parents:
- 19370ce8f2f2a00e555d8de12946e08fb4e20b7c
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/claptmpl.cc
r19370c r89b59f 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 // $Id: claptmpl.cc,v 1.3 4 2006-07-27 09:04:07 SingularExp $5 // $Id: claptmpl.cc,v 1.35 2007-02-07 12:40:06 bricken Exp $ 6 6 /* 7 7 * ABSTRACT - instantiation of all templates … … 219 219 template int pos_helper(kStrategy strat, poly p, int len, intset setL, polyset set); 220 220 template int pos_helper(kStrategy strat, poly p, wlen_type len, wlen_set setL, polyset set); 221 #ifdef NORO_CACHE 222 template class std::map<PolySimple,std::pair<PolySimple,int> >; 223 template class std::vector<PolySimple>; 224 #endif 221 225 //template int pos_helper(kStrategy strat, poly p, int len, intset setL, polyset set); -
kernel/tgb.cc
r19370c r89b59f 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* $Id: tgb.cc,v 1.12 3 2007-02-07 10:49:41 SingularExp $ */7 /* $Id: tgb.cc,v 1.124 2007-02-07 12:39:55 bricken Exp $ */ 8 8 /* 9 9 * ABSTRACT: slimgb and F4 implementation … … 29 29 #include <stdlib.h> 30 30 #include <stdio.h> 31 #include <map> 31 32 #define SR_HDL(A) ((long)(A)) 32 33 static const int bundle_size=1000; … … 2182 2183 2183 2184 } 2185 2186 #ifdef NORO_CACHE 2187 class NoroCache{ 2188 public: 2189 void insert(poly term, poly nf, int len){ 2190 assume(impl.find(p_Copy(term,currRing))==impl.end()); 2191 assume(len==pLength(nf)); 2192 if (term==nf){ 2193 poly copied=p_Copy(term, currRing); 2194 term=copied; 2195 nf=copied; 2196 ressources.push_back(copied); 2197 } else{ 2198 term=p_Copy(term,currRing); 2199 2200 ressources.push_back(term); 2201 if (nf){ 2202 nf=p_Copy(nf,currRing); 2203 ressources.push_back(nf); 2204 } 2205 } 2206 impl[term]=std::pair<PolySimple,int> (nf,len); 2207 } 2208 poly lookup(poly term, BOOLEAN& succ, int& len){ 2209 cache_map::iterator it=impl.find(term); 2210 if (it!=impl.end()){ 2211 succ=TRUE; 2212 //PrintS("Hit"); 2213 len=it->second.second; 2214 return it->second.first.impl; 2215 } else { 2216 //PrintS("Miss"); 2217 succ=FALSE; 2218 return NULL; 2219 } 2220 } 2221 ~NoroCache(){ 2222 int s=ressources.size(); 2223 int i; 2224 for(i=0;i<s;i++){ 2225 p_Delete(&ressources[i].impl,currRing); 2226 } 2227 } 2228 protected: 2229 typedef std::vector<PolySimple> poly_vec; 2230 poly_vec ressources; 2231 typedef std::map<PolySimple,std::pair<PolySimple,int> > cache_map; 2232 cache_map impl; 2233 }; 2234 2235 static poly noro_red(poly p, int &len, NoroCache* cache,slimgb_alg* c); 2236 2237 static poly noro_red_mon(poly t, int &len, BOOLEAN& changed, NoroCache* cache,slimgb_alg* c){ 2238 BOOLEAN succ; 2239 //wrp(t); 2240 changed=TRUE; 2241 poly cache_lookup=cache->lookup(t,succ, len);//don't own this yet 2242 if (succ){ 2243 if (p_LmEqual(cache_lookup,t,c->r)){ 2244 //know they are equal 2245 len=1; 2246 changed=FALSE; 2247 return t; 2248 } 2249 poly t_new=ppMult_nn(cache_lookup,pGetCoeff(t)); 2250 pDelete(&t); 2251 return t_new; 2252 } else { 2253 unsigned long sev=p_GetShortExpVector(t,currRing); 2254 int i=kFindDivisibleByInS_easy(c->strat,t,sev); 2255 if (i>=0){ 2256 number coef_bak=pGetCoeff(t); 2257 if (!(npIsOne(coef_bak))){ 2258 number coef_inverse=npInvers(coef_bak); 2259 t=pMult_nn(t,coef_inverse); 2260 2261 } 2262 assume(npIsOne(p_GetCoeff(c->strat->S[i],c->r))); 2263 number coefstrat=p_GetCoeff(c->strat->S[i],c->r); 2264 //assume(nIsOne(coef)); 2265 2266 poly t_copy_mon=p_Copy(t,c->r); 2267 2268 2269 //TODO: t=spoly(t,..) 2270 p_ExpVectorSub(t,c->strat->S[i],c->r); 2271 p_SetCoeff(t,npNeg(npInvers(coefstrat)),c->r); 2272 p_Setm(t,c->r); 2273 assume(c->strat->S[i]!=NULL); 2274 poly t_to_del=t; 2275 t=pp_Mult_mm(pNext(c->strat->S[i]),t,c->r); 2276 p_Delete(&t_to_del,c->r); 2277 len=c->strat->lenS[i]-1; 2278 t=noro_red(t,len,cache,c); 2279 2280 2281 cache->insert(t_copy_mon,t,pLength(t)); 2282 p_Delete(&t_copy_mon,c->r); 2283 t=pMult_nn(t,coef_bak); 2284 return t; 2285 } else { 2286 number coef_bak=p_GetCoeff(t,c->r); 2287 number one=npInit(1); 2288 p_SetCoeff(t,one,c->r); 2289 len=1; 2290 cache->insert(t,t,len); 2291 p_SetCoeff(t,coef_bak,c->r); 2292 return t; 2293 } 2294 } 2295 } 2296 //len input and out: Idea: reverse addition 2297 static poly noro_red(poly p, int &len, NoroCache* cache,slimgb_alg* c){ 2298 assume(len==pLength(p)); 2299 poly orig_p=p; 2300 //poly* pre_buckets=(poly*) omalloc(len*sizeof(poly)); 2301 //int* pre_buckets_len=(int*) omalloc(len*sizeof(int)); 2302 //wrp(p); 2303 if (p==NULL) { 2304 len=0; 2305 return NULL; 2306 } 2307 kBucket_pt bucket=kBucketCreate(currRing); 2308 kBucketInit(bucket,NULL,0); 2309 int pos=0; 2310 poly unchanged_head=NULL; 2311 poly unchanged_tail=NULL; 2312 int unchanged_size=0; 2313 while(p){ 2314 poly t=p; 2315 pIter(p); 2316 pNext(t)=NULL; 2317 int l; 2318 //poly reference=p_Head(t,c->r); 2319 BOOLEAN changed; 2320 t=noro_red_mon(t,l,changed,cache,c); 2321 if (!(changed)){ 2322 unchanged_size++; 2323 if (unchanged_head){ 2324 pNext(unchanged_tail)=t; 2325 pIter(unchanged_tail); 2326 } else{ 2327 unchanged_tail=t; 2328 unchanged_head=t; 2329 } 2330 } else{ 2331 assume(l==pLength(t)); 2332 2333 kBucket_Add_q(bucket,t,&l); 2334 } 2335 //pre_buckets[pos]=t; 2336 //pre_buckets_len[pos++]=l; 2337 } 2338 //todo catch in general the length from cache 2339 2340 assume(pos==len); 2341 int i; 2342 //for(i=pos-1;i>=0;i--){ 2343 // kBucket_Add_q(bucket,pre_buckets[i],&pre_buckets_len[i]); 2344 //} 2345 poly res; 2346 len=0; 2347 kBucket_Add_q(bucket,unchanged_head,&unchanged_size); 2348 kBucketClear(bucket,&res,&len); 2349 kBucketDestroy(&bucket); 2350 //omfree(pre_buckets); 2351 //omfree(pre_buckets_len); 2352 return res; 2353 } 2354 #endif 2355 2184 2356 static void noro_step(poly*p,int &pn,slimgb_alg* c){ 2185 2357 poly* reduced=(poly*) omalloc(pn*sizeof(poly)); … … 2187 2359 int* reduced_len=(int*) omalloc(pn*sizeof(int)); 2188 2360 int reduced_c=0; 2189 if (TEST_OPT_PROT) 2190 PrintS("reduced system:\n"); 2361 //if (TEST_OPT_PROT) 2362 // PrintS("reduced system:\n"); 2363 #ifdef NORO_CACHE 2364 NoroCache cache; 2365 #endif 2191 2366 for(j=0;j<pn;j++){ 2192 2367 2193 2368 poly h=p[j]; 2194 2369 int h_len=pLength(h); 2370 2195 2371 number coef; 2372 #ifndef NORO_CACHE 2196 2373 h=redNF2(p_Copy(h,c->r),c,h_len,coef,0); 2374 #else 2375 h=noro_red(p_Copy(h,c->r),h_len,&cache,c); 2376 assume(pLength(h)==h_len); 2377 #endif 2197 2378 if (h!=NULL){ 2379 #ifndef NORO_CACHE 2380 2198 2381 h=redNFTail(h,c->strat->sl,c->strat,h_len); 2199 2382 h_len=pLength(h); 2383 #endif 2384 2385 2200 2386 reduced[reduced_c]=h; 2201 2387 reduced_len[reduced_c]=h_len; … … 2234 2420 pn=rank; 2235 2421 omfree(reduced); 2422 2236 2423 if (TEST_OPT_PROT) 2237 2424 PrintS("\n"); -
kernel/tgb_internal.h
r19370c r89b59f 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* $Id: tgb_internal.h,v 1. 49 2007-02-06 09:59:01bricken Exp $ */7 /* $Id: tgb_internal.h,v 1.50 2007-02-07 12:39:56 bricken Exp $ */ 8 8 /* 9 9 * ABSTRACT: tgb internal .h file … … 18 18 #include "polys.h" 19 19 #include "stdlib.h" 20 //#define USE_NORO 1 20 #define USE_NORO 1 21 //#define NORO_CACHE 1 22 #ifdef NORO_CACHE 23 #include <map> 24 #include <vector> 25 #endif 21 26 #ifdef HAVE_BOOST_DYNAMIC_BITSET_HPP 22 27 #define HAVE_BOOST 1 … … 57 62 //#define REDTAIL_PROT 58 63 //#define QUICK_SPOLY_TEST 64 class PolySimple{ 65 public: 66 PolySimple(poly p){ 67 impl=p; 68 } 69 PolySimple(){ 70 impl=NULL; 71 } 72 PolySimple(const PolySimple& a){ 73 //impl=p_Copy(a.impl,currRing); 74 impl=a.impl; 75 } 76 PolySimple& operator=(const PolySimple& p2){ 77 //p_Delete(&impl,currRing); 78 //impl=p_Copy(p2.impl,currRing); 79 impl=p2.impl; 80 return *this; 81 } 82 ~PolySimple(){ 83 //p_Delete(&impl,currRing); 84 } 85 bool operator< (const PolySimple& other) const{ 86 return pLmCmp(impl,other.impl)<0; 87 } 88 bool operator==(const PolySimple& other){ 89 return pLmEqual(impl,other.impl); 90 } 91 poly impl; 92 93 }; 59 94 struct sorted_pair_node{ 60 95 //criterium, which is stable 0. small lcm 1. small i 2. small j
Note: See TracChangeset
for help on using the changeset viewer.