Borderbasix

MatrixOf.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 * This file is part of the source code of BORDERBASIX software. *
3 * (C) B. Mourrain, INRIA *
4 **********************************************************************
5 History:
6 $Id: MatrixOf.hpp,v 1.1.1.1 2006/10/06 08:01:40 trebuche Exp $
7 **********************************************************************/
8 #ifndef _MatrixOf_H_
9 #define _MatrixOf_H_
10 //----------------------------------------------------------------------
11 #include "linpkg/array2d.H"
12 #include "linpkg/MATRIX.H"
13 #include "linpkg/MatRef.H"
16 #include <list>
17 #include <map>
18 #include <set>
19 //----------------------------------------------------------------------
24 template<class POL>
25 typename POL::coeff_t
26 CoeffOf(const POL & p, const typename POL::monom_t & mono)
27 {
28  typedef typename POL::coeff_t coeff_t;
29  typename POL::const_iterator m;
30  for(m = p.begin(); !IsComparable((*m),mono) && m!= p.end(); m++);
31  if(m!=p.end())
32  return m->GetCoeff();
33  else
34  return coeff_t(0);
35 }
36 //----------------------------------------------------------------------
37 namespace matrixof
38 {
39  template<class R> void build(R & A, typename R::index_t nl,
40  typename R::index_t nc, typename R::index_t nz);
41 };
42 //----------------------------------------------------------------------
48 template<class R>
49 void matrixof::build(R & A, typename R::index_t nl,
50  typename R::index_t nc, typename R::index_t nz)
51 {
52  A.rebuild(nl,nc);
53 }
54 //----------------------------------------------------------------------
65 template<class POL, class RM>
66 MatRef<RM> MatrixOf(const list<POL> & L, RM M, char t='N')
67 {
68  typedef typename POL::monom_t monom_t;
69  POL s;
70  monom_t mt;
71  int c=0;
72  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi){
73  for(typename POL::const_iterator m = pi->begin(); m!= pi->end(); m++)
74  {
75  mt=(*m);
76  mt.SetCoeff(1.);
77  s += POL(mt);
78  }
79  c++;
80  }
81 
82  map<monom_t,int> index;
83  int l=0;
84  for(typename POL::iterator m = s.begin(); m!=s.end(); m++){
85  m->SetCoeff(1.);
86  index[*m]=l;
87  l++;
88  }
89  unsigned nz=0;
90  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi)
91  nz+=pi->rep.size();
92 
93  if(t=='T') {
94  RM* res= new RM;
95  matrixof::build(*res,c,l,nz);
96  l=0;
97  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi)
98  {
99  for(typename POL::const_iterator m = pi->begin(); m!=pi->end(); m++)
100  {
101  (*res)(l,index[*m])=m->GetCoeff();
102  }
103  l++;
104  }
105  return MatRef<RM>(res);
106  }else{
107  RM* res= new RM; matrixof::build(*res,l,c,nz);
108  l=0;
109  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi){
110  for(typename POL::const_iterator m = pi->begin(); m!=pi->end(); m++)
111  {
112  (*res)(index[*m],l)=m->GetCoeff();
113  }
114  l++;
115  }
116  return MatRef<RM>(res);
117  }
118 }
119 
128 template <class POL, class RM>
129 MatRef<RM>
130 MatrixOf(const list<POL> & L,
131  const list<typename POL::monom_t> & lm,
132  RM M, char t='N')
133 {
134  typedef typename POL::monom_t monom_t;
135 
136  map<monom_t,int> index;
137 
138  int l=1;
139  for(list<monom_t>::const_iterator m = lm.begin(); m!=lm.end(); m++){
140  index[*m]=l;
141  l++;
142  }
143  int c;
144  if(t=='T') {
145  RM* res= new RM(L.size(),l-1);
146  l=0;
147  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi)
148  {
149  for(typename POL::const_iterator m = pi->begin(); m!=pi->end(); m++)
150  {
151  if((c=index[*m])) (*res)(l,c-1)=m->GetCoeff();
152  }
153  l++;
154  }
155  return MatRef<RM>(res);
156  }else{
157  RM* res= new RM(l-1,L.size());
158  l=0;
159  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi){
160  for(typename POL::const_iterator m = pi->begin(); m!=pi->end(); m++)
161  {
162  if((c=index[*m])) (*res)(c-1,l)=m->GetCoeff();
163  }
164  l++;
165  }
166  return MatRef<RM>(res);
167  }
168 }
169 
170 #ifdef _SpUMFMat_H_
171 
174 template <class POL, class C>
175 MatRef<umfpack<C> >
176 MatrixOf(const list<POL> & L,
177  const list<typename POL::monom_t> & lm,
178  umfpack<C> r, char t='N')
179 {
180  typedef umfpack<C> R;
181  typedef typename POL::monom_t monom_t;
182 
183  map<monom_t,int> index;
184 
185  int l=1;
186  for(list<monom_t>::const_iterator m = lm.begin(); m!=lm.end(); m++){
187  index[*m]=l; l++;
188  }
189 
190  int nz=0;
191  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi)
192  for(typename POL::const_iterator m = pi->begin(); m!=pi->end(); m++)
193  if(index[*m]) nz++;
194 
195  int nr= lm.size();
196  int nc= L.size();
197 
198  if(t=='T') {
199  R* res= new R(nr,nc,nz);
200  int k =0, j=0, i;
201  for(list<POL>::const_iterator pi = L.begin(); pi != L.end(); ++pi)
202  {
203  for(typename POL::const_iterator m = pi->begin(); m!=pi->end(); m++)
204  {
205  if((i=index[*m])) {
206  res->tab_[k] = m->GetCoeff();
207  res->index_[k]=j;
208  res->index_[k+nz]=i-1;
209  k++;
210  }
211  }
212  j++;
213  }
214  return MatRef<R>(res);
215  }
216 }
217 #endif // _SpUMFMat_H_
218 #endif // _MatrixOf_H_
Definition: MatrixOf.hpp:37
void build(R &A, typename R::index_t nl, typename R::index_t nc, typename R::index_t nz)
Definition: MatrixOf.hpp:49
POL::coeff_t CoeffOf(const POL &p, const typename POL::monom_t &mono)
Definition: MatrixOf.hpp:26
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
MSKint32t k
Definition: mosek.h:2713
MSKCONST char MSKint32t MSKint32t * index
Definition: mosek.h:2860
MSKrealt * c
Definition: mosek.h:2678
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
MSKint64t * nz
Definition: mosek.h:3998
MSKrescodee r
Definition: mosek.h:2321
MatRef< RM > MatrixOf(const list< POL > &L, RM M, char t='N')
Definition: MatrixOf.hpp:66
Home  |  Download & InstallContributions