Changeset 8f963e in git for libpolys


Ignore:
Timestamp:
Mar 3, 2017, 10:07:48 AM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
Children:
814a65342deba6307f8681b5318b625767ed2bc9
Parents:
77ba486a2bb537dad7c328a5710ec099c240c06f
Message:
opt: mp_Tesnsor
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/matpol.cc

    r77ba48 r8f963e  
    17251725  }
    17261726}
    1727 
     1727// helper for mp_Tensor
     1728// destroyes f, keeps B
    17281729static ideal mp_MultAndShift(poly f, ideal B, int s, const ring r)
    17291730{
     1731  assume(f!=NULL);
    17301732  ideal res=idInit(IDELEMS(B),B->rank+s);
    1731   if (f!=NULL)
    1732   {
    1733     int q=IDELEMS(B); // p x q
    1734     for(int j=0;j<q;j++)
    1735     {
    1736       poly h=pp_Mult_qq(f,B->m[j],r);
    1737       if (h!=NULL)
    1738       {
    1739         if (s>0) p_Shift(&h,s,r);
    1740         res->m[j]=h;
    1741       }
    1742     }
    1743   }
     1733  int q=IDELEMS(B); // p x q
     1734  for(int j=0;j<q;j++)
     1735  {
     1736    poly h=pp_Mult_qq(f,B->m[j],r);
     1737    if (h!=NULL)
     1738    {
     1739      if (s>0) p_Shift(&h,s,r);
     1740      res->m[j]=h;
     1741    }
     1742  }
     1743  p_Delete(&f,r);
    17441744  return res;
    17451745}
    1746 static ideal mp_AddSubMat(ideal res, ideal sm, int col, const ring r)
     1746// helper for mp_Tensor
     1747// updates res, destroyes contents of sm
     1748static void mp_AddSubMat(ideal res, ideal sm, int col, const ring r)
    17471749{
    17481750  for(int i=0;i<IDELEMS(sm);i++)
     
    17511753    sm->m[i]=NULL;
    17521754  }
    1753   return res;
    17541755}
    17551756
     
    17621763  int p=B->rank;
    17631764  ideal res=idInit(n*q,m*p);
    1764   poly *a=(poly*)omAlloc0(m*sizeof(poly));
     1765  poly *a=(poly*)omAlloc(m*sizeof(poly));
    17651766  for(int i=0; i<n; i++)
    17661767  {
     1768    memset(a,0,m*sizeof(poly));
    17671769    p_DecomposeComp(p_Copy(A->m[i],r),a,m,r);
    17681770    for(int j=0;j<m;j++)
    17691771    {
    1770       ideal sm=mp_MultAndShift(a[j], // A_i_j
    1771                                B,
    1772                                j*p, // shift j*p down
    1773                                r);
    1774       res=mp_AddSubMat(res,sm,i*q,r); // add this colums to col i*q ff
    1775       id_Delete(&sm,r);
    1776     }
    1777     memset(a,0,m*sizeof(poly));
     1772      if (a[j]!=NULL)
     1773      {
     1774        ideal sm=mp_MultAndShift(a[j], // A_i_j
     1775                                 B,
     1776                                 j*p, // shift j*p down
     1777                                 r);
     1778        mp_AddSubMat(res,sm,i*q,r); // add this columns to col i*q ff
     1779        id_Delete(&sm,r); // delete the now empty ideal
     1780      }
     1781    }
    17781782  }
    17791783  omFreeSize(a,m*sizeof(poly));
Note: See TracChangeset for help on using the changeset viewer.