My Project
Public Member Functions | Private Member Functions | Private Attributes
mp_permmatrix Class Reference

Public Member Functions

 mp_permmatrix ()
 
 mp_permmatrix (matrix, ring)
 
 mp_permmatrix (mp_permmatrix *)
 
 ~mp_permmatrix ()
 
int mpGetRow ()
 
int mpGetCol ()
 
int mpGetRdim ()
 
int mpGetCdim ()
 
int mpGetSign ()
 
void mpSetSearch (int s)
 
void mpSaveArray ()
 
poly mpGetElem (int, int)
 
void mpSetElem (poly, int, int)
 
void mpDelElem (int, int)
 
void mpElimBareiss (poly)
 
int mpPivotBareiss (row_col_weight *)
 
int mpPivotRow (row_col_weight *, int)
 
void mpToIntvec (intvec *)
 
void mpRowReorder ()
 
void mpColReorder ()
 

Private Member Functions

void mpInitMat ()
 
poly * mpRowAdr (int r)
 
poly * mpColAdr (int c)
 
void mpRowWeight (float *)
 
void mpColWeight (float *)
 
void mpRowSwap (int, int)
 
void mpColSwap (int, int)
 

Private Attributes

int a_m
 
int a_n
 
int s_m
 
int s_n
 
int sign
 
int piv_s
 
int * qrow
 
int * qcol
 
poly * Xarray
 
ring _R
 

Detailed Description

Definition at line 925 of file matpol.cc.

Constructor & Destructor Documentation

◆ mp_permmatrix() [1/3]

mp_permmatrix::mp_permmatrix ( )
inline

Definition at line 942 of file matpol.cc.

942 : a_m(0) {}

◆ mp_permmatrix() [2/3]

mp_permmatrix::mp_permmatrix ( matrix  A,
ring  R 
)

Definition at line 963 of file matpol.cc.

963  : sign(1)
964 {
965  a_m = A->nrows;
966  a_n = A->ncols;
967  this->mpInitMat();
968  Xarray = A->m;
969  _R=R;
970 }
poly * m
Definition: matpol.h:18
poly * Xarray
Definition: matpol.cc:930
void mpInitMat()
Definition: matpol.cc:1085
#define R
Definition: sirandom.c:27
#define A
Definition: sirandom.c:24

◆ mp_permmatrix() [3/3]

mp_permmatrix::mp_permmatrix ( mp_permmatrix M)

Definition at line 972 of file matpol.cc.

973 {
974  poly p, *athis, *aM;
975  int i, j;
976 
977  _R=M->_R;
978  a_m = M->s_m;
979  a_n = M->s_n;
980  sign = M->sign;
981  this->mpInitMat();
982  Xarray = (poly *)omAlloc0(a_m*a_n*sizeof(poly));
983  for (i=a_m-1; i>=0; i--)
984  {
985  athis = this->mpRowAdr(i);
986  aM = M->mpRowAdr(i);
987  for (j=a_n-1; j>=0; j--)
988  {
989  p = aM[M->qcol[j]];
990  if (p)
991  {
992  athis[j] = p_Copy(p,_R);
993  }
994  }
995  }
996 }
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4080
poly * mpRowAdr(int r)
Definition: matpol.cc:933
int j
Definition: facHensel.cc:110
#define omAlloc0(size)
Definition: omAllocDecl.h:211
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:812
#define M
Definition: sirandom.c:25

◆ ~mp_permmatrix()

mp_permmatrix::~mp_permmatrix ( )

Definition at line 998 of file matpol.cc.

999 {
1000  int k;
1001 
1002  if (a_m != 0)
1003  {
1004  omFreeSize((ADDRESS)qrow,a_m*sizeof(int));
1005  omFreeSize((ADDRESS)qcol,a_n*sizeof(int));
1006  if (Xarray != NULL)
1007  {
1008  for (k=a_m*a_n-1; k>=0; k--)
1009  p_Delete(&Xarray[k],_R);
1010  omFreeSize((ADDRESS)Xarray,a_m*a_n*sizeof(poly));
1011  }
1012  }
1013 }
void * ADDRESS
Definition: auxiliary.h:119
int k
Definition: cfEzgcd.cc:99
int * qrow
Definition: matpol.cc:929
int * qcol
Definition: matpol.cc:929
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define NULL
Definition: omList.c:12
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:861

Member Function Documentation

◆ mpColAdr()

poly* mp_permmatrix::mpColAdr ( int  c)
inlineprivate

Definition at line 935 of file matpol.cc.

936  { return &(Xarray[qcol[c]]); }

◆ mpColReorder()

void mp_permmatrix::mpColReorder ( )

Definition at line 1098 of file matpol.cc.

1099 {
1100  int k, j, j1, j2;
1101 
1102  if (a_n > a_m)
1103  k = a_n - a_m;
1104  else
1105  k = 0;
1106  for (j=a_n-1; j>=k; j--)
1107  {
1108  j1 = qcol[j];
1109  if (j1 != j)
1110  {
1111  this->mpColSwap(j1, j);
1112  j2 = 0;
1113  while (qcol[j2] != j) j2++;
1114  qcol[j2] = j1;
1115  }
1116  }
1117 }
void mpColSwap(int, int)
Definition: matpol.cc:1071

◆ mpColSwap()

void mp_permmatrix::mpColSwap ( int  j1,
int  j2 
)
private

Definition at line 1071 of file matpol.cc.

1072 {
1073  poly p, *a1, *a2;
1074  int i, k = a_n*a_m;
1075 
1076  a1 = &(Xarray[j1]);
1077  a2 = &(Xarray[j2]);
1078  for (i=0; i< k; i+=a_n)
1079  {
1080  p = a1[i];
1081  a1[i] = a2[i];
1082  a2[i] = p;
1083  }
1084 }

◆ mpColWeight()

void mp_permmatrix::mpColWeight ( float *  wcol)
private

Definition at line 1017 of file matpol.cc.

1018 {
1019  poly p, *a;
1020  int i, j;
1021  float count;
1022 
1023  for (j=s_n; j>=0; j--)
1024  {
1025  a = this->mpColAdr(j);
1026  count = 0.0;
1027  for(i=s_m; i>=0; i--)
1028  {
1029  p = a[a_n*qrow[i]];
1030  if (p)
1031  count += mp_PolyWeight(p,_R);
1032  }
1033  wcol[j] = count;
1034  }
1035 }
poly * mpColAdr(int c)
Definition: matpol.cc:935
static float mp_PolyWeight(poly p, const ring r)
Definition: matpol.cc:1302
int status int void size_t count
Definition: si_signals.h:59

◆ mpDelElem()

void mp_permmatrix::mpDelElem ( int  ,
int   
)

◆ mpElimBareiss()

void mp_permmatrix::mpElimBareiss ( poly  div)

Definition at line 1244 of file matpol.cc.

1245 {
1246  poly piv, elim, q1, q2, *ap, *a;
1247  int i, j, jj;
1248 
1249  ap = this->mpRowAdr(s_m);
1250  piv = ap[qcol[s_n]];
1251  for(i=s_m-1; i>=0; i--)
1252  {
1253  a = this->mpRowAdr(i);
1254  elim = a[qcol[s_n]];
1255  if (elim != NULL)
1256  {
1257  elim = p_Neg(elim,_R);
1258  for (j=s_n-1; j>=0; j--)
1259  {
1260  q2 = NULL;
1261  jj = qcol[j];
1262  if (ap[jj] != NULL)
1263  {
1264  q2 = SM_MULT(ap[jj], elim, div,_R);
1265  if (a[jj] != NULL)
1266  {
1267  q1 = SM_MULT(a[jj], piv, div,_R);
1268  p_Delete(&a[jj],_R);
1269  q2 = p_Add_q(q2, q1, _R);
1270  }
1271  }
1272  else if (a[jj] != NULL)
1273  {
1274  q2 = SM_MULT(a[jj], piv, div, _R);
1275  }
1276  if ((q2!=NULL) && div)
1277  SM_DIV(q2, div, _R);
1278  a[jj] = q2;
1279  }
1280  p_Delete(&a[qcol[s_n]], _R);
1281  }
1282  else
1283  {
1284  for (j=s_n-1; j>=0; j--)
1285  {
1286  jj = qcol[j];
1287  if (a[jj] != NULL)
1288  {
1289  q2 = SM_MULT(a[jj], piv, div, _R);
1290  p_Delete(&a[jj], _R);
1291  if (div)
1292  SM_DIV(q2, div, _R);
1293  a[jj] = q2;
1294  }
1295  }
1296  }
1297  }
1298 }
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm div(const CanonicalForm &, const CanonicalForm &)
Definition: ap.h:40
static poly p_Neg(poly p, const ring r)
Definition: p_polys.h:1067
static poly p_Add_q(poly p, poly q, const ring r)
Definition: p_polys.h:896
#define SM_DIV
Definition: sparsmat.h:24
#define SM_MULT
Definition: sparsmat.h:23

◆ mpGetCdim()

int mp_permmatrix::mpGetCdim ( )
inline

Definition at line 949 of file matpol.cc.

949 { return s_n; }

◆ mpGetCol()

int mp_permmatrix::mpGetCol ( )

◆ mpGetElem()

poly mp_permmatrix::mpGetElem ( int  r,
int  c 
)

Definition at line 1236 of file matpol.cc.

1237 {
1238  return Xarray[a_n*qrow[r]+qcol[c]];
1239 }

◆ mpGetRdim()

int mp_permmatrix::mpGetRdim ( )
inline

Definition at line 948 of file matpol.cc.

948 { return s_m; }

◆ mpGetRow()

int mp_permmatrix::mpGetRow ( )

◆ mpGetSign()

int mp_permmatrix::mpGetSign ( )
inline

Definition at line 950 of file matpol.cc.

950 { return sign; }

◆ mpInitMat()

void mp_permmatrix::mpInitMat ( )
private

Definition at line 1085 of file matpol.cc.

1086 {
1087  int k;
1088 
1089  s_m = a_m;
1090  s_n = a_n;
1091  piv_s = 0;
1092  qrow = (int *)omAlloc(a_m*sizeof(int));
1093  qcol = (int *)omAlloc(a_n*sizeof(int));
1094  for (k=a_m-1; k>=0; k--) qrow[k] = k;
1095  for (k=a_n-1; k>=0; k--) qcol[k] = k;
1096 }
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ mpPivotBareiss()

int mp_permmatrix::mpPivotBareiss ( row_col_weight C)

Definition at line 1159 of file matpol.cc.

1160 {
1161  poly p, *a;
1162  int i, j, iopt, jopt;
1163  float sum, f1, f2, fo, r, ro, lp;
1164  float *dr = C->wrow, *dc = C->wcol;
1165 
1166  fo = 1.0e20;
1167  ro = 0.0;
1168  iopt = jopt = -1;
1169 
1170  s_n--;
1171  s_m--;
1172  if (s_m == 0)
1173  return 0;
1174  if (s_n == 0)
1175  {
1176  for(i=s_m; i>=0; i--)
1177  {
1178  p = this->mpRowAdr(i)[qcol[0]];
1179  if (p)
1180  {
1181  f1 = mp_PolyWeight(p,_R);
1182  if (f1 < fo)
1183  {
1184  fo = f1;
1185  if (iopt >= 0)
1186  p_Delete(&(this->mpRowAdr(iopt)[qcol[0]]),_R);
1187  iopt = i;
1188  }
1189  else
1190  p_Delete(&(this->mpRowAdr(i)[qcol[0]]),_R);
1191  }
1192  }
1193  if (iopt >= 0)
1194  mpReplace(iopt, s_m, sign, qrow);
1195  return 0;
1196  }
1197  this->mpRowWeight(dr);
1198  this->mpColWeight(dc);
1199  sum = 0.0;
1200  for(i=s_m; i>=0; i--)
1201  sum += dr[i];
1202  for(i=s_m; i>=0; i--)
1203  {
1204  r = dr[i];
1205  a = this->mpRowAdr(i);
1206  for(j=s_n; j>=0; j--)
1207  {
1208  p = a[qcol[j]];
1209  if (p)
1210  {
1211  lp = mp_PolyWeight(p,_R);
1212  ro = r - lp;
1213  f1 = ro * (dc[j]-lp);
1214  if (f1 != 0.0)
1215  {
1216  f2 = lp * (sum - ro - dc[j]);
1217  f2 += f1;
1218  }
1219  else
1220  f2 = lp-r-dc[j];
1221  if (f2 < fo)
1222  {
1223  fo = f2;
1224  iopt = i;
1225  jopt = j;
1226  }
1227  }
1228  }
1229  }
1230  if (iopt < 0)
1231  return 0;
1232  mpReplace(iopt, s_m, sign, qrow);
1233  mpReplace(jopt, s_n, sign, qcol);
1234  return 1;
1235 }
void mpColWeight(float *)
Definition: matpol.cc:1017
void mpRowWeight(float *)
Definition: matpol.cc:1036
float * wcol
Definition: matpol.cc:893
float * wrow
Definition: matpol.cc:893
static void mpReplace(int j, int n, int &sign, int *perm)
Definition: matpol.cc:1144

◆ mpPivotRow()

int mp_permmatrix::mpPivotRow ( row_col_weight ,
int   
)

◆ mpRowAdr()

poly* mp_permmatrix::mpRowAdr ( int  r)
inlineprivate

Definition at line 933 of file matpol.cc.

934  { return &(Xarray[a_n*qrow[r]]); }

◆ mpRowReorder()

void mp_permmatrix::mpRowReorder ( )

Definition at line 1119 of file matpol.cc.

1120 {
1121  int k, i, i1, i2;
1122 
1123  if (a_m > a_n)
1124  k = a_m - a_n;
1125  else
1126  k = 0;
1127  for (i=a_m-1; i>=k; i--)
1128  {
1129  i1 = qrow[i];
1130  if (i1 != i)
1131  {
1132  this->mpRowSwap(i1, i);
1133  i2 = 0;
1134  while (qrow[i2] != i) i2++;
1135  qrow[i2] = i1;
1136  }
1137  }
1138 }
void mpRowSwap(int, int)
Definition: matpol.cc:1056

◆ mpRowSwap()

void mp_permmatrix::mpRowSwap ( int  i1,
int  i2 
)
private

Definition at line 1056 of file matpol.cc.

1057 {
1058  poly p, *a1, *a2;
1059  int j;
1060 
1061  a1 = &(Xarray[a_n*i1]);
1062  a2 = &(Xarray[a_n*i2]);
1063  for (j=a_n-1; j>= 0; j--)
1064  {
1065  p = a1[j];
1066  a1[j] = a2[j];
1067  a2[j] = p;
1068  }
1069 }

◆ mpRowWeight()

void mp_permmatrix::mpRowWeight ( float *  wrow)
private

Definition at line 1036 of file matpol.cc.

1037 {
1038  poly p, *a;
1039  int i, j;
1040  float count;
1041 
1042  for (i=s_m; i>=0; i--)
1043  {
1044  a = this->mpRowAdr(i);
1045  count = 0.0;
1046  for(j=s_n; j>=0; j--)
1047  {
1048  p = a[qcol[j]];
1049  if (p)
1050  count += mp_PolyWeight(p,_R);
1051  }
1052  wrow[i] = count;
1053  }
1054 }

◆ mpSaveArray()

void mp_permmatrix::mpSaveArray ( )
inline

Definition at line 952 of file matpol.cc.

952 { Xarray = NULL; }

◆ mpSetElem()

void mp_permmatrix::mpSetElem ( poly  ,
int  ,
int   
)

◆ mpSetSearch()

void mp_permmatrix::mpSetSearch ( int  s)

◆ mpToIntvec()

void mp_permmatrix::mpToIntvec ( intvec )

Field Documentation

◆ _R

ring mp_permmatrix::_R
private

Definition at line 931 of file matpol.cc.

◆ a_m

int mp_permmatrix::a_m
private

Definition at line 928 of file matpol.cc.

◆ a_n

int mp_permmatrix::a_n
private

Definition at line 928 of file matpol.cc.

◆ piv_s

int mp_permmatrix::piv_s
private

Definition at line 928 of file matpol.cc.

◆ qcol

int * mp_permmatrix::qcol
private

Definition at line 929 of file matpol.cc.

◆ qrow

int* mp_permmatrix::qrow
private

Definition at line 929 of file matpol.cc.

◆ s_m

int mp_permmatrix::s_m
private

Definition at line 928 of file matpol.cc.

◆ s_n

int mp_permmatrix::s_n
private

Definition at line 928 of file matpol.cc.

◆ sign

int mp_permmatrix::sign
private

Definition at line 928 of file matpol.cc.

◆ Xarray

poly* mp_permmatrix::Xarray
private

Definition at line 930 of file matpol.cc.


The documentation for this class was generated from the following file: