Changeset 8120f8 in git
- Timestamp:
- Feb 26, 2007, 11:57:39 AM (16 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- f529246505a5d745330cbb08ffc3f1db543d3ed3
- Parents:
- 74802b0c748389d7b2662b157bcd57bbbe13eb0d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/tgb_internal.h
r74802b r8120f8 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* $Id: tgb_internal.h,v 1.6 3 2007-02-25 09:40:24bricken Exp $ */7 /* $Id: tgb_internal.h,v 1.64 2007-02-26 10:57:39 bricken Exp $ */ 8 8 /* 9 9 * ABSTRACT: tgb internal .h file … … 26 26 #define NORO_SPARSE_ROWS_PRE 1 27 27 #define NORO_NON_POLY 1 28 #include <algorithm> 28 29 #endif 29 30 #ifdef NORO_CACHE … … 763 764 SparseRow<number_type>* res=new SparseRow<number_type>(non_zeros); 764 765 //int pos=0; 766 //Print("denseness:%f\n",((double) non_zeros/(double) temp_size)); 765 767 number_type* it_coef=res->coef_array; 766 768 int* it_idx=res->idx_array; … … 819 821 return res; 820 822 } 821 template <class number_type> void add_coef_times_sparse(number_type* temp_array,int temp_size,SparseRow<number_type>* row, number coef){823 template <class number_type> void add_coef_times_sparse(number_type* const temp_array,int temp_size,SparseRow<number_type>* row, number coef){ 822 824 int j; 823 for(j=0;j<row->len;j++){ 824 int idx=row->idx_array[j]; 825 number_type* const coef_array=row->coef_array; 826 int* const idx_array=row->idx_array; 827 const int len=row->len; 828 for(j=0;j<len;j++){ 829 int idx=idx_array[j]; 825 830 assume(!(npIsZero(coef))); 826 assume(!(npIsZero((number) row->coef_array[j])));827 temp_array[idx]=F4mat_to_number_type(npAddM((number) temp_array[idx],npMultM((number) row->coef_array[j],coef)));831 assume(!(npIsZero((number) coef_array[j]))); 832 temp_array[idx]=F4mat_to_number_type(npAddM((number) temp_array[idx],npMultM((number) coef_array[j],coef))); 828 833 assume(idx<temp_size); 829 834 } 835 } 836 template <class number_type> void add_sparse(number_type* const temp_array,int temp_size,SparseRow<number_type>* row){ 837 int j; 838 839 number_type* const coef_array=row->coef_array; 840 int* const idx_array=row->idx_array; 841 const int len=row->len; 842 for(j=0;j<len;j++){ 843 int idx=idx_array[j]; 844 temp_array[idx]=F4mat_to_number_type( npAddM((number) temp_array[idx],(number) coef_array[j])); 845 assume(idx<temp_size); 846 } 847 } 848 template <class number_type> void sub_sparse(number_type* const temp_array,int temp_size,SparseRow<number_type>* row){ 849 int j; 850 851 number_type* const coef_array=row->coef_array; 852 int* const idx_array=row->idx_array; 853 const int len=row->len; 854 for(j=0;j<len;j++){ 855 int idx=idx_array[j]; 856 temp_array[idx]=F4mat_to_number_type( npSubM((number) temp_array[idx],(number) coef_array[j])); 857 assume(idx<temp_size); 858 } 859 } 860 template <class number_type> SparseRow<number_type>* noro_red_to_non_poly_dense(MonRedResNP<number_type>* mon, int len,NoroCache<number_type>* cache){ 861 size_t temp_size_bytes=cache->nIrreducibleMonomials*sizeof(number_type)+8;//use 8bit int for testing 862 assume(sizeof(int64)==8); 863 cache->ensureTempBufferSize(temp_size_bytes); 864 number_type* temp_array=(number_type*) cache->tempBuffer;//omalloc(cache->nIrreducibleMonomials*sizeof(number_type)); 865 int temp_size=cache->nIrreducibleMonomials; 866 memset(temp_array,0,temp_size_bytes); 867 number minus_one=npInit(-1); 868 int i; 869 for(i=0;i<len;i++){ 870 MonRedResNP<number_type> red=mon[i]; 871 if ((red.ref)){ 872 if (red.ref->row){ 873 SparseRow<number_type>* row=red.ref->row; 874 number coef=red.coef; 875 int j; 876 if (!((coef==(number) 1)||(coef==minus_one))){ 877 add_coef_times_sparse(temp_array,temp_size,row,coef); 878 879 880 881 }else{ 882 if (coef==(number) 1){ 883 add_sparse(temp_array,temp_size,row); 884 } else { 885 886 sub_sparse(temp_array,temp_size,row); 887 } 888 } 889 } 890 else{ 891 if (red.ref->value_len==NoroCache<number_type>::backLinkCode){ 892 temp_array[red.ref->term_index]=F4mat_to_number_type( npAddM((number) temp_array[red.ref->term_index],red.coef)); 893 } else { 894 //PrintS("third case\n"); 895 } 896 } 897 } 898 } 899 int non_zeros=0; 900 for(i=0;i<cache->nIrreducibleMonomials;i++){ 901 //if (!(temp_array[i]==0)){ 902 // non_zeros++; 903 //} 904 assume(((temp_array[i]!=0)==0)|| (((temp_array[i]!=0)==1))); 905 non_zeros+=(temp_array[i]!=0); 906 } 907 908 if (non_zeros==0){ 909 //omfree(mon); 910 return NULL; 911 } 912 SparseRow<number_type>* res=convert_to_sparse_row(temp_array,temp_size, non_zeros); 913 914 //omfree(temp_array); 915 916 917 return res; 918 } 919 template<class number_type> class CoefIdx{ 920 public: 921 number_type coef; 922 int idx; 923 bool operator<(const CoefIdx<number_type>& other) const{ 924 return idx<other.idx; 925 } 926 }; 927 template <class number_type> SparseRow<number_type>* noro_red_to_non_poly_sparse(MonRedResNP<number_type>* mon, int len,NoroCache<number_type>* cache){ 928 int i; 929 int together=0; 930 for(i=0;i<len;i++){ 931 MonRedResNP<number_type> red=mon[i]; 932 if ((red.ref) &&( red.ref->row)){ 933 together+=red.ref->row->len; 934 } else {if ((red.ref) &&(red.ref->value_len==NoroCache<number_type>::backLinkCode)) 935 together++; 936 } 937 938 } 939 //PrintS("here\n"); 940 if (together==0) return 0; 941 //PrintS("there\n"); 942 cache->ensureTempBufferSize(together*sizeof(CoefIdx<number_type>)); 943 CoefIdx<number_type>* pairs=(CoefIdx<number_type>*) cache->tempBuffer; //omalloc(together*sizeof(CoefIdx<number_type>)); 944 int pos=0; 945 int j; 946 for(i=0;i<len;i++){ 947 MonRedResNP<number_type> red=mon[i]; 948 if ((red.ref) &&( red.ref->row)){ 949 //together+=red.ref->row->len; 950 int* idx_array=red.ref->row->idx_array; 951 number_type* coef_array=red.ref->row->coef_array; 952 int rlen=red.ref->row->len; 953 for(j=0;j<rlen;j++){ 954 assume(coef_array[j]!=0); 955 CoefIdx<number_type> ci; 956 ci.coef=F4mat_to_number_type(npMultM((number) red.coef,(number) coef_array[j])); 957 ci.idx=idx_array[j]; 958 pairs[pos++]=ci; 959 } 960 } else { 961 if ((red.ref) &&(red.ref->value_len==NoroCache<number_type>::backLinkCode)){ 962 CoefIdx<number_type> ci; 963 ci.coef=F4mat_to_number_type(red.coef); 964 ci.idx=red.ref->term_index; 965 pairs[pos++]=ci; 966 } 967 } 968 } 969 assume(pos==together); 970 std::sort(pairs,pairs+together); 971 972 int act=0; 973 974 assume(pairs[0].coef!=0); 975 for(i=1;i<together;i++){ 976 if (pairs[i].idx!=pairs[act].idx){ 977 if (pairs[act].coef!=0){ 978 act=act+1; 979 } 980 pairs[act]=pairs[i]; 981 } else{ 982 pairs[act].coef=F4mat_to_number_type(npAddM((number)pairs[act].coef,(number)pairs[i].coef)); 983 } 984 } 985 986 if (pairs[act].coef==0){ 987 988 act--; 989 } 990 int sparse_row_len=act+1; 991 //Print("res len:%d",sparse_row_len); 992 if (sparse_row_len==0) {return NULL;} 993 SparseRow<number_type>* res=new SparseRow<number_type>(sparse_row_len); 994 { 995 number_type* coef_array=res->coef_array; 996 int* idx_array=res->idx_array; 997 for(i=0;i<sparse_row_len;i++){ 998 idx_array[i]=pairs[i].idx; 999 coef_array[i]=pairs[i].coef; 1000 } 1001 } 1002 //omfree(pairs); 1003 1004 return res; 830 1005 } 831 1006 template<class number_type> SparseRow<number_type> * noro_red_to_non_poly_t(poly p, int &len, NoroCache<number_type>* cache,slimgb_alg* c){ … … 840 1015 MonRedResNP<number_type>* mon=(MonRedResNP<number_type>*) omalloc(len*sizeof(MonRedResNP<number_type>)); 841 1016 int i=0; 842 1017 double max_density=0.0; 843 1018 while(p){ 844 1019 … … 851 1026 #endif 852 1027 MonRedResNP<number_type> red=noro_red_mon_to_non_poly(t,cache,c); 1028 if ((red.ref) && (red.ref->row)){ 1029 double act_density=(double) red.ref->row->len; 1030 act_density/=(double) cache->nIrreducibleMonomials; 1031 max_density=si_max(act_density,max_density); 1032 } 853 1033 mon[i]=red; 854 1034 i++; … … 857 1037 assume(i==len); 858 1038 len=i; 1039 bool dense=true; 1040 if (max_density<0.1) dense=false; 1041 if (dense){ 1042 SparseRow<number_type>* res=noro_red_to_non_poly_dense(mon,len,cache); 1043 omfree(mon); 1044 return res; 1045 } else { 1046 SparseRow<number_type>* res=noro_red_to_non_poly_sparse(mon,len,cache); 1047 omfree(mon); 1048 return res; 1049 } 859 1050 //in the loop before nIrreducibleMonomials increases, so position here is important 860 size_t temp_size_bytes=cache->nIrreducibleMonomials*sizeof(number_type)+8;//use 8bit int for testing 861 assume(sizeof(int64)==8); 862 cache->ensureTempBufferSize(temp_size_bytes); 863 number_type* temp_array=(number_type*) cache->tempBuffer;//omalloc(cache->nIrreducibleMonomials*sizeof(number_type)); 864 int temp_size=cache->nIrreducibleMonomials; 865 memset(temp_array,0,temp_size_bytes); 866 number minus_one=npInit(-1); 867 for(i=0;i<len;i++){ 868 MonRedResNP<number_type> red=mon[i]; 869 if ((red.ref)){ 870 if (red.ref->row){ 871 SparseRow<number_type>* row=red.ref->row; 872 number coef=red.coef; 873 int j; 874 if (!((coef==(number) 1)||(coef==minus_one))){ 875 add_coef_times_sparse(temp_array,temp_size,row,coef); 876 877 878 879 }else{ 880 if (coef==(number) 1){ 881 for(j=0;j<row->len;j++){ 882 int idx=row->idx_array[j]; 883 temp_array[idx]=F4mat_to_number_type( npAddM((number) temp_array[idx],(number) row->coef_array[j])); 884 assume(idx<temp_size); 885 } 886 } else { 887 for(j=0;j<row->len;j++){ 888 int idx=row->idx_array[j]; 889 temp_array[idx]=F4mat_to_number_type( npSubM((number) temp_array[idx],(number) row->coef_array[j])); 890 assume(idx<temp_size); 891 }} 892 } 893 } 894 else{ 895 if (red.ref->value_len==NoroCache<number_type>::backLinkCode){ 896 temp_array[red.ref->term_index]=F4mat_to_number_type( npAddM((number) temp_array[red.ref->term_index],red.coef)); 897 } else { 898 //PrintS("third case\n"); 899 } 900 } 901 } 902 } 903 int non_zeros=0; 904 for(i=0;i<cache->nIrreducibleMonomials;i++){ 905 //if (!(temp_array[i]==0)){ 906 // non_zeros++; 907 //} 908 assume(((temp_array[i]!=0)==0)|| (((temp_array[i]!=0)==1))); 909 non_zeros+=(temp_array[i]!=0); 910 } 911 912 if (non_zeros==0){ 913 omfree(mon); 914 return NULL; 915 } 916 SparseRow<number_type>* res=convert_to_sparse_row(temp_array,temp_size, non_zeros); 917 918 //omfree(temp_array); 919 920 omfree(mon); 921 return res; 1051 922 1052 } 923 1053 #endif … … 1273 1403 1274 1404 SparseRow<number_type>* srow=srows[j]; 1405 1275 1406 if (srow){ 1276 for(i=0;i<srow->len;i++){ 1277 int idx=old_to_new_indices[srow->idx_array[i]]; 1278 row[idx]=F4mat_to_number_type(srow->coef_array[i]); 1407 int* const idx_array=srow->idx_array; 1408 number_type* const coef_array=srow->coef_array; 1409 const int len=srow->len; 1410 for(i=0;i<len;i++){ 1411 int idx=old_to_new_indices[idx_array[i]]; 1412 row[idx]=F4mat_to_number_type(coef_array[i]); 1279 1413 } 1280 1414 delete srow;
Note: See TracChangeset
for help on using the changeset viewer.