6 #ifndef MATRIXBLOCKIP_H
7 #define MATRIXBLOCKIP_H
101 void create_general_matrix_row_wise(
int m,
int n,
int nz,
int* &inirowa,
int* &icola,
double* &a);
103 void create_general_matrix_column_wise(
int m,
int n,
int nz,
int* &inicola,
int* &irowa,
double* &a);
105 void create_network_matrix(
int num_arcs,
int num_nodes,
int* &src,
int* &dst,
bool oriented=
true);
107 void create_identity_matrix(
int dim);
109 void create_idty_idty_matrix(
int nrows);
111 void create_diagonal_matrix(
int dim,
double* &d);
113 void create_diag_diag_matrix(
int nrows,
double* &d1,
double* &d2);
133 void create_general_matrix_format_ija(
int m,
int n,
int nz,
int* &row_index,
int* &col_index,
double* &values);
139 void compute_full_matrix(
int numBlocks,
bool sameN,
MatrixBlockIP N[],
bool sameL,
MatrixBlockIP L[],
int numActiveLnk=0,
int *listActiveLnk=NULL);
141 void analyze_D(
int numBlocks,
bool sameL,
MatrixBlockIP L[]);
142 void analyze_D_diagonal(
int numBlocks,
bool sameL,
MatrixBlockIP L[]);
143 void analyze_D_gen_sym_uptr(
int numBlocks,
bool sameL,
MatrixBlockIP L[]);
145 void compute_D(
int numBlocks,
bool sameL,
MatrixBlockIP L[],
bool isActive[],
int iniTheta[],
double Theta[]);
146 void compute_D_diagonal(
int numBlocks,
bool sameL,
MatrixBlockIP L[],
bool isActive[],
int iniTheta[],
double Theta[]);
147 void compute_D_gen_sym_uptr(
int numBlocks,
bool sameL,
MatrixBlockIP L[],
bool isActive[],
int iniTheta[],
double Theta[]);
152 void native_to_general(
bool delete_native_format=
false);
154 void ija_to_rowwise();
156 void network_to_general();
158 void identity_to_general();
160 void diagonal_to_general();
162 void idty_idty_to_general();
164 void diag_diag_to_general();
167 void network_to_ija_format();
169 void identity_to_ija_format();
171 void diagonal_to_ija_format();
173 void idty_idty_to_ija_format();
175 void diag_diag_to_ija_format();
181 void mul_Mv(
double vout[],
const double vin[]);
183 void mul_Mtv(
double vout[],
const double vin[]);
185 void add_mul_Mv(
double vout[],
const double vin[]);
187 void add_mul_Mtv(
double vout[],
const double vin[]);
189 void exist_var_in_row(
int column,
bool appear[],
double coefs[]);
191 void add_new_column(
int size,
int irows[],
double values[]);
193 void add_new_columns(
int num_columns,
int size[],
int *irows[],
double *values[]);
195 void change_columns_sign(
int size,
int columns[]);
197 void change_rows_sign(
int size,
int rows[]);
199 void delete_rows(
int size,
int rows[]);
201 int get_column(
int column,
int* &irows,
double* &values,
bool invert_sign=
false);
206 void numeric_fact_MMt(
double *Theta,
int i_k=0);
210 void numeric_fact_M();
219 int get_num_zero_pivots();
220 int get_num_semidef_matrix();
223 void print_matrix(
bool ija=
true,
bool start_one=
true);
224 void print_matrix(ofstream &outfile,
bool print_ija=
true,
bool start_one=
true);
226 void print_vector(
double *v,
int size,
string name);
230 void column_wise_to_row_wise_format();
234 void row_wise_to_column_wise_format();
241 void mul_Mv_row_wise(
double vout[],
const double vin[]);
242 void mul_Mtv_row_wise(
double vout[],
const double vin[]);
243 void add_mul_Mv_row_wise(
double vout[],
const double vin[]);
244 void add_mul_Mtv_row_wise(
double vout[],
const double vin[]);
246 void mul_Mv_column_wise(
double vout[],
const double vin[]);
247 void mul_Mtv_column_wise(
double vout[],
const double vin[]);
248 void add_mul_Mv_column_wise(
double vout[],
const double vin[]);
249 void add_mul_Mtv_column_wise(
double vout[],
const double vin[]);
251 void mul_Mv_network(
double vout[],
const double vin[]);
252 void mul_Mtv_network(
double vout[],
const double vin[]);
253 void add_mul_Mv_network(
double vout[],
const double vin[]);
254 void add_mul_Mtv_network(
double vout[],
const double vin[]);
256 void mul_Mv_identity(
double vout[],
const double vin[]);
257 void add_mul_Mv_identity(
double vout[],
const double vin[]);
259 void mul_Mv_diagonal(
double vout[],
const double vin[]);
260 void add_mul_Mv_diagonal(
double vout[],
const double vin[]);
262 void mul_Mv_idty_idty(
double vout[],
const double vin[]);
263 void mul_Mtv_idty_idty(
double vout[],
const double vin[]);
264 void add_mul_Mv_idty_idty(
double vout[],
const double vin[]);
265 void add_mul_Mtv_idty_idty(
double vout[],
const double vin[]);
267 void mul_Mv_diag_diag(
double vout[],
const double vin[]);
268 void mul_Mtv_diag_diag(
double vout[],
const double vin[]);
269 void add_mul_Mv_diag_diag(
double vout[],
const double vin[]);
270 void add_mul_Mtv_diag_diag(
double vout[],
const double vin[]);
272 void mul_Mv_gen_sym_uptr(
double vout[],
const double vin[]);
273 void add_mul_Mv_gen_sym_uptr(
double vout[],
const double vin[]);
276 void order_packed_format(
int begsize,
int nz,
int* &beg,
int* &ind,
double* &val);
282 bool operator() (
int i,
int j)
284 return ((row[i] < row[j]) || ((row[i] == row[j]) && (col[i] < col[j])));
291 bool operator() (
int i,
int j)
293 return (v[i] < v[j]);
302 chol.initialize(chslv,type,type_orientation);
308 chol.symbolic_fact_MMt(m, n, nz, icola, inirowa, a, num_blocks, prov_pfa, prov_ipfa, prov_pfa_numbering);
311 chol.symbolic_fact_MMt(num_nodes, num_arcs, src, dst, num_blocks, prov_pfa, prov_ipfa, prov_pfa_numbering);
315 chol.symbolic_fact_MMt(m, num_blocks);
318 chol.symbolic_fact_MMt(m,d1,num_blocks);
321 chol.symbolic_fact_MMt(m,d1,d2,num_blocks);
334 if (!made_symbfct_MMt) {
336 made_symbfct_MMt=
true;
339 chol.numeric_fact_MMt(Theta, i_k);
347 chol.numeric_solve_MMt(rhs, i_k, whoperm);
353 chol.initialize(chslv,type,type_orientation);
360 chol.symbolic_fact_M(m);
363 chol.symbolic_fact_M(m, nz, icola, inirowa, prov_pfa, prov_ipfa, prov_pfa_numbering);
376 if (!made_symbfct_M) {
378 made_symbfct_M=
true;
383 chol.numeric_fact_M(d1);
386 chol.numeric_fact_M(a);
398 chol.numeric_solve_M(rhs, whoperm);
408 return(chol.get_pfa(i));
418 return(chol.get_ipfa(i));
428 return (chol.get_maxlnz());
438 return (chol.get_maxfillin());
448 return (chol.get_njka());
458 return (chol.get_num_zero_pivots());
468 return (chol.get_num_semidef_matrix());
482 column_wise_to_row_wise_format();
491 network_to_general();
494 identity_to_general();
497 diagonal_to_general();
500 idty_idty_to_general();
503 diag_diag_to_general();
506 if (delete_native_format) {
523 identity_to_ija_format();
531 diagonal_to_ija_format();
539 idty_idty_to_ija_format();
547 diag_diag_to_ija_format();
562 for(j=inirowa[i];j<=inirowa[i+1]-1;++j) vout[i]+= a[j]*vin[icola[j]];
576 for(i=0;i<n;++i) vout[i]= 0.0;
579 for(j=inirowa[i];j<=inirowa[i+1]-1;++j) vout[icola[j]]+= r*a[j];
593 for(j=inirowa[i];j<=inirowa[i+1]-1;++j) vout[i]+= a[j]*vin[icola[j]];
609 for(j=inirowa[i];j<=inirowa[i+1]-1;++j) vout[icola[j]]+= r*a[j];
623 for(i=0;i<m;++i) vout[i]= 0.0;
626 for(j=inicola[i];j<inicola[i+1];++j) vout[irowa[j]]+= r*a[j];
641 for(j=inicola[i];j<inicola[i+1];++j) vout[i]+= a[j]*vin[irowa[j]];
657 for(j=inicola[i];j<inicola[i+1];++j) vout[irowa[j]]+= r*a[j];
671 for(j=inicola[i];j<inicola[i+1];++j) vout[i]+= a[j]*vin[irowa[j]];
685 double backvoutm= vout[m];
691 for(i=0;i<m+1;i++) vout[i]= 0;
693 for(i=0;i<num_arcs;++i) {
694 vout[src[i]]+= vin[i];
695 vout[dst[i]]-= vin[i];
706 for(i=0;i<m+1;i++) vout[i]= 0;
708 for(i=0;i<num_arcs;++i) {
710 vout[src[i]]+= vin[i];
711 vout[dst[i]]-= vin[i];
713 vout[src[i]]-= vin[i+num_arcs];
714 vout[dst[i]]+= vin[i+num_arcs];
731 vinback=
const_cast<double *
>(vin);
732 double backvinm= vin[m];
739 for(i=0;i<num_arcs;++i) {
741 vout[i]+= vin[src[i]];
742 vout[i]-= vin[dst[i]];
753 for(i=0;i<num_arcs;++i) {
756 vout[i]+= vin[src[i]];
757 vout[i]-= vin[dst[i]];
759 vout[i+num_arcs]= -vout[i];
762 vinback[m]= backvinm;
775 double backvoutm= vout[m];
782 for(i=0;i<num_arcs;++i) {
783 vout[src[i]]+= vin[i];
784 vout[dst[i]]-= vin[i];
796 for(i=0;i<num_arcs;++i) {
798 vout[src[i]]+= vin[i];
799 vout[dst[i]]-= vin[i];
801 vout[src[i]]-= vin[i+num_arcs];
802 vout[dst[i]]+= vin[i+num_arcs];
819 vinback=
const_cast<double *
>(vin);
820 double backvinm= vin[m];
827 for(i=0;i<num_arcs;++i) {
828 vout[i]+= vin[src[i]];
829 vout[i]-= vin[dst[i]];
840 for(i=0;i<num_arcs;++i) {
841 double raux= vin[src[i]]-vin[dst[i]];
845 vout[i+num_arcs]= -raux;
848 vinback[m]= backvinm;
859 for (
int i= 0; i < n; ++i) vout[i]= vin[i];
870 for (
int i= 0; i < n; ++i) vout[i]+= vin[i];
880 for (
int i= 0; i < n; ++i) vout[i]= d1[i]*vin[i];
891 for (
int i= 0; i < n; ++i) vout[i]+= d1[i]*vin[i];
902 for (
int i= 0, j=m; i<m; i++, j++) vout[i]= vin[i]+vin[j];
912 for (
int i= 0, j=m; i<m; i++, j++) {
925 for (
int i= 0, j=m; i<m; i++, j++) vout[i]+= vin[i]+vin[j];
935 for (
int i= 0, j=m; i<m; i++, j++) {
948 for (
int i= 0, j=m; i<m; i++, j++) vout[i]= d1[i]*vin[i]+d2[i]*vin[j];
958 for (
int i= 0, j=m; i<m; i++, j++) {
959 vout[i]= d1[i]*vin[i];
960 vout[j]= d2[i]*vin[i];
971 for (
int i= 0, j=m; i<m; i++, j++) vout[i]+= d1[i]*vin[i]+d2[i]*vin[j];
981 for (
int i= 0, j=m; i<m; i++, j++) {
982 vout[i]+= d1[i]*vin[i];
983 vout[j]+= d2[i]*vin[i];
994 for(
int i=0;i<m;i++) vout[i]= 0.0;
995 for(
int i=0;i<m;i++){
996 for(
int l=inirowa[i];l<=inirowa[i+1]-1;l++) {
998 vout[i]+= a[l]*vin[j];
999 if (i != j) vout[j]+= a[l]*vin[i];
1011 for(
int i=0;i<m;i++){
1012 for(
int l=inirowa[i];l<=inirowa[i+1]-1;l++) {
1014 vout[i]+= a[l]*vin[j];
1015 if (i != j) vout[j]+= a[l]*vin[i];
1030 if (!made_analyze_D) {
1031 analyze_D(numBlocks,sameL,L);
1032 made_analyze_D=
true;
1036 compute_D_diagonal(numBlocks,sameL,L,isActive,iniTheta,Theta);
1038 compute_D_gen_sym_uptr(numBlocks,sameL,L,isActive,iniTheta,Theta);
1054 int sizeL= sameL ? 1 : numBlocks;
1056 for(
int i=0 ; i<sizeL && is_diag ;i++) {
1063 analyze_D_diagonal(numBlocks, sameL, L);
1069 analyze_D_gen_sym_uptr(numBlocks, sameL, L);
1074 #endif //MATRIXBLOCKIP_H