20 #ifndef BLITZ_LU_SOLVE_INTERFACE_HH 21 #define BLITZ_LU_SOLVE_INTERFACE_HH 23 #include "blitz/array.h" 26 BZ_USING_NAMESPACE(blitz)
59 for (
int j=col_start ;
j<col_end+1 ;
j++){
77 for (
int j=col_start ;
j<col_end+1 ;
j++){
79 somme+=
A(row,
j)*
B(
j+row_shift,col);
87 inline static void LU_factor(gene_matrix & LU, Pivot_Vector & pivot,
int N)
90 ASSERT( LU.rows()==LU.cols() ) ;
96 gene_vector ImplicitScaling( N ) ;
97 for(
int i=0;
i<
N;
i++ ) {
99 for(
int j=0;
j<
N;
j++ ) {
100 if(
abs( LU(
i,
j ) )>=big ) big =
abs( LU(
i,
j ) ) ;
103 INFOS(
"blitz_LU_factor::Singular matrix" ) ;
106 ImplicitScaling(
i ) = 1./big ;
109 for(
int j=0;
j<
N;
j++ ) {
110 for(
int i=0;
i<
j;
i++ ) {
111 theSum = LU(
i, j ) ;
112 theSum -= matrix_matrix_product_sliced(LU,
i, 0,
i-1, LU, 0, j) ;
114 LU(
i, j ) = theSum ;
119 for(
int i=j;
i<
N;
i++ ) {
120 theSum = LU(
i, j ) ;
121 theSum -= matrix_matrix_product_sliced(LU,
i, 0, j-1, LU, 0, j) ;
123 LU(
i, j ) = theSum ;
124 if( (ImplicitScaling(
i )*
abs( theSum ))>=big ) {
125 dum = ImplicitScaling(
i )*
abs( theSum ) ;
132 for(
int k=0; k<
N; k++ ) {
133 dum = LU( index_max, k ) ;
134 LU( index_max, k ) = LU( j, k ) ;
137 ImplicitScaling( index_max ) = ImplicitScaling( j ) ;
139 pivot( j ) = index_max ;
140 if ( LU( j, j )==0. ) LU( j, j ) = 1.e-20 ;
143 dum = 1./LU( j, j ) ;
144 for(
int i=j+1;
i<
N;
i++ ) LU(
i, j ) *= dum ;
150 inline static void LU_solve(
const gene_matrix & LU,
const Pivot_Vector pivot, gene_vector &
B, gene_vector
X,
int N)
155 ASSERT( LU.rows()==LU.cols() ) ;
160 for(
int i=0;
i<
N;
i++ ) {
161 int ip = pivot(
i ) ;
167 theSum -= matrix_vector_product_sliced(LU, X,
i, ii-1,
i-1) ;
170 }
else if( theSum ) {
177 for(
int i=N-1;
i>=0;
i-- ) {
180 theSum -= matrix_vector_product_sliced(LU, X,
i,
i+1, N) ;
184 X(
i ) = theSum/LU(
i,
i ) ;
blitz::Array< real, 2 > gene_matrix
blitz_interface< real >::gene_vector gene_vector
blitz::Array< int, 1 > Pivot_Vector
static void LU_factor(gene_matrix &LU, Pivot_Vector &pivot, int N)
Matrix< SCALARA, Dynamic, Dynamic > A
Matrix< SCALARB, Dynamic, Dynamic > B
#define ASSERT(expression)
static void LU_solve(const gene_matrix &LU, const Pivot_Vector pivot, gene_vector &B, gene_vector X, int N)
static void new_Pivot_Vector(Pivot_Vector &pivot, int N)
static real matrix_matrix_product_sliced(gene_matrix &A, int row, int col_start, int col_end, gene_matrix &B, int row_shift, int col)
blitz_interface< real >::gene_matrix gene_matrix
static void free_Pivot_Vector(Pivot_Vector &pivot)
static real matrix_vector_product_sliced(const gene_matrix &A, gene_vector B, int row, int col_start, int col_end)
blitz::Array< real, 1 > gene_vector