Changeset abce2e in git


Ignore:
Timestamp:
Feb 23, 2007, 10:07:41 AM (16 years ago)
Author:
Michael Brickenstein <bricken@…>
Branches:
(u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
Children:
5ac8e54b3b15118ff649cfabffd509d7b8c7ce26
Parents:
7b28960dda07617e698fc4f880aca3ceb0ffb191
Message:
*bricken: even more templates for noro


git-svn-id: file:///usr/local/Singular/svn/trunk@9888 2c84dea3-7e68-4137-9b89-c4e89433aadc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Singular/claptmpl.cc

    r7b2896 rabce2e  
    33*  Computer Algebra System SINGULAR     *
    44****************************************/
    5 // $Id: claptmpl.cc,v 1.40 2007-02-22 14:46:51 bricken Exp $
     5// $Id: claptmpl.cc,v 1.41 2007-02-23 09:07:41 bricken Exp $
    66/*
    77* ABSTRACT - instantiation of all templates
     
    236236template poly row_to_poly<tgb_uint32>(tgb_uint32* row, poly* terms, int tn, ring r);
    237237template poly row_to_poly<tgb_uint16>(tgb_uint16* row, poly* terms, int tn, ring r);
     238template void noro_step<tgb_uint8>(poly*p,int &pn,slimgb_alg* c);
     239template void noro_step<tgb_uint16>(poly*p,int &pn,slimgb_alg* c);
     240template void noro_step<tgb_uint32>(poly*p,int &pn,slimgb_alg* c);
    238241//std::priority_queue<MonRedRes>
    239242#endif
  • kernel/tgb.cc

    r7b2896 rabce2e  
    55*  Computer Algebra System SINGULAR     *
    66****************************************/
    7 /* $Id: tgb.cc,v 1.148 2007-02-23 08:34:40 bricken Exp $ */
     7/* $Id: tgb.cc,v 1.149 2007-02-23 09:07:40 bricken Exp $ */
    88/*
    99* ABSTRACT: slimgb and F4 implementation
     
    18651865  fclose(out);
    18661866}
    1867 typedef unsigned short number_type;
     1867//typedef unsigned short number_type;
    18681868
    18691869
     
    23932393SparseRow* noro_red_to_non_poly(poly p, int &len, NoroCache* cache,slimgb_alg* c){
    23942394  if (npPrimeM<255){
    2395     return noro_red_to_non_poly_t<unsigned char>(p,len,cache,c);
     2395    return noro_red_to_non_poly_t<tgb_uint8>(p,len,cache,c);
    23962396  } else {
    23972397    if (npPrimeM<65000){
    2398       return noro_red_to_non_poly_t<unsigned short>(p,len,cache,c);
     2398      return noro_red_to_non_poly_t<tgb_uint16>(p,len,cache,c);
    23992399    } else{
    2400       return noro_red_to_non_poly_t<unsigned int>(p,len,cache,c);
     2400      return noro_red_to_non_poly_t<tgb_uint32>(p,len,cache,c);
    24012401    }
    24022402  }
     
    25052505}
    25062506#else
    2507 class TermNoroDataNode{
    2508 public:
    2509   DataNoroCacheNode* node;
    2510   poly t;
    2511 };
    2512 static int term_nodes_sort_crit(const void* a, const void* b){
     2507
     2508int term_nodes_sort_crit(const void* a, const void* b){
    25132509  return -pLmCmp(((TermNoroDataNode*) a)->t,((TermNoroDataNode*) b)->t);
    25142510}
    25152511
    2516 void noro_step(poly*p,int &pn,slimgb_alg* c){
    2517   //Print("Input rows %d\n",pn);
    2518   int j;
    2519   if (TEST_OPT_PROT){
    2520     Print("Input rows %d\n",pn);
    2521   }
    2522 
    2523   NoroCache cache;
    2524 
    2525   SparseRow** srows=(SparseRow**) omalloc(pn*sizeof(SparseRow*));
    2526   int non_zeros=0;
    2527   for(j=0;j<pn;j++){
    2528    
    2529     poly h=p[j];
    2530     int h_len=pLength(h);
    2531 
    2532     //number coef;
    2533 
    2534 
    2535     srows[non_zeros]=noro_red_to_non_poly(h,h_len,&cache,c);
    2536     if (srows[non_zeros]!=NULL) non_zeros++;
    2537   }
    2538   std::vector<DataNoroCacheNode*> irr_nodes;
    2539   cache.collectIrreducibleMonomials(irr_nodes);
    2540   //now can build up terms array
    2541   //Print("historic irred Mon%d\n",cache.nIrreducibleMonomials);
    2542   int n=irr_nodes.size();//cache.countIrreducibleMonomials();
    2543   cache.nIrreducibleMonomials=n;
    2544   if (TEST_OPT_PROT){
    2545     Print("Irred Mon:%d\n",n);
    2546     Print("red Mon:%d\n",cache.nReducibleMonomials);
    2547   }
    2548   TermNoroDataNode* term_nodes=(TermNoroDataNode*) omalloc(n*sizeof(TermNoroDataNode));
    2549  
    2550   for(j=0;j<n;j++){
    2551     assume(irr_nodes[j]!=NULL);
    2552     assume(irr_nodes[j]->value_len==NoroCache::backLinkCode);
    2553     term_nodes[j].t=irr_nodes[j]->value_poly;
    2554     assume(term_nodes[j].t!=NULL);
    2555     term_nodes[j].node=irr_nodes[j];
    2556   }
    2557  
    2558  
    2559   qsort(term_nodes,n,sizeof(TermNoroDataNode),term_nodes_sort_crit);
    2560   poly* terms=(poly*) omalloc(n*sizeof(poly));
    2561 
    2562   int* old_to_new_indices=(int*) omalloc(cache.nIrreducibleMonomials*sizeof(int));
    2563   for(j=0;j<n;j++){
    2564     old_to_new_indices[term_nodes[j].node->term_index]=j;
    2565     term_nodes[j].node->term_index=j;
    2566     terms[j]=term_nodes[j].t;
    2567   }
    2568 
    2569   //if (TEST_OPT_PROT)
    2570   //  Print("Evaluate Rows \n");
    2571   pn=non_zeros;
    2572   number_type* number_array=(number_type*) omalloc(n*pn*sizeof(number_type));
    2573   memset(number_array,0,sizeof(number_type)*n*pn);
    2574   number zero=npInit(0);
    2575 
    2576   for(j=0;j<pn;j++){
    2577     int i;
    2578     number_type* row=number_array+n*j;
    2579     /*for(i=0;i<n;i++){
    2580       row[i]=zero;
    2581     }*/
    2582 
    2583     SparseRow* srow=srows[j];
    2584     if (srow){
    2585     for(i=0;i<srow->len;i++){
    2586       int idx=old_to_new_indices[srow->idx_array[i]];
    2587       row[idx]=F4mat_to_number_type(srow->coef_array[i]);
    2588     }
    2589     delete srow;
    2590     }
    2591   }
    2592  
    2593   static int export_n=0;
    2594   //export_mat(number_array,pn,n,"mat%i.py",++export_n);
    2595   simplest_gauss_modp(number_array,pn,n);
    2596 
    2597   int p_pos=0;
    2598   for(j=0;j<pn;j++){
    2599     poly h=row_to_poly(number_array+j*n,terms,n,c->r);
    2600     if(h!=NULL){
    2601       p[p_pos++]=h;
    2602     }
    2603   }
    2604   pn=p_pos;
    2605   omfree(terms);
    2606   omfree(term_nodes);
    2607   omfree(number_array);
    2608   #ifdef NORO_NON_POLY
    2609   omfree(srows);
    2610   omfree(old_to_new_indices);
    2611   #endif
    2612   //don't forget the rank
    2613  
    2614 }
     2512
    26152513#endif
    26162514#endif
     
    27082606  if (use_noro){
    27092607    int pn=i;
    2710     if (pn==0) return;
    2711     noro_step(p,pn,c);
     2608    if (pn==0) {omfree(p);return;}
     2609   
     2610    {
     2611     
     2612      if (npPrimeM<255){
     2613        noro_step<tgb_uint8>(p,pn,c);
     2614      } else {
     2615        if (npPrimeM<65000){
     2616          noro_step<tgb_uint16>(p,pn,c);
     2617        } else{
     2618          noro_step<tgb_uint32>(p,pn,c);
     2619        }
     2620      }
     2621     
     2622     
     2623     
     2624    }
     2625   
    27122626    if (TEST_OPT_PROT){
    27132627      Print("reported rank:%i\n",pn);
  • kernel/tgb_internal.h

    r7b2896 rabce2e  
    55*  Computer Algebra System SINGULAR     *
    66****************************************/
    7 /* $Id: tgb_internal.h,v 1.58 2007-02-23 08:34:40 bricken Exp $ */
     7/* $Id: tgb_internal.h,v 1.59 2007-02-23 09:07:41 bricken Exp $ */
    88/*
    99 * ABSTRACT: tgb internal .h file
     
    515515    if (row) delete row;
    516516  }
     517};
     518class TermNoroDataNode{
     519public:
     520  DataNoroCacheNode* node;
     521  poly t;
    517522};
    518523class NoroCache{
     
    10391044    PrintS("StopGauss\n");
    10401045}
    1041 #endif
    1042 
    1043 #endif
     1046int term_nodes_sort_crit(const void* a, const void* b);
     1047template <class number_type> void noro_step(poly*p,int &pn,slimgb_alg* c){
     1048  //Print("Input rows %d\n",pn);
     1049  int j;
     1050  if (TEST_OPT_PROT){
     1051    Print("Input rows %d\n",pn);
     1052  }
     1053
     1054  NoroCache cache;
     1055
     1056  SparseRow** srows=(SparseRow**) omalloc(pn*sizeof(SparseRow*));
     1057  int non_zeros=0;
     1058  for(j=0;j<pn;j++){
     1059   
     1060    poly h=p[j];
     1061    int h_len=pLength(h);
     1062
     1063    //number coef;
     1064
     1065
     1066    srows[non_zeros]=noro_red_to_non_poly_t<number_type>(h,h_len,&cache,c);
     1067    if (srows[non_zeros]!=NULL) non_zeros++;
     1068  }
     1069  std::vector<DataNoroCacheNode*> irr_nodes;
     1070  cache.collectIrreducibleMonomials(irr_nodes);
     1071  //now can build up terms array
     1072  //Print("historic irred Mon%d\n",cache.nIrreducibleMonomials);
     1073  int n=irr_nodes.size();//cache.countIrreducibleMonomials();
     1074  cache.nIrreducibleMonomials=n;
     1075  if (TEST_OPT_PROT){
     1076    Print("Irred Mon:%d\n",n);
     1077    Print("red Mon:%d\n",cache.nReducibleMonomials);
     1078  }
     1079  TermNoroDataNode* term_nodes=(TermNoroDataNode*) omalloc(n*sizeof(TermNoroDataNode));
     1080 
     1081  for(j=0;j<n;j++){
     1082    assume(irr_nodes[j]!=NULL);
     1083    assume(irr_nodes[j]->value_len==NoroCache::backLinkCode);
     1084    term_nodes[j].t=irr_nodes[j]->value_poly;
     1085    assume(term_nodes[j].t!=NULL);
     1086    term_nodes[j].node=irr_nodes[j];
     1087  }
     1088 
     1089 
     1090  qsort(term_nodes,n,sizeof(TermNoroDataNode),term_nodes_sort_crit);
     1091  poly* terms=(poly*) omalloc(n*sizeof(poly));
     1092
     1093  int* old_to_new_indices=(int*) omalloc(cache.nIrreducibleMonomials*sizeof(int));
     1094  for(j=0;j<n;j++){
     1095    old_to_new_indices[term_nodes[j].node->term_index]=j;
     1096    term_nodes[j].node->term_index=j;
     1097    terms[j]=term_nodes[j].t;
     1098  }
     1099
     1100  //if (TEST_OPT_PROT)
     1101  //  Print("Evaluate Rows \n");
     1102  pn=non_zeros;
     1103  number_type* number_array=(number_type*) omalloc(n*pn*sizeof(number_type));
     1104  memset(number_array,0,sizeof(number_type)*n*pn);
     1105  number zero=npInit(0);
     1106
     1107  for(j=0;j<pn;j++){
     1108    int i;
     1109    number_type* row=number_array+n*j;
     1110    /*for(i=0;i<n;i++){
     1111      row[i]=zero;
     1112    }*/
     1113
     1114    SparseRow* srow=srows[j];
     1115    if (srow){
     1116    for(i=0;i<srow->len;i++){
     1117      int idx=old_to_new_indices[srow->idx_array[i]];
     1118      row[idx]=F4mat_to_number_type(srow->coef_array[i]);
     1119    }
     1120    delete srow;
     1121    }
     1122  }
     1123 
     1124  static int export_n=0;
     1125  //export_mat(number_array,pn,n,"mat%i.py",++export_n);
     1126  simplest_gauss_modp(number_array,pn,n);
     1127
     1128  int p_pos=0;
     1129  for(j=0;j<pn;j++){
     1130    poly h=row_to_poly(number_array+j*n,terms,n,c->r);
     1131    if(h!=NULL){
     1132      p[p_pos++]=h;
     1133    }
     1134  }
     1135  pn=p_pos;
     1136  omfree(terms);
     1137  omfree(term_nodes);
     1138  omfree(number_array);
     1139  #ifdef NORO_NON_POLY
     1140  omfree(srows);
     1141  omfree(old_to_new_indices);
     1142  #endif
     1143  //don't forget the rank
     1144 
     1145}
     1146#endif
     1147
     1148#endif
Note: See TracChangeset for help on using the changeset viewer.