7 #ifndef __solve_SparseMatrix_h__ 8 #define __solve_SparseMatrix_h__ 25 template<
class T,
class ROW=SparseArray<T> >
30 SparseMatrix(U32 rows,U32 columns);
31 SparseMatrix(
const SparseMatrix<T,ROW>& rhs);
34 SparseMatrix<T,ROW>& operator=(
const SparseMatrix<T,ROW>& rhs);
36 T operator()(U32 i, U32 j)
const;
37 T& operator()(U32 i, U32 j);
39 void reset(U32 rows,U32 columns);
41 U32 rows(
void)
const {
return m_rows; }
42 U32 columns(
void)
const {
return m_columns; }
44 void setTranspose(
const SparseMatrix<T,ROW>& rhs);
45 void setSum(
const SparseMatrix<T,ROW> &rhs);
46 void setDifference(
const SparseMatrix<T,ROW> &rhs);
48 const SparseMatrix<T,ROW> &lhs,
49 const SparseMatrix<T,ROW> &rhs);
51 void premultiplyDiagonal(
52 const SparseMatrix<T,ROW> &diag,
53 SparseMatrix<T,ROW> &b)
const;
54 void premultiplyDiagonal(
55 const DenseVector<T> &diag,
56 SparseMatrix<T,ROW> &b)
const;
57 void premultiplyInverseDiagonal(
58 const SparseMatrix<T,ROW> &diag,
59 SparseMatrix<T,ROW> &b)
const;
60 void premultiplyInverseDiagonal(
61 const DenseVector<T> &diag,
62 SparseMatrix<T,ROW> &b)
const;
63 void postmultiplyDiagonal(
64 const DenseVector<T> &diag,
65 SparseMatrix<T,ROW> &b)
const;
66 void postmultiplyInverseDiagonal(
67 const SparseMatrix<T,ROW> &diag,
68 SparseMatrix<T,ROW> &b)
const;
69 void postmultiplyInverseDiagonal(
70 const DenseVector<T> &diag,
71 SparseMatrix<T,ROW> &b)
const;
73 void scale(
const F32 scalar);
74 void scale(
const F32 scalar,
75 SparseMatrix<T,ROW>& result)
const;
77 void transform(
const DenseVector<T> &x,
78 DenseVector<T> &b)
const;
79 void transposeTransform(
const DenseVector<T> &x,
80 DenseVector<T> &b)
const;
89 template<
class T,
class ROW>
90 inline SparseMatrix<T,ROW>::SparseMatrix(
void):
94 m_pRow=
new ROW[m_rows];
97 template<
class T,
class ROW>
98 inline SparseMatrix<T,ROW>::SparseMatrix(U32 rows,U32 columns):
102 m_pRow=
new ROW[m_rows];
105 template<
class T,
class ROW>
106 inline SparseMatrix<T,ROW>::SparseMatrix(
const SparseMatrix<T,ROW>& rhs):
108 m_columns(rhs.m_columns)
110 m_pRow=
new ROW[m_rows];
114 template<
class T,
class ROW>
115 inline SparseMatrix<T,ROW>::~SparseMatrix(
void)
120 template<
class T,
class ROW>
121 inline void SparseMatrix<T,ROW>::reset(U32 rows,U32 columns)
126 m_pRow=
new ROW[m_rows];
128 template<
class T,
class ROW>
129 inline void SparseMatrix<T,ROW>::clear(
void)
131 for(U32 i=0;i<m_rows;i++)
137 template<
class T,
class ROW>
138 inline T SparseMatrix<T,ROW>::operator()(U32 i, U32 j)
const 141 if(i >= m_rows || j >= m_columns) { feX(e_invalidRange); }
144 const ROW& row=m_pRow[i];
148 template<
class T,
class ROW>
149 inline T& SparseMatrix<T,ROW>::operator()(U32 i, U32 j)
152 if(i >= m_rows || j >= m_columns) { feX(e_invalidRange); }
161 template<
class T,
class ROW>
162 inline SparseMatrix<T,ROW>& SparseMatrix<T,ROW>::operator=(
163 const SparseMatrix<T,ROW>& rhs)
167 if(m_rows==rhs.m_rows)
169 m_columns=rhs.m_columns;
174 reset(rhs.m_rows,rhs.m_columns);
177 for(U32 i=0;i<m_rows;i++)
179 const ROW& row=rhs.m_pRow[i];
189 template<
class T,
class ROW>
190 inline void SparseMatrix<T,ROW>::setTranspose(
const SparseMatrix<T,ROW> &rhs)
194 if(m_rows==rhs.m_rows)
196 m_columns=rhs.m_columns;
201 reset(rhs.m_rows,rhs.m_columns);
204 for(U32 i=0;i<m_rows;i++)
206 const ROW& row=rhs.m_pRow[i];
208 for(U32 loc=0; loc<
entries; loc++)
211 operator()(row.index(loc),i)=row.entry(loc);
220 template<
class T,
class ROW>
221 inline void SparseMatrix<T,ROW>::setSum(
const SparseMatrix<T,ROW> &rhs)
223 for(U32 i=0; i<m_rows; i++)
225 const ROW& row=rhs.m_pRow[i];
226 U32 entries=row.entries();
227 for(U32 loc=0; loc<
entries; loc++)
230 operator()(i,row.index(loc))+=row.entry(loc);
238 template<
class T,
class ROW>
239 inline void SparseMatrix<T,ROW>::setDifference(
const SparseMatrix<T,ROW> &rhs)
241 for(U32 i=0; i<m_rows; i++)
243 const ROW& row=rhs.m_pRow[i];
244 U32 entries=row.entries();
245 for(U32 loc=0; loc<
entries; loc++)
248 operator()(i,row.index(loc))-=row.entry(loc);
258 template<
class T,
class ROW>
259 inline void SparseMatrix<T,ROW>::setProduct(
260 const SparseMatrix<T,ROW> &lhs,
261 const SparseMatrix<T,ROW> &rhs)
263 FEASSERT(lhs.m_columns==rhs.m_rows);
265 if(m_rows==lhs.m_rows)
267 m_columns=rhs.m_columns;
272 reset(lhs.m_rows,rhs.m_columns);
275 for(U32 i=0; i<m_rows; i++)
277 for(U32 j=0; j<m_columns; j++)
280 for(U32 k=0; k<lhs.m_columns; k++)
282 sum += lhs(i,k)*rhs(k,j);
295 template<
class T,
class ROW>
296 inline void SparseMatrix<T,ROW>::scale(
const F32 scalar)
298 for(U32 i=0; i<m_rows; i++)
301 U32 entries=row.entries();
302 for(U32 loc=0; loc<
entries; loc++)
305 row.entry(loc)*=scalar;
313 template<
class T,
class ROW>
314 inline void SparseMatrix<T,ROW>::scale(
const F32 scalar,
315 SparseMatrix<T,ROW> &result)
const 317 for(U32 i=0; i<m_rows; i++)
319 const ROW& row=m_pRow[i];
320 U32 entries=row.entries();
321 for(U32 loc=0; loc<
entries; loc++)
324 result(i,row.index(loc))=row.entry(loc)*scalar;
332 template<
class T,
class ROW>
333 inline void SparseMatrix<T,ROW>::transform(
const DenseVector<T> &x,
334 DenseVector<T> &b)
const 336 for(U32 i=0; i<m_rows; i++)
338 const ROW& row=m_pRow[i];
339 U32 entries=row.entries();
342 for(U32 loc=0; loc<
entries; loc++)
345 sum+=row.entry(loc) * x[row.index(loc)];
354 template<
class T,
class ROW>
355 inline void SparseMatrix<T,ROW>::transposeTransform(
const DenseVector<T> &x,
356 DenseVector<T> &b)
const 360 for(U32 i=0; i<m_rows; i++)
362 const ROW& row=m_pRow[i];
363 U32 entries=row.entries();
365 for(U32 loc=0; loc<
entries; loc++)
368 b[row.index(loc)]+=row.entry(loc) * x[i];
378 template<
class T,
class ROW>
379 inline void SparseMatrix<T,ROW>::premultiplyDiagonal(
380 const SparseMatrix<T,ROW> &diag,SparseMatrix<T,ROW> &result)
const 382 if(result.rows()!=m_rows || result.columns()!=m_columns)
384 result.reset(m_rows,m_columns);
386 for(U32 i=0; i<m_rows; i++)
388 const ROW& row=m_pRow[i];
389 U32 entries=row.entries();
392 for(U32 loc=0; loc<
entries; loc++)
395 result(i,row.index(loc))=row.entry(loc)*d;
407 template<
class T,
class ROW>
408 inline void SparseMatrix<T,ROW>::premultiplyDiagonal(
409 const DenseVector<T> &diag,SparseMatrix<T,ROW> &result)
const 411 if(result.rows()!=m_rows || result.columns()!=m_columns)
413 result.reset(m_rows,m_columns);
415 for(U32 i=0; i<m_rows; i++)
417 const ROW& row=m_pRow[i];
418 U32 entries=row.entries();
421 for(U32 loc=0; loc<
entries; loc++)
424 result(i,row.index(loc))=row.entry(loc)*d;
435 template<
class T,
class ROW>
436 inline void SparseMatrix<T,ROW>::premultiplyInverseDiagonal(
437 const SparseMatrix<T,ROW> &diag,SparseMatrix<T,ROW> &result)
const 439 if(result.rows()!=m_rows || result.columns()!=m_columns)
441 result.reset(m_rows,m_columns);
443 for(U32 i=0; i<m_rows; i++)
445 const ROW& row=m_pRow[i];
446 U32 entries=row.entries();
449 for(U32 loc=0; loc<
entries; loc++)
452 result(i,row.index(loc))=row.entry(loc)*d;
465 template<
class T,
class ROW>
466 inline void SparseMatrix<T,ROW>::premultiplyInverseDiagonal(
467 const DenseVector<T> &diag,SparseMatrix<T,ROW> &result)
const 469 if(result.rows()!=m_rows || result.columns()!=m_columns)
471 result.reset(m_rows,m_columns);
473 for(U32 i=0; i<m_rows; i++)
475 const ROW& row=m_pRow[i];
476 U32 entries=row.entries();
479 for(U32 loc=0; loc<
entries; loc++)
482 result(i,row.index(loc))=row.entry(loc)*d;
495 template<
class T,
class ROW>
496 inline void SparseMatrix<T,ROW>::postmultiplyDiagonal(
497 const DenseVector<T> &diag,SparseMatrix<T,ROW> &result)
const 499 if(result.rows()!=m_rows || result.columns()!=m_columns)
501 result.reset(m_rows,m_columns);
503 for(U32 i=0; i<m_rows; i++)
505 const ROW& row=m_pRow[i];
506 U32 entries=row.entries();
508 for(U32 loc=0; loc<
entries; loc++)
511 const U32 j=row.index(loc);
512 result(i,j)=row.entry(loc)*diag[j];
523 template<
class T,
class ROW>
524 inline void SparseMatrix<T,ROW>::postmultiplyInverseDiagonal(
525 const SparseMatrix<T,ROW> &diag,SparseMatrix<T,ROW> &result)
const 527 if(result.rows()!=m_rows || result.columns()!=m_columns)
529 result.reset(m_rows,m_columns);
532 for(U32 i=0; i<m_rows; i++)
534 scale[i]=T(1)/diag(i,i);
536 for(U32 i=0; i<m_rows; i++)
538 const ROW& row=m_pRow[i];
539 U32 entries=row.entries();
541 for(U32 loc=0; loc<
entries; loc++)
544 const U32 j=row.index(loc);
545 result(i,row.index(loc))=row.entry(loc)*scale[j];
558 template<
class T,
class ROW>
559 inline void SparseMatrix<T,ROW>::postmultiplyInverseDiagonal(
560 const DenseVector<T> &diag,SparseMatrix<T,ROW> &result)
const 562 if(result.rows()!=m_rows || result.columns()!=m_columns)
564 result.reset(m_rows,m_columns);
567 for(U32 i=0; i<m_rows; i++)
569 scale[i]=T(1)/diag(i);
571 for(U32 i=0; i<m_rows; i++)
573 const ROW& row=m_pRow[i];
574 U32 entries=row.entries();
576 for(U32 loc=0; loc<
entries; loc++)
579 const U32 j=row.index(loc);
580 result(i,row.index(loc))=row.entry(loc)*scale[j];
590 template<
class T,
class ROW>
593 return matrix.rows();
599 template<
class T,
class ROW>
602 return matrix.columns();
613 template<
class T,
class ROW>
621 const U32
size=vector.size();
622 if(result.size()!=
size)
626 for(U32 m=0;m<
size;m++)
628 result[m]=vector[m]*diagonal(m,m);
640 template<
class T,
class ROW>
648 const U32
size=vector.size();
649 if(result.size()!=
size)
653 for(U32 m=0;m<
size;m++)
655 result[m]=vector[m]/diagonal(m,m);
659 template<
class T,
class ROW>
669 template<
class T,
class ROW>
672 return(matrix.rows()==matrix.columns());
678 template<
class T,
class ROW>
681 U32 limit=minimum(matrix.columns(),matrix.rows());
683 for(U32 i = 0;i < limit;i++)
691 template<
class T,
class ROW>
695 A.setTranspose(matrix);
703 template<
class T,
class ROW>
715 template<
class T,
class ROW>
720 result.setDifference(rhs);
727 template<
class T,
class ROW>
738 template<
class T,
class ROW>
742 lhs.setDifference(rhs);
755 template<
class T,
class ROW>
760 rhs.premultiplyDiagonal(lhs,result);
773 template<
class T,
class ROW>
778 rhs.premultiplyDiagonal(lhs,result);
792 template<
class T,
class ROW>
798 rhs.premultiplyInverseDiagonal(lhs,result);
814 template<
class T,
class ROW>
820 rhs.premultiplyInverseDiagonal(lhs,result);
833 template<
class T,
class ROW>
838 lhs.postmultiplyDiagonal(rhs,result);
852 template<
class T,
class ROW>
858 lhs.postmultiplyInverseDiagonal(rhs,result);
874 template<
class T,
class ROW>
880 lhs.postmultiplyInverseDiagonal(rhs,result);
887 template<
class T,
class ROW>
893 lhs.transform(rhs,b);
900 template<
class T,
class ROW>
904 lhs.transform(in,out);
910 template<
class T,
class ROW>
914 lhs.transposeTransform(in,out);
920 template<
class T,
class ROW,
class U>
925 matrix.scale(scalar,result);
932 template<
class T,
class ROW,
class U>
937 matrix.scale(scalar,result);
944 template<
class T,
class ROW>
954 template <
typename T>
955 class FE_DL_EXPORT SparseMatrix1 :
public Component 960 virtual ~SparseMatrix1(
void) {}
961 virtual void multiply(std::vector<t_real> &a_b,
962 const std::vector<t_real> &a_x)
const = 0;
963 virtual void scale(t_real a_scale) = 0;
966 template <
typename T>
967 class FE_DL_EXPORT FullBCRS1 :
public SparseMatrix1<T>
972 virtual ~FullBCRS1(
void);
975 virtual void multiply(std::vector<t_real> &a_b,
976 const std::vector<t_real> &a_x)
const;
977 virtual void scale(t_real a_scale);
981 virtual void done(
void);
982 t_real &insert(
unsigned int a_columnIndex,
983 const t_real &a_block);
985 void dump(
void)
const;
987 void write(
const String &a_filename);
988 void read(
const String &a_filename);
990 void writeDense(
const String &a_filename);
991 void readDense(
const String &a_filename,
unsigned int a_M,
unsigned int a_N);
993 void writeStructure(
const String &a_filename)
const;
1003 std::vector<t_real> &blocks(
void) {
return m_blocks; }
1004 std::vector<unsigned int> &colind(
void) {
return m_colind; }
1005 std::vector<unsigned int> &rowptr(
void) {
return m_rowptr; }
1008 std::vector<t_real> m_blocks;
1009 std::vector<unsigned int> m_colind;
1010 std::vector<unsigned int> m_rowptr;
1012 t_real m_zeroVector;
1015 template <
typename T>
1016 class FE_DL_EXPORT UpperTriangularBCRS1 :
public FullBCRS1<T>
1020 UpperTriangularBCRS1(
void){}
1021 virtual ~UpperTriangularBCRS1(
void){}
1023 virtual void multiply(std::vector<t_real> &a_b,
1024 const std::vector<t_real> &a_x)
const;
1026 void incompleteSqrt(
void);
1027 void backSub(std::vector<t_real> &a_x,
const std::vector<t_real> &a_b);
1028 void transposeForeSub(std::vector<t_real> &a_x,
const std::vector<t_real> &a_b);
1029 void backSolve(std::vector<t_real> &a_x,
const std::vector<t_real> &a_b);
1030 virtual void done(
void);
1033 std::vector<unsigned int> m_ptr;
1034 std::vector<t_real> m_y;
1038 template <
typename T>
1039 inline FullBCRS1<T>::FullBCRS1(
void)
1045 template <
typename T>
1046 inline FullBCRS1<T>::~FullBCRS1(
void)
1050 template <
typename T>
1051 inline void FullBCRS1<T>::clear(
void)
1059 template <
typename T>
1060 inline void FullBCRS1<T>::startrow(
void)
1062 m_rowptr.push_back(m_r);
1065 template <
typename T>
1066 inline void FullBCRS1<T>::done(
void)
1068 m_rowptr.push_back(m_r);
1071 template <
typename T>
1072 inline void UpperTriangularBCRS1<T>::done(
void)
1074 m_y.resize(FullBCRS1<T>::m_rowptr.
size());
1075 FullBCRS1<T>::m_rowptr.push_back(FullBCRS1<T>::m_r);
1076 m_ptr.resize(FullBCRS1<T>::m_rowptr.
size());
1079 template <
typename T>
1080 inline T &FullBCRS1<T>::insert(
unsigned int a_columnIndex,
const t_real &a_block)
1082 m_blocks.push_back(a_block);
1083 m_colind.push_back(a_columnIndex);
1085 return m_blocks.back();
1088 template <
typename T>
1089 inline void FullBCRS1<T>::multiply(std::vector<t_real> &a_b,
const std::vector<t_real> &a_x)
const 1091 unsigned int n = (
unsigned int)(m_rowptr.size() - 1);
1092 for(
unsigned int i = 0; i < n; i++)
1094 a_b[i] = m_zeroVector;
1095 for(
unsigned int k = m_rowptr[i]; k < m_rowptr[i+1]; k++)
1097 a_b[i] += m_blocks[k] * a_x[m_colind[k]];
1102 template <
typename T>
1103 inline void FullBCRS1<T>::dump(
void)
const 1105 t_real offdiagonal_sum;
1106 offdiagonal_sum = 0.0;
1107 unsigned int n = (
unsigned int)(m_rowptr.size() - 1);
1108 for(
unsigned int i = 0; i < n; i++)
1110 fe_fprintf(stderr,
" %d: ", i);
1111 for(
unsigned int k = m_rowptr[i]; k < m_rowptr[i+1]; k++)
1113 fe_fprintf(stderr,
"%g ", m_blocks[k]);
1114 if(m_colind[k] != i)
1116 offdiagonal_sum = offdiagonal_sum + m_blocks[k];
1119 fe_fprintf(stderr,
"\n");
1122 feLogGroup(
"BCRS",
"off diagonal\n%g\n", offdiagonal_sum);
1124 fe_fprintf(stderr,
"--------------------------\n");
1125 for(
unsigned int i = 0; i < n; i++)
1128 for(
unsigned int k = m_rowptr[i]; k < m_rowptr[i+1]; k++)
1130 while(j < m_colind[k] && j < n)
1132 fe_fprintf(stderr,
"%6.3g ", 0.0);
1135 fe_fprintf(stderr,
"%6.3g ", m_blocks[k]);
1138 fe_fprintf(stderr,
"\n");
1140 fe_fprintf(stderr,
"--------------------------\n");
1143 template <
typename T>
1144 inline void FullBCRS1<T>::scale(t_real a_scale)
1146 unsigned int n = (
unsigned int)m_blocks.size();
1147 for(
unsigned int i = 0; i < n; i++)
1149 m_blocks[i] *= a_scale;
1153 template <
typename T>
1154 inline void UpperTriangularBCRS1<T>::multiply(std::vector<t_real> &a_b,
const std::vector<t_real> &a_x)
const 1156 unsigned int n = (
unsigned int)(FullBCRS1<T>::m_rowptr.
size() - 1);
1157 for(
unsigned int i = 0; i < n; i++)
1159 a_b[i] = FullBCRS1<T>::m_zeroVector;
1161 for(
unsigned int i = 0; i < n; i++)
1163 unsigned int k = FullBCRS1<T>::m_rowptr[i];
1164 a_b[i] += FullBCRS1<T>::m_blocks[k] * a_x[i];
1165 for(k=k+1; k < FullBCRS1<T>::m_rowptr[i+1]; k++)
1167 a_b[i] += FullBCRS1<T>::m_blocks[k] * a_x[FullBCRS1<T>::m_colind[k]];
1168 a_b[FullBCRS1<T>::m_colind[k]] += FullBCRS1<T>::m_blocks[k] * a_x[i];
1173 template <
typename T>
1174 inline void FullBCRS1<T>::sparse(
const sp<FullBCRS1> &a_other)
1180 unsigned int n = a_other->m_rowptr.size()-1;
1181 for(
unsigned int i = 0; i < n; i++)
1184 int d = a_other->m_rowptr[i];
1185 for(
int k=d; k < a_other->m_rowptr[i+1]; k++)
1187 int c = a_other->m_colind[k];
1188 if(!(0.0 == a_other->m_blocks[k]))
1190 insert(c, a_other->m_blocks[k]);
1197 template <
typename T>
1200 unsigned int n = a_other->m_rowptr.size()-1;
1201 for(
unsigned int i = 0; i < n; i++)
1203 int d = a_other->m_rowptr[i];
1204 int d_self = m_rowptr[i];
1205 for(
int k=d; k < a_other->m_rowptr[i+1]; k++)
1207 int c = a_other->m_colind[k];
1208 for(
int k_self=d_self; k_self < m_rowptr[i+1]; k_self++)
1210 int c_self = m_colind[k_self];
1213 m_blocks[k_self] = a_other->m_blocks[k];
1220 template <
typename T>
1221 inline void UpperTriangularBCRS1<T>::backSub(std::vector<t_real> &a_x,
const std::vector<t_real> &a_b)
1223 unsigned int n = (
unsigned int)(FullBCRS1<T>::m_rowptr.
size()-1);
1225 a_x[n-1] = a_b[n-1]/FullBCRS1<T>::m_blocks[FullBCRS1<T>::m_rowptr[n-1]];
1228 for(
int i = n-2; i >= 0; i--)
1231 int d = FullBCRS1<T>::m_rowptr[i];
1232 for(
unsigned int k=d+1; k < FullBCRS1<T>::m_rowptr[i+1]; k++)
1234 int c = FullBCRS1<T>::m_colind[k];
1235 tmp = FullBCRS1<T>::m_blocks[k] * a_x[c];
1239 a_x[i] = a_x[i]/FullBCRS1<T>::m_blocks[FullBCRS1<T>::m_rowptr[i]];
1243 template <
typename T>
1244 inline void UpperTriangularBCRS1<T>::transposeForeSub(std::vector<t_real> &a_x,
const std::vector<t_real> &a_b)
1246 unsigned int n = (
unsigned int)(FullBCRS1<T>::m_rowptr.
size()-1);
1247 for(
unsigned int i = 0 ; i < FullBCRS1<T>::m_rowptr.size(); i++)
1249 m_ptr[i] = FullBCRS1<T>::m_rowptr[i];
1252 a_x[0] = a_b[0] / FullBCRS1<T>::m_blocks[FullBCRS1<T>::m_rowptr[0]];
1254 for(
unsigned int i = 1; i < n; i++)
1257 for(
unsigned int m = 0; m < i; m++)
1259 unsigned int c = FullBCRS1<T>::m_colind[m_ptr[m]];
1260 while(c < i && m_ptr[m] < FullBCRS1<T>::m_rowptr[m+1]-1)
1263 c = FullBCRS1<T>::m_colind[m_ptr[m]];
1268 a_x[i] -= FullBCRS1<T>::m_blocks[m_ptr[m]] * a_x[m];
1272 a_x[i] = a_x[i] / FullBCRS1<T>::m_blocks[FullBCRS1<T>::m_rowptr[i]];
1276 template <
typename T>
1277 inline void UpperTriangularBCRS1<T>::backSolve(std::vector<t_real> &a_x,
const std::vector<t_real> &a_b)
1279 transposeForeSub(m_y, a_b);
1283 template <
typename T>
1284 inline void UpperTriangularBCRS1<T>::incompleteSqrt(
void)
1287 unsigned int n = (
unsigned int)(FullBCRS1<T>::m_rowptr.
size()-1);
1290 for(
unsigned int k = 0; k < n-1; k++)
1292 d = FullBCRS1<T>::m_rowptr[k];
1293 FullBCRS1<T>::m_blocks[d] = sqrt(FullBCRS1<T>::m_blocks[d]);
1294 z = FullBCRS1<T>::m_blocks[d];
1298 for(
unsigned int i=d+1; i < FullBCRS1<T>::m_rowptr[k+1]; i++)
1300 z = FullBCRS1<T>::m_blocks[i] * inv_z;
1302 FullBCRS1<T>::m_blocks[i] = z;
1305 for(
unsigned int i=d+1; i < FullBCRS1<T>::m_rowptr[k+1]; i++)
1307 z = FullBCRS1<T>::m_blocks[i];
1308 unsigned int h = FullBCRS1<T>::m_colind[i];
1311 for(
unsigned int j = FullBCRS1<T>::m_rowptr[h]; j < FullBCRS1<T>::m_rowptr[h+1]; j++)
1313 for(; g < FullBCRS1<T>::m_rowptr[k+1] && FullBCRS1<T>::m_colind[g] <= FullBCRS1<T>::m_colind[j]; g++)
1315 if (FullBCRS1<T>::m_colind[g] == FullBCRS1<T>::m_colind[j])
1318 t = z * FullBCRS1<T>::m_blocks[g];
1319 FullBCRS1<T>::m_blocks[j] = FullBCRS1<T>::m_blocks[j] - t;
1325 d = FullBCRS1<T>::m_rowptr[n-1];
1327 tmp = sqrt(FullBCRS1<T>::m_blocks[d]);
1328 FullBCRS1<T>::m_blocks[d] = tmp;
1339 template<
class T,
class ROW>
1343 for(U32 i = 0; i<matrix.rows(); i++)
1345 for(U32 j = 0; j<matrix.columns(); j++)
1347 s.
catf(
"%6.3f ", matrix(i,j));
1356 #endif // __solve_SparseMatrix_h__ SparseMatrix< T, ROW > & postmultiplyInverseDiagonal(SparseMatrix< T, ROW > &result, const SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix-SparseMatrix multiply where second matrix is presumed diagonal.
Definition: SparseMatrix.h:853
Dense vector - size fixed at construction or reset.
Definition: DenseVector.h:21
SparseMatrix< T, ROW > & operator*=(SparseMatrix< T, ROW > &lhs, const F32 scalar)
SparseMatrix-Scalar multiply in place.
Definition: SparseMatrix.h:945
SparseMatrix< T, ROW > & setIdentity(SparseMatrix< T, ROW > &matrix)
Set matrix to identity matrix.
Definition: SparseMatrix.h:679
void clear(void)
Zero existing values, but do not remove.
Definition: SparseArray.h:128
void transposeTransformVector(const SparseMatrix< T, ROW > &lhs, const DenseVector< T > &in, DenseVector< T > &out)
SparseMatrix-Vector multiply with matrix transposed.
Definition: SparseMatrix.h:911
kernel
Definition: namespace.dox:3
U32 width(const SparseMatrix< T, ROW > &matrix)
Return the horizonatal dimension.
Definition: SparseMatrix.h:591
SparseMatrix< T, ROW > & postmultiplyInverseDiagonal(SparseMatrix< T, ROW > &result, const SparseMatrix< T, ROW > &lhs, const DenseVector< T > &rhs)
SparseMatrix-SparseMatrix multiply where second matrix is a diagonal represented by a vector...
Definition: SparseMatrix.h:875
SparseMatrix< T, ROW > operator-(const SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix subtract.
Definition: SparseMatrix.h:716
SparseMatrix< T, ROW > & premultiplyDiagonal(SparseMatrix< T, ROW > &result, const DenseVector< T > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix-SparseMatrix multiply where first matrix is presumed diagonal.
Definition: SparseMatrix.h:756
void premultiplyInverseDiagonal(DenseVector< T > &result, const SparseMatrix< T, ROW > &diagonal, const DenseVector< T > &vector)
Compute the per-element product of the vector and the inverse diagonal entries.
Definition: SparseMatrix.h:641
DenseVector< T > operator*(const SparseMatrix< T, ROW > &lhs, const DenseVector< T > &rhs)
SparseMatrix-Vector multiply.
Definition: SparseMatrix.h:888
SparseMatrix< T, ROW > & premultiplyDiagonal(SparseMatrix< T, ROW > &result, const SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix-SparseMatrix multiply where first matrix is presumed diagonal.
Definition: SparseMatrix.h:774
SparseMatrix< T, ROW > transpose(const SparseMatrix< T, ROW > &matrix)
Return transpose of matrix.
Definition: SparseMatrix.h:692
String & cat(const char *operand)
Append the current String with the given text.
Definition: String.cc:545
SparseMatrix< T, ROW > operator*(const SparseMatrix< T, ROW > &matrix, const U scalar)
SparseMatrix-Scalar post-multiply.
Definition: SparseMatrix.h:921
U32 entries(void) const
Return the number of actual stored entries.
Definition: SparseArray.h:55
Automatically reference-counted string container.
Definition: String.h:128
void project(Vector< 4, T > &a_r, const Matrix< 4, 4, T > &a_m, const Vector< 4, T > &a_v)
project vector through matrix. divides by transformed w
Definition: Matrix.h:1182
SparseMatrix< T, ROW > & premultiplyInverseDiagonal(SparseMatrix< T, ROW > &result, const SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix-SparseMatrix multiply where first matrix is presumed diagonal.
Definition: SparseMatrix.h:793
SparseMatrix< T, ROW > operator*(const U scalar, const SparseMatrix< T, ROW > &matrix)
SparseMatrix-Scalar pre-multiply.
Definition: SparseMatrix.h:933
SparseMatrix< T, ROW > & premultiplyInverseDiagonal(SparseMatrix< T, ROW > &result, const DenseVector< T > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix-SparseMatrix multiply where first matrix is a diagonal represented with a vector...
Definition: SparseMatrix.h:815
String & catf(const char *fmt,...)
Populate the string as with sPrintf(), but by concatenating the results to the existing string...
Definition: String.cc:554
void transformVector(const SparseMatrix< T, ROW > &lhs, const DenseVector< T > &in, DenseVector< T > &out)
SparseMatrix-Vector multiply with matrix.
Definition: SparseMatrix.h:901
Base for all interfacable components.
Definition: Component.h:20
String print(const SparseArray< T > &rhs, BWORD sparse=FALSE)
Print to a string.
Definition: SparseArray.h:227
SparseMatrix< T, ROW > & postmultiplyDiagonal(SparseMatrix< T, ROW > &result, const SparseMatrix< T, ROW > &lhs, const DenseVector< T > &rhs)
SparseMatrix-SparseMatrix multiply where second matrix is a diagonal.
Definition: SparseMatrix.h:834
U32 height(const SparseMatrix< T, ROW > &matrix)
Return the vertical dimension.
Definition: SparseMatrix.h:600
SparseMatrix< T, ROW > & operator+=(SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix add in place.
Definition: SparseMatrix.h:728
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
SparseMatrix< T, ROW > operator+(const SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix add.
Definition: SparseMatrix.h:704
Dense array of sparse rows.
Definition: ListSparseMatrix.h:25
BWORD isSquare(const SparseMatrix< T, ROW > &matrix)
Return true is matrix is square, otherwise return false.
Definition: SparseMatrix.h:670
SparseMatrix< T, ROW > & operator-=(SparseMatrix< T, ROW > &lhs, const SparseMatrix< T, ROW > &rhs)
SparseMatrix subtract in place.
Definition: SparseMatrix.h:739
void premultiplyDiagonal(DenseVector< T > &result, const SparseMatrix< T, ROW > &diagonal, const DenseVector< T > &vector)
Compute the per-element product of the vector and the diagonal entries.
Definition: SparseMatrix.h:614
void reset(U32 prealloc=FE_SA_PREALLOC)
Remove all existing values.
Definition: SparseArray.h:120
U32 size(void) const
Return the largest index.
Definition: SparseArray.h:40