Changeset 3a2985 in git
 Timestamp:
 Feb 27, 2007, 11:12:14 AM (16 years ago)
 Branches:
 (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
 Children:
 cb1222e9d011def1f666d962b393df0671f6b3d5
 Parents:
 b66eebb6e0a7103993fe517afda97ee69c1a82a1
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

kernel/tgb_internal.h
rb66eeb r3a2985 5 5 * Computer Algebra System SINGULAR * 6 6 ****************************************/ 7 /* $Id: tgb_internal.h,v 1.6 7 20070227 08:03:44 bricken Exp $ */7 /* $Id: tgb_internal.h,v 1.68 20070227 10:12:14 bricken Exp $ */ 8 8 /* 9 9 * ABSTRACT: tgb internal .h file … … 482 482 coef_array=(number_type*) omalloc(n*sizeof(number_type)); 483 483 } 484 SparseRow<number_type>(int n, const number_type* source){ 485 len=n; 486 idx_array=NULL; 487 coef_array=(number_type*) omalloc(n*sizeof(number_type)); 488 memcpy(coef_array,source,n*sizeof(number_type)); 489 } 484 490 ~SparseRow<number_type>(){ 485 491 omfree(idx_array); … … 856 862 } 857 863 } 864 template <class number_type> void add_coef_times_dense(number_type* const temp_array, 865 int temp_size,const number_type* row, int len,number coef){ 866 int j; 867 const number_type* const coef_array=row; 868 //int* const idx_array=row>idx_array; 869 //const int len=temp_size; 870 tgb_uint32 buffer[256]; 871 const tgb_uint32 prime=npPrimeM; 872 const tgb_uint32 c=F4mat_to_number_type(coef); 873 assume(!(npIsZero(coef))); 874 for(j=0;j<len;j=j+256){ 875 const int bound=std::min(j+256,len); 876 int i; 877 int bpos=0; 878 for(i=j;i<bound;i++){ 879 buffer[bpos++]=coef_array[i]; 880 } 881 int bpos_bound=boundj; 882 for(i=0;i<bpos_bound;i++){ 883 buffer[i]*=c; 884 } 885 for(i=0;i<bpos_bound;i++){ 886 buffer[i]=buffer[i]%prime; 887 } 888 bpos=0; 889 for(i=j;i<bound;i++){ 890 //int idx=idx_array[i]; 891 assume(bpos<256); 892 //assume(!(npIsZero((number) buffer[bpos]))); 893 temp_array[i]=F4mat_to_number_type(npAddM((number) temp_array[i], (number) buffer[bpos++])); 894 assume(i<temp_size); 895 } 896 897 } 898 } 899 template <class number_type> void add_dense(number_type* const temp_array, 900 int temp_size,const number_type* row, int len){ 901 //int j; 902 const number_type* const coef_array=row; 903 //int* const idx_array=row>idx_array; 904 //const int len=temp_size; 905 tgb_uint32 buffer[256]; 906 const tgb_uint32 prime=npPrimeM; 907 //const tgb_uint32 c=F4mat_to_number_type(coef); 908 909 int i; 910 for(i=0;i<len;i++){ 911 912 temp_array[i]=F4mat_to_number_type(npAddM((number) temp_array[i], (number) row[i])); 913 assume(i<temp_size); 914 } 915 916 } 917 template <class number_type> void sub_dense(number_type* const temp_array, 918 int temp_size,const number_type* row, int len){ 919 //int j; 920 const number_type* const coef_array=row; 921 //int* const idx_array=row>idx_array; 922 //const int len=temp_size; 923 tgb_uint32 buffer[256]; 924 const tgb_uint32 prime=npPrimeM; 925 //const tgb_uint32 c=F4mat_to_number_type(coef); 926 927 int i; 928 for(i=0;i<len;i++){ 929 930 temp_array[i]=F4mat_to_number_type(npSubM((number) temp_array[i], (number) row[i])); 931 assume(i<temp_size); 932 } 933 934 } 935 858 936 template <class number_type> void add_sparse(number_type* const temp_array,int temp_size,SparseRow<number_type>* row){ 859 937 int j; … … 896 974 number coef=red.coef; 897 975 int j; 976 if (row>idx_array){ 898 977 if (!((coef==(number) 1)(coef==minus_one))){ 899 978 add_coef_times_sparse(temp_array,temp_size,row,coef); … … 909 988 } 910 989 } 990 } else 991 //TODO: treat, 1,1 992 if (!((coef==(number) 1)(coef==minus_one))){ 993 add_coef_times_dense(temp_array,temp_size,row>coef_array,row>len,coef); 994 } else { 995 if (coef==(number)1) 996 add_dense(temp_array,temp_size,row>coef_array,row>len); 997 else{ 998 assume(coef==minus_one); 999 sub_dense(temp_array,temp_size,row>coef_array,row>len); 1000 //add_coef_times_dense(temp_array,temp_size,row>coef_array,row>len,coef); 1001 } 911 1002 } 1003 } 1004 912 1005 else{ 913 1006 if (red.ref>value_len==NoroCache<number_type>::backLinkCode){ … … 932 1025 return NULL; 933 1026 } 934 SparseRow<number_type>* res= convert_to_sparse_row(temp_array,temp_size, non_zeros);1027 SparseRow<number_type>* res=new SparseRow<number_type>(temp_size,temp_array);//convert_to_sparse_row(temp_array,temp_size, non_zeros); 935 1028 936 1029 //omfree(temp_array); … … 957 1050 } 958 1051 } 1052 template<class number_type> void write_coef_times_xx_idx_to_buffer_dense(CoefIdx<number_type>* const pairs,int& pos, number_type* const coef_array,const int rlen, const number coef){ 1053 int j; 1054 1055 for(j=0;j<rlen;j++){ 1056 if (coef_array[j]!=0){ 1057 assume(coef_array[j]!=0); 1058 CoefIdx<number_type> ci; 1059 ci.coef=F4mat_to_number_type(npMultM((number) coef,(number) coef_array[j])); 1060 assume(ci.coef!=0); 1061 ci.idx=j; 1062 pairs[pos++]=ci; 1063 } 1064 } 1065 } 959 1066 template<class number_type> void write_coef_idx_to_buffer(CoefIdx<number_type>* const pairs,int& pos,int* const idx_array, number_type* const coef_array,const int rlen){ 960 1067 int j; … … 980 1087 template <class number_type> SparseRow<number_type>* noro_red_to_non_poly_sparse(MonRedResNP<number_type>* mon, int len,NoroCache<number_type>* cache){ 981 1088 int i; 982 int together=0; 983 for(i=0;i<len;i++){ 984 MonRedResNP<number_type> red=mon[i]; 985 if ((red.ref) &&( red.ref>row)){ 986 together+=red.ref>row>len; 987 } else {if ((red.ref) &&(red.ref>value_len==NoroCache<number_type>::backLinkCode)) 1089 int together=0; 1090 for(i=0;i<len;i++){ 1091 MonRedResNP<number_type> red=mon[i]; 1092 if ((red.ref) &&( red.ref>row)){ 1093 together+=red.ref>row>len; 1094 } else { 1095 if ((red.ref) &&(red.ref>value_len==NoroCache<number_type>::backLinkCode)) 988 1096 together++; 1097 } 1098 1099 } 1100 //PrintS("here\n"); 1101 if (together==0) return 0; 1102 //PrintS("there\n"); 1103 cache>ensureTempBufferSize(together*sizeof(CoefIdx<number_type>)); 1104 CoefIdx<number_type>* pairs=(CoefIdx<number_type>*) cache>tempBuffer; //omalloc(together*sizeof(CoefIdx<number_type>)); 1105 int pos=0; 1106 int j; 1107 const number one=npInit(1); 1108 const number minus_one=npInit(1); 1109 for(i=0;i<len;i++){ 1110 MonRedResNP<number_type> red=mon[i]; 1111 if ((red.ref) &&( red.ref>row)){ 1112 //together+=red.ref>row>len; 1113 int* idx_array=red.ref>row>idx_array; 1114 number_type* coef_array=red.ref>row>coef_array; 1115 int rlen=red.ref>row>len; 1116 number coef=red.coef; 1117 if (idx_array){ 1118 if ((coef!=one)&&(coef!=minus_one)){ 1119 write_coef_times_xx_idx_to_buffer(pairs,pos,idx_array, coef_array,rlen, coef); 1120 } else 1121 { 1122 if (coef==one){ 1123 write_coef_idx_to_buffer(pairs,pos,idx_array, coef_array,rlen); 1124 } else { 1125 assume(coef==minus_one); 1126 write_minus_coef_idx_to_buffer(pairs,pos,idx_array, coef_array,rlen); 1127 } 1128 } 1129 } else{ 1130 write_coef_times_xx_idx_to_buffer_dense(pairs,pos,coef_array,rlen,coef); 989 1131 } 990 991 } 992 //PrintS("here\n"); 993 if (together==0) return 0; 994 //PrintS("there\n"); 995 cache>ensureTempBufferSize(together*sizeof(CoefIdx<number_type>)); 996 CoefIdx<number_type>* pairs=(CoefIdx<number_type>*) cache>tempBuffer; //omalloc(together*sizeof(CoefIdx<number_type>)); 997 int pos=0; 998 int j; 999 const number one=npInit(1); 1000 const number minus_one=npInit(1); 1001 for(i=0;i<len;i++){ 1002 MonRedResNP<number_type> red=mon[i]; 1003 if ((red.ref) &&( red.ref>row)){ 1004 //together+=red.ref>row>len; 1005 int* idx_array=red.ref>row>idx_array; 1006 number_type* coef_array=red.ref>row>coef_array; 1007 int rlen=red.ref>row>len; 1008 number coef=red.coef; 1009 if ((coef!=one)&&(coef!=minus_one)){ 1010 write_coef_times_xx_idx_to_buffer(pairs,pos,idx_array, coef_array,rlen, coef); 1011 } else 1012 { 1013 if (coef==one){ 1014 write_coef_idx_to_buffer(pairs,pos,idx_array, coef_array,rlen); 1015 } else { 1016 assume(coef==minus_one); 1017 write_minus_coef_idx_to_buffer(pairs,pos,idx_array, coef_array,rlen); 1018 } 1019 } 1020 } else { 1132 } 1133 else { 1021 1134 if ((red.ref) &&(red.ref>value_len==NoroCache<number_type>::backLinkCode)){ 1022 1135 CoefIdx<number_type> ci; … … 1027 1140 } 1028 1141 } 1029 assume(pos==together); 1142 assume(pos<=together); 1143 together=pos; 1144 1030 1145 std::sort(pairs,pairs+together); 1031 1146 1032 1147 int act=0; 1033 1148 1034 1149 assume(pairs[0].coef!=0); 1035 1150 for(i=1;i<together;i++){ … … 1043 1158 } 1044 1159 } 1045 1160 1046 1161 if (pairs[act].coef==0){ 1047 1162 1048 1163 act; 1049 1164 } … … 1061 1176 } 1062 1177 //omfree(pairs); 1063 1178 1064 1179 return res; 1065 1180 } … … 1098 1213 len=i; 1099 1214 bool dense=true; 1100 if (max_density<0. 05) dense=false;1215 if (max_density<0.2) dense=false; 1101 1216 if (dense){ 1102 1217 SparseRow<number_type>* res=noro_red_to_non_poly_dense(mon,len,cache); … … 1468 1583 number_type* const coef_array=srow>coef_array; 1469 1584 const int len=srow>len; 1470 for(i=0;i<len;i++){ 1471 int idx=old_to_new_indices[idx_array[i]]; 1472 row[idx]=F4mat_to_number_type(coef_array[i]); 1473 } 1474 delete srow; 1585 if (srow>idx_array){ 1586 for(i=0;i<len;i++){ 1587 int idx=old_to_new_indices[idx_array[i]]; 1588 row[idx]=F4mat_to_number_type(coef_array[i]); 1589 } 1590 } 1591 else { 1592 for(i=0;i<len;i++){ 1593 row[old_to_new_indices[i]]=F4mat_to_number_type(coef_array[i]); 1594 } 1595 } 1596 delete srow; 1475 1597 } 1476 1598 }
Note: See TracChangeset
for help on using the changeset viewer.