Commit 8a084ad8 authored by Manuel Günther's avatar Manuel Günther

Removed the last occurrences of ..._ and ..._nocheck functions (now hopefully really)

parent 21c0c84a
Pipeline #10435 passed with stages
in 7 minutes and 54 seconds
......@@ -18,25 +18,25 @@
// Declaration of the external LAPACK function (Divide and conquer SVD)
extern "C" void dggsvd3_(const char *jobu,
const char *jobv,
const char *jobv,
const char *jobq,
const int *M,
const int *N,
const int *P,
const int *K,
const int *L,
double *A,
const int *lda,
double *B,
double *A,
const int *lda,
double *B,
const int *ldb,
double *alpha,
double *beta,
double *U,
const int *ldu,
const int *ldu,
double *V,
const int *ldv,
const int *ldv,
double *Q,
const int *ldq,
const int *ldq,
double *work,
const int *lwork,
int *iwork,
......@@ -61,16 +61,16 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
const int M = A.extent(0);
const int N = A.extent(1);
const int P = B.extent(0);
const int lda = std::max(1,M);
const int ldb = std::max(1,P);
const int ldu = std::max(1,M);
const int ldv = std::max(1,P);
const int ldq = std::max(1,N);
int K = 0; //out
int L = 0; //out
int L = 0; //out
// Prepares to call LAPACK function:
// We will decompose A^T rather than A and B^T rather than B to reduce the required number of copy
// We recall that FORTRAN/LAPACK is column-major order whereas blitz arrays
......@@ -84,21 +84,21 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
//B_lapack = B^T
blitz::Array<double,2> B_blitz_lapack(bob::core::array::ccopy(const_cast<blitz::Array<double,2>&>(B).transpose(1,0)));
double* B_lapack = B_blitz_lapack.data();
// U. We will trainpose this one in the end
double *U_lapack = U.data();
// V. We will trainpose this one in the end
double *V_lapack = V.data();
// For Q, we will return the transpose
// For Q, we will return the transpose
double *Q_lapack = Q.data();
// In LAPACK C and S is 1-d. Our code makes it diagonal
blitz::Array<double,1> C_1d(N); C_1d = 0;
double *C_lapack = C_1d.data();
blitz::Array<double,1> S_1d(N); S_1d = 0;
double *S_lapack = S_1d.data();
......@@ -109,81 +109,81 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
int info = 0;
// A/ Queries the optimal size of the working array
dggsvd3_(&jobu,
&jobv,
&jobv,
&jobq,
&M,
&N,
&P,
&K,
&L,
A_lapack,
&lda,
B_lapack,
A_lapack,
&lda,
B_lapack,
&ldb,
C_lapack,
S_lapack,
U_lapack,
&ldu,
&ldu,
V_lapack,
&ldv,
&ldv,
Q_lapack,
&ldq,
&ldq,
&work_query,
&lwork_query,
iwork.get(),
&info);
if (info != 0)
throw std::runtime_error("The LAPACK dggsvd3 function returned a non-zero value during the checking");
// B/ Computes
const int lwork = static_cast<int>(work_query);
boost::shared_array<double> work(new double[lwork]);
dggsvd3_(&jobu,
&jobv,
&jobv,
&jobq,
&M,
&N,
&P,
&K,
&L,
A_lapack,
&lda,
B_lapack,
A_lapack,
&lda,
B_lapack,
&ldb,
C_lapack,
S_lapack,
U_lapack,
&ldu,
&ldu,
V_lapack,
&ldv,
&ldv,
Q_lapack,
&ldq,
&ldq,
work.get(),
&lwork,
iwork.get(),
&info);
if (info != 0)
throw std::runtime_error("The LAPACK dggsvd3 function returned a non-zero value during the computation.");
/*
/*
According to the website http://www.netlib.org/lapack/explore-html/d1/d7e/group__double_g_esing_ga4a187519e5c71da3b3f67c85e9baf0f2.html#ga4a187519e5c71da3b3f67c85e9baf0f2
if (M-K-L >= 0)
N-K-L K L
( 0 R ) = K ( 0 R11 R12 )
L ( 0 0 R22 )
Where R11, R12, R22, = A(1:K+L,N-K-L+1:N)
else
N-K-L K M-K K+L-M
( 0 R ) = K ( 0 R11 R12 R13 )
M-K ( 0 0 R22 R23 )
......@@ -204,11 +204,11 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
X.resize(r,N);
if (M-K-L >= 0){
//1. First we need the [0 R], which has the shape (N-K-L + K + L, K+L)
//1. First we need the [0 R], which has the shape (N-K-L + K + L, K+L)
zeroR(blitz::Range(0, r-1), blitz::Range(N-r, N-1)) = A_blitz_lapack.transpose(1,0)(blitz::Range(0,r-1), blitz::Range(N-r,N-1));
// 2. Now we have to deal with C and S according to http://www.netlib.org/lapack/lug/node36.html
// In the end C is m-by-r and is p-by-r, both are real, nonnegative and diagonal and C'C + S'S = I ,
// They have the following structure
// They have the following structure
// COPY AND PASTE
//2.1 Preparing C
......@@ -216,16 +216,16 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
// C = K ( I 0 )
// L ( 0 C )
// M-K-L ( 0 0 )
// A - Identity part
if (K>0){
blitz::Array<double,2> I (K,K); I= 0;
bob::math::eye_(I);
bob::math::eye(I);
C(blitz::Range(0, K-1), blitz::Range(0, K-1)) = I;
}
// B - diag(C) part. Here the C is LxL
// Swaping
bob::math::swap_(C_1d, iwork.get(), K, std::min(M,r));
blitz::Array<double,2> C_diag (L,L); C_diag = 0;
bob::math::diag(C_1d(blitz::Range(K,K+L-1)), C_diag);
......@@ -248,7 +248,7 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
//1. First we need the [0 R], which has the shape (N-K-L K M-K K+L-M , k + M-K K+L-M )
//A. First part of R is in A(1:M, N-K-L+1:N)
//A. First part of R is in A(1:M, N-K-L+1:N)
zeroR(blitz::Range(0,M-1), blitz::Range(N-K-L, N-1)) = A_blitz_lapack.transpose(1,0)(blitz::Range(0,M-1) , blitz::Range(N-K-L,N-1));
//B. Second part of R is in B(M-K+1:L,N+M-K-L+1:N)
......@@ -256,7 +256,7 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
//2. Now we have to deal with C and S according to http://www.netlib.org/lapack/lug/node36.html
// In the end C is m-by-r and is p-by-r, both are real, nonnegative and diagonal and C'C + S'S = I ,
// They have the following structure
// They have the following structure
// COPY AND PASTE
//2.1 Preparing C, where C=diag( ALPHA(K+1), ... , ALPHA(M) ),
......@@ -267,7 +267,7 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
// A - Identity part
if (K>0){
blitz::Array<double,2> I (K,K); I = 0;
bob::math::eye_(I);
bob::math::eye(I);
C(blitz::Range(0, K-1), blitz::Range(0, K-1)) = I;
}
......@@ -290,7 +290,7 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
// A - Identity part
if (K+L-M>0){
blitz::Array<double,2> I (K+L-M,K+L-M); I= 0;
bob::math::eye_(I);
bob::math::eye(I);
S(blitz::Range(M-K,L-1), blitz::Range(M,K+L-1)) = I;
}
......@@ -298,7 +298,7 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
// Swaping
blitz::Array<double,1> S_1d_cropped(M-K); S_1d_cropped = 0;
S_1d_cropped = S_1d(blitz::Range(K,K+M-1));
bob::math::swap_(S_1d_cropped, iwork.get(), K, std::min(M,r));
blitz::Array<double,2> S_diag (M,M); S_diag = 0;
bob::math::diag(S_1d_cropped, S_diag);
......@@ -320,10 +320,10 @@ void bob::math::gsvd( blitz::Array<double,2>& A,
bob::math::swap_(V, iwork.get(), K, std::min(M,r));
//Computing X
bob::math::prod_(zeroR, Q, X);
bob::math::prod(zeroR, Q, X);
blitz::Array<double,2> Xt(
bob::core::array::ccopy(const_cast<blitz::Array<double,2>&>(X).transpose(1,0)));
X = Xt;
bob::math::swap_(X, iwork.get(), K, std::min(M,r));
}
}
......@@ -283,7 +283,7 @@ void bob::math::linsolveCGSympos(const blitz::Array<double,2>& A,
while (n_iter < max_iter && delta > acc*acc*delta0)
{
// q = A*d
bob::math::prod_(A, d, q);
bob::math::prod(A, d, q);
// alpha = delta/(d'*q);
double alpha = delta / bob::math::dot(d,q);
......
......@@ -46,5 +46,5 @@ void bob::math::sqrtSymReal(const blitz::Array<double,2>& A,
blitz::firstIndex i;
blitz::secondIndex j;
tmp = V(i,j) * D(j); // tmp = V.sqrt(D)
bob::math::prod_(tmp, Vt, B); // B = V.sqrt(D).V^T
bob::math::prod(tmp, Vt, B); // B = V.sqrt(D).V^T
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment