48 #include "ROL_LinearAlgebra.hpp"
49 #include "ROL_LAPACK.hpp"
64 std::vector<Ptr<Vector<Real>>>
Psi_,
Y_;
78 for (
int i = 0; i <
k_; ++i) {
80 if (rii > ROL_EPSILON<Real>()) {
82 for (
int j = i+1; j <
k_; ++j) {
83 rij = Y[i]->dot(*Y[j]);
84 Y[j]->axpy(-rij,*Y[i]);
101 LA::Matrix<Real> Z(
l_,
k_);
102 for (
int i = 0; i <
l_; ++i) {
103 for (
int j = 0; j <
k_; ++j) {
104 Z(i,j) =
Psi_[i]->dot(*
Y_[j]);
113 std::vector<Real> WORK(1);
118 lapack_.GELS(TRANS,M,N,NRHS,Z.values(),LDA,
W_.values(),LDB,&WORK[0],LWORK,&INFO);
119 LWORK =
static_cast<int>(WORK[0]);
121 lapack_.GELS(TRANS,M,N,NRHS,Z.values(),LDA,
W_.values(),LDB,&WORK[0],LWORK,&INFO);
124 std::vector<Real> S(N);
127 lapack_.GELSS(M,N,NRHS,Z.values(),LDA,
W_.values(),LDB,&S[0],RCOND,&RANK,&WORK[0],LWORK,&INFO);
128 LWORK =
static_cast<int>(WORK[0]);
130 lapack_.GELSS(M,N,NRHS,Z.values(),LDA,
W_.values(),LDB,&S[0],RCOND,&RANK,&WORK[0],LWORK,&INFO);
137 bool testQ(std::ostream &outStream = std::cout,
const int verbosity = 0) {
138 const Real one(1), tol(std::sqrt(ROL_EPSILON<Real>()));
140 Real qij(0), err(0), maxerr(0);
141 std::ios_base::fmtflags oflags(outStream.flags());
143 outStream << std::scientific << std::setprecision(3);
146 outStream << std::endl
147 <<
" Printing Q'Q...This should be approximately equal to I"
148 << std::endl << std::endl;
150 for (
int i = 0; i <
k_; ++i) {
151 for (
int j = 0; j <
k_; ++j) {
152 qij =
Y_[i]->dot(*
Y_[j]);
153 err = (i==j ? std::abs(qij-one) : std::abs(qij));
154 maxerr = (err > maxerr ? err : maxerr);
156 outStream << std::setw(12) << std::right << qij;
160 outStream << std::endl;
164 outStream << std::endl <<
" TEST ORTHOGONALIZATION: Max Error = "
165 << std::setw(12) << std::right << maxerr
167 outStream.flags(oflags);
169 return (maxerr < tol ?
true :
false);
175 for (
int i = 0; i <
l_; ++i) {
176 Psi_[i]->randomize(-one,one);
177 for (
int j = 0; j <
ncol_; ++j) {
178 W_(i,j) =
static_cast<Real
>(0);
181 Real a(2), b(-1), x(0);
182 for (
int i = 0; i <
k_; ++i) {
184 for (
int j = 0; j <
ncol_; ++j) {
185 x =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
202 for (
int i = 0; i <
l_; ++i) {
205 for (
int i = 0; i <
k_; ++i) {
229 if ( col >=
ncol_ ) {
234 for (
int i = 0; i <
k_; ++i) {
239 for (
int i = 0; i <
l_; ++i) {
240 for (
int j = 0; j <
ncol_; ++j) {
253 if ( col >=
ncol_ ) {
262 for (
int i = 0; i <
k_; ++i) {
267 bool test(
const int rank, std::ostream &outStream = std::cout,
const int verbosity = 0) {
268 const Real one(1), tol(std::sqrt(ROL_EPSILON<Real>()));
270 std::vector<Ptr<Vector<Real>>> U(rank);
271 LA::Matrix<Real>
V(
ncol_,rank);
272 for (
int i = 0; i < rank; ++i) {
273 U[i] =
Y_[0]->clone();
274 U[i]->randomize(-one,one);
275 for (
int j = 0; j <
ncol_; ++j) {
276 V(j,i) =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
281 std::vector<Ptr<Vector<Real>>> A(
ncol_);
282 for (
int i = 0; i <
ncol_; ++i) {
283 A[i] =
Y_[0]->clone(); A[i]->zero();
284 for (
int j = 0; j < rank; ++j) {
285 A[i]->axpy(
V(i,j),*U[j]);
290 bool flagQ =
testQ(outStream, verbosity);
292 Real nerr(0), maxerr(0);
293 Ptr<Vector<Real>> err =
Y_[0]->clone();
294 for (
int i = 0; i <
ncol_; ++i) {
296 err->axpy(-one,*A[i]);
298 maxerr = (nerr > maxerr ? nerr : maxerr);
301 std::ios_base::fmtflags oflags(outStream.flags());
302 outStream << std::scientific << std::setprecision(3);
303 outStream <<
" TEST RECONSTRUCTION: Max Error = "
304 << std::setw(12) << std::right << maxerr
305 << std::endl << std::endl;
306 outStream.flags(oflags);
308 return flagQ & (maxerr < tol ?
true :
false);
std::vector< Ptr< Vector< Real > > > Y_
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Contains definitions of custom data types in ROL.
Provides an interface for randomized sketching.
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
virtual Real dot(const Vector &x) const =0
Compute where .
void reconstruct(Vector< Real > &a, const int col)
ROL::LAPACK< int, Real > lapack_
bool testQ(std::ostream &outStream=std::cout, const int verbosity=0)
void mgs(std::vector< Ptr< Vector< Real >>> &Y) const
std::vector< Ptr< Vector< Real > > > Psi_
Sketch(const Vector< Real > &x, const int ncol, const int rank, const int solverType=0)
void setRank(const int rank)
bool test(const int rank, std::ostream &outStream=std::cout, const int verbosity=0)
LA::Matrix< Real > Omega_
void advance(const Real alpha, Vector< Real > &h, const int col, const Real beta=1.0)