Changeset 421e42 in git
- Timestamp:
- Feb 20, 2007, 4:11:04 PM (16 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- 82244545f2799f63a8fa69c4b3834e3c23f6121c
- Parents:
- e01da414af20c998b1409ca8f11bd4ff098033bc
- Location:
- kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/tgb.cc
re01da4 r421e42 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* $Id: tgb.cc,v 1.14 0 2007-02-20 10:47:45bricken Exp $ */7 /* $Id: tgb.cc,v 1.141 2007-02-20 15:11:03 bricken Exp $ */ 8 8 /* 9 9 * ABSTRACT: slimgb and F4 implementation … … 32 32 #define BUCKETS_FOR_NORO_RED 1 33 33 #define SR_HDL(A) ((long)(A)) 34 static const int bundle_size=100 0;34 static const int bundle_size=100; 35 35 static const int bundle_size_noro=1000; 36 36 static const int delay_factor=3; … … 1933 1933 } 1934 1934 }else { 1935 assume(FALSE);1935 //assume(FALSE); 1936 1936 for(i=start;i<=lastIndex;i++){ 1937 1937 other_row_array[i]=npAdd(npMult(coef2,row_array[i]),other_row_array[i]); … … 2312 2312 term_index=-1; 2313 2313 } 2314 ~DataNoroCacheNode(){ 2314 #ifdef NORO_SPARSE_ROWS_PRE 2315 DataNoroCacheNode(SparseRow* row){ 2316 if (row!=NULL) 2317 value_len=row->len; 2318 else 2319 value_len=0; 2320 value_poly=NULL; 2321 this->row=row; 2322 term_index=-1; 2323 } 2324 #endif 2325 ~DataNoroCacheNode( 2326 ){ 2315 2327 //p_Delete(&value_poly,currRing); 2316 2328 if (row) delete row; … … 2354 2366 //impl[term]=std::pair<PolySimple,int> (nf,len); 2355 2367 } 2368 #ifdef NORO_SPARSE_ROWS_PRE 2369 DataNoroCacheNode* insert(poly term, SparseRow* srow){ 2370 //assume(impl.find(p_Copy(term,currRing))==impl.end()); 2371 //assume(len==pLength(nf)); 2372 2373 return treeInsert(term,srow); 2374 2375 2376 //impl[term]=std::pair<PolySimple,int> (nf,len); 2377 } 2378 #endif 2356 2379 DataNoroCacheNode* insertAndTransferOwnerShip(poly t, ring r){ 2380 2381 ressources.push_back(t); 2382 DataNoroCacheNode* res=treeInsertBackLink(t); 2383 res->term_index=nIrreducibleMonomials; 2357 2384 nIrreducibleMonomials++; 2358 ressources.push_back(t); 2359 return treeInsertBackLink(t); 2385 return res; 2360 2386 } 2361 2387 poly lookup(poly term, BOOLEAN& succ, int & len); … … 2406 2432 return (DataNoroCacheNode*) parent->setNode(p_GetExp(term,nvars,currRing),new DataNoroCacheNode(nf,len)); 2407 2433 } 2434 #ifdef NORO_SPARSE_ROWS_PRE 2435 DataNoroCacheNode* treeInsert(poly term,SparseRow* srow){ 2436 int i; 2437 nReducibleMonomials++; 2438 int nvars=pVariables; 2439 NoroCacheNode* parent=&root; 2440 for(i=1;i<nvars;i++){ 2441 parent=parent->getOrInsertBranch(p_GetExp(term,i,currRing)); 2442 } 2443 return (DataNoroCacheNode*) parent->setNode(p_GetExp(term,nvars,currRing),new DataNoroCacheNode(srow)); 2444 } 2445 #endif 2408 2446 DataNoroCacheNode* treeInsertBackLink(poly term){ 2409 2447 int i; … … 2645 2683 return res_holder; 2646 2684 } 2647 //poly t_new=ppMult_nn(cache_lookup,pGetCoeff(t)); 2685 2648 2686 res_holder.coef=p_GetCoeff(t,c->r); 2649 2687 p_Delete(&t,c->r); 2650 //res_holder.len=1; 2651 //res_holder.changed=TRUE; 2688 2652 2689 res_holder.p=cache_lookup; 2653 2690 2654 2691 res_holder.onlyBorrowed=TRUE; 2655 2692 return res_holder; 2656 //return t_new; 2693 2657 2694 } 2658 2695 } … … 2728 2765 if (ref!=NULL){ 2729 2766 2730 /*if (res_holder.len==NoroCache::backLinkCode){ 2731 res_holder.len=1; 2732 2733 2734 }*/ 2767 2735 2768 res_holder.coef=p_GetCoeff(t,c->r); 2736 2769 … … 2749 2782 number coefstrat=p_GetCoeff(c->strat->S[i],c->r); 2750 2783 2751 //poly t_copy_mon=p_Copy(t,c->r); 2784 2752 2785 poly exp_diff=cache->temp_term; 2753 2786 p_ExpVectorDiff(exp_diff,t,c->strat->S[i],c->r); … … 2755 2788 p_Setm(exp_diff,c->r); 2756 2789 assume(c->strat->S[i]!=NULL); 2757 //poly t_to_del=t; 2790 2758 2791 poly res; 2759 2792 res=pp_Mult_mm(pNext(c->strat->S[i]),exp_diff,c->r); … … 2762 2795 SparseRow* srow; 2763 2796 srow=noro_red_to_non_poly(res,len,cache,c); 2764 2765 //DataNoroCacheNode* ref=cache->insert(t,srow); 2797 ref=cache->insert(t,srow); 2766 2798 p_Delete(&t,c->r); 2767 //p_Delete(&t_copy_mon,c->r);2768 //res=pMult_nn(res,coef_bak);2769 2799 2770 2800 … … 2779 2809 2780 2810 res_holder.ref=cache->insertAndTransferOwnerShip(t,c->r); 2811 assume(res_holder.ref!=NULL); 2781 2812 res_holder.coef=coef_bak; 2782 2813 … … 2871 2902 return NULL; 2872 2903 } 2873 number* temp_array=(number*) omalloc(cache->nIrreducibleMonomials*sizeof(number)); 2874 memset(temp_array,0,sizeof(number)*cache->nIrreducibleMonomials); 2904 2875 2905 2876 2906 MonRedResNP* mon=(MonRedResNP*) omalloc(len*sizeof(MonRedResNP)); … … 2890 2920 i++; 2891 2921 } 2922 2892 2923 assume(i==len); 2893 2924 len=i; 2925 //in the loop before nIrreducibleMonomials increases, so position here is important 2926 number* temp_array=(number*) omalloc(cache->nIrreducibleMonomials*sizeof(number)); 2927 int temp_size=cache->nIrreducibleMonomials; 2928 memset(temp_array,0,sizeof(number)*cache->nIrreducibleMonomials); 2894 2929 for(i=0;i<len;i++){ 2895 2930 MonRedResNP red=mon[i]; … … 2898 2933 SparseRow* row=red.ref->row; 2899 2934 number coef=red.coef; 2900 for(i=0;i<row->len;i++){ 2901 int idx=row->idx_array[i]; 2902 temp_array[idx]=npAdd(temp_array[idx],npMult(row->coef_array[i],coef)); 2935 int j; 2936 for(j=0;j<row->len;j++){ 2937 int idx=row->idx_array[j]; 2938 temp_array[idx]=npAdd(temp_array[idx],npMult(row->coef_array[j],coef)); 2939 assume(idx<temp_size); 2903 2940 } 2904 2941 } 2905 2942 else{ 2906 2943 if (red.ref->value_len==NoroCache::backLinkCode){ 2907 temp_array[red.ref->term_index]= red.coef;2944 temp_array[red.ref->term_index]=npAdd(temp_array[red.ref->term_index],red.coef); 2908 2945 } else { 2909 PrintS("third case\n");2946 //PrintS("third case\n"); 2910 2947 } 2911 2948 } 2912 2949 } 2913 2950 } 2914 2915 2916 2917 2918 2919 //TODO:return res; 2951 int non_zeros=0; 2952 for(i=0;i<cache->nIrreducibleMonomials;i++){ 2953 if (!(npIsZero(temp_array[i]))){ 2954 non_zeros++; 2955 } 2956 } 2957 SparseRow* res=new SparseRow(non_zeros); 2958 int pos=0; 2959 for(i=0;i<cache->nIrreducibleMonomials;i++){ 2960 if (!(npIsZero(temp_array[i]))){ 2961 2962 res->idx_array[pos]=i; 2963 res->coef_array[pos]=temp_array[i]; 2964 2965 pos++; 2966 } 2967 2968 } 2969 omfree(temp_array); 2970 2971 omfree(mon); 2972 return res; 2920 2973 } 2921 2974 #endif … … 3037 3090 3038 3091 NoroCache cache; 3039 3092 #ifndef NORO_NON_POLY 3040 3093 std::vector<std::vector<NoroPlaceHolder> > place_holders(pn); 3094 #else 3095 SparseRow** srows=(SparseRow**) omalloc(pn*sizeof(SparseRow*)); 3096 #endif 3041 3097 for(j=0;j<pn;j++){ 3042 3098 … … 3044 3100 int h_len=pLength(h); 3045 3101 3046 number coef;3047 3048 3102 //number coef; 3103 3104 #ifndef NORO_NON_POLY 3049 3105 std::vector<NoroPlaceHolder> ph=noro_red(h,h_len,&cache,c); 3050 3106 place_holders[j]=ph; 3107 #else 3108 srows[j]=noro_red_to_non_poly(h,h_len,&cache,c); 3109 #endif 3051 3110 } 3052 3111 std::vector<DataNoroCacheNode*> irr_nodes; … … 3073 3132 qsort(term_nodes,n,sizeof(TermNoroDataNode),term_nodes_sort_crit); 3074 3133 poly* terms=(poly*) omalloc(n*sizeof(poly)); 3134 #ifndef NORO_NON_POLY 3075 3135 for(j=0;j<n;j++){ 3076 3136 term_nodes[j].node->term_index=j; 3077 3137 terms[j]=term_nodes[j].t; 3078 3138 } 3139 #else 3140 int* old_to_new_indices=(int*) omalloc(cache.nIrreducibleMonomials*sizeof(int)); 3141 for(j=0;j<n;j++){ 3142 old_to_new_indices[term_nodes[j].node->term_index]=j; 3143 term_nodes[j].node->term_index=j; 3144 terms[j]=term_nodes[j].t; 3145 } 3146 #endif 3079 3147 if (TEST_OPT_PROT) 3080 3148 Print("Evaluate Rows \n"); 3149 #ifndef NORO_NON_POLY 3081 3150 cache.evaluateRows(); 3151 #endif 3082 3152 number* number_array=(number*) omalloc(n*pn*sizeof(number)); 3153 memset(number_array,0,sizeof(number)*n*pn); 3083 3154 number zero=npInit(0); 3084 3155 if (TEST_OPT_PROT) … … 3087 3158 int i; 3088 3159 number* row=number_array+n*j; 3089 for(i=0;i<n;i++){3160 /*for(i=0;i<n;i++){ 3090 3161 row[i]=zero; 3091 } 3162 }*/ 3163 #ifndef NORO_NON_POLY 3092 3164 cache.evaluatePlaceHolder(row,place_holders[j]); 3165 #else 3166 SparseRow* srow=srows[j]; 3167 for(i=0;i<srow->len;i++){ 3168 int idx=old_to_new_indices[srow->idx_array[i]]; 3169 row[idx]=srow->coef_array[i]; 3170 } 3171 delete srow; 3172 #endif 3093 3173 } 3094 3174 … … 3108 3188 omfree(term_nodes); 3109 3189 omfree(number_array); 3190 #ifdef NORO_NON_POLY 3191 omfree(srows); 3192 omfree(old_to_new_indices); 3193 #endif 3110 3194 //don't forget the rank 3111 3195 -
kernel/tgb_internal.h
re01da4 r421e42 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* $Id: tgb_internal.h,v 1.5 4 2007-02-20 10:47:46bricken Exp $ */7 /* $Id: tgb_internal.h,v 1.55 2007-02-20 15:11:04 bricken Exp $ */ 8 8 /* 9 9 * ABSTRACT: tgb internal .h file … … 20 20 //#define USE_NORO 1 21 21 //#define NORO_CACHE 1 22 #define NORO_SPARSE_ROWS_PRE 1 22 //#define NORO_SPARSE_ROWS_PRE 1 23 //#define NORO_NON_POLY 1 23 24 #ifdef NORO_CACHE 24 25 //#include <map>
Note: See TracChangeset
for help on using the changeset viewer.