52 #include "AbstractLinAlgPack/src/DirectSparseFortranCompatibleSolver.h"
53 #include "AbstractLinAlgPack/src/MatrixConvertToSparseFortranCompatible.hpp"
54 #include "AbstractLinAlgPack/test/TestMatrixConvertToSparseFortranCompatible.hpp"
58 namespace ConstrainedOptPack {
61 const direct_solver_ptr_t& direct_solver )
63 direct_solver_(direct_solver)
66 , G_(NULL), convG_(0), G_nz_(0)
67 , A_(NULL), convA_(0), A_nz_(0)
71 const MatrixOp& G,
const MatrixOp&
A
72 , std::ostream*
out, EPrintMoreOrLess print_what, ERunTests test_what )
97 const MatrixOp& G,
const MatrixOp&
A
99 , std::ostream*
out, EPrintMoreOrLess print_what, ERunTests test_what )
114 direct_solver().release_memory();
178 y1 = (*vs_lhs)(1,
n_),
179 y2 = (*vs_lhs)(
n_+1,
n_+
m_);
224 typedef MatrixConvertToSparseFortranCompatible MCTSFC_t;
226 A_nz =
convA_->num_nonzeros(MCTSFC_t::EXTRACT_FULL_MATRIX);
227 nz =
convG_->num_nonzeros( extract_region )
228 + ( extract_region == MCTSFC_t::EXTRACT_FULL_MATRIX ? 2 * A_nz : A_nz );
234 EExtractRegion extract_region
246 if( len_Aval == 0 && len_Aij == 0 ) {
249 <<
"\n*** MatrixKKTFullSpaceRelaxed::coor_extract_nonzeros(...) : "
250 <<
"Warning, nothing to compute: len_Aval==0 && len_Aij==0\n";
257 typedef MatrixConvertToSparseFortranCompatible
259 namespace slaptp = AbstractLinAlgPack::TestingPack;
260 using slaptp::TestMatrixConvertToSparseFortranCompatible;
268 slaptp::ETestSparseFortranFormat
269 sparse_format = slaptp::TEST_COOR_FORMAT;
273 <<
"\n*** Testing conversion interface for submatrix G ...\n";
275 bool result = TestMatrixConvertToSparseFortranCompatible(
276 extract_region,sparse_format,*
convG_,*
G_
277 ,warning_tol,error_tol,
true,
out_
281 char omsg[] =
"MatrixKKTFullSpaceRelaxed : Error, the conversion "
282 "interface for G did not check out\n";
285 << std::endl << omsg;
286 throw std::logic_error(omsg);
291 <<
"\n*** Conversion interface for G checked out!\n";
297 MCTSFC_t::EExtractRegion
298 extract_region = MCTSFC_t::EXTRACT_FULL_MATRIX;
299 slaptp::ETestSparseFortranFormat
300 sparse_format = slaptp::TEST_COOR_FORMAT;
304 <<
"\n*** Testing conversion interface for submatrix A ...\n";
306 bool result = TestMatrixConvertToSparseFortranCompatible(
307 extract_region,sparse_format,*
convA_,*
A_
308 ,warning_tol,error_tol,
true,
out_
312 char omsg[] =
"MatrixKKTFullSpaceRelaxed : Error, the conversion "
313 "interface for A did not check out\n";
316 << std::endl << omsg;
317 throw std::logic_error(omsg);
322 <<
"\n*** Conversion interface for A checked out!\n";
339 typedef MatrixConvertToSparseFortranCompatible MCTSFC_t;
341 switch(extract_region) {
342 case MCTSFC_t::EXTRACT_FULL_MATRIX:
345 case MCTSFC_t::EXTRACT_UPPER_TRIANGULAR:
348 case MCTSFC_t::EXTRACT_LOWER_TRIANGULAR:
358 G_lo_nz =
convG_->num_nonzeros( MCTSFC_t::EXTRACT_LOWER_TRIANGULAR ),
359 A_nz =
convA_->num_nonzeros( MCTSFC_t::EXTRACT_FULL_MATRIX);
361 && (len_Aij == 0 || len_Aij == G_lo_nz + A_nz) );
363 convG_->coor_extract_nonzeros(
364 MCTSFC_t::EXTRACT_LOWER_TRIANGULAR
365 , (len_Aval > 0 ? G_lo_nz : 0), Aval
366 , (len_Aij > 0 ? G_lo_nz : 0), Arow, Acol, 0, 0 );
370 convA_->coor_extract_nonzeros(
371 MCTSFC_t::EXTRACT_FULL_MATRIX
372 , (len_Aval > 0 ? A_nz : 0), Aval+G_lo_nz
373 , (len_Aij > 0 ? A_nz: 0), Acol+G_lo_nz, Arow+G_lo_nz, 0,
n_ );
388 throw NotInitializedException(
"MatrixKKTFullSpaceRelaxed::assert_initialized() : "
389 "Error, called a member function without initialize(...) or "
390 "initialize_relaxed(...) being called first probably" );
397 throw NotInitializedException(
"MatrixKKTFullSpaceRelaxed::assert_matrices_set() : "
398 "Error, the matrices G and A have not been set yet" );
403 const MatrixOp& G,
const MatrixOp&
A )
409 if( G.cols() != n ) {
410 std::ostringstream omsg;
412 <<
"MatrixKKTFullSpaceRelaxed::validate_and_set_matrices(...) : Error, "
413 <<
"The matrix G with rows = " << n
414 <<
" is not square with cols = " << G.cols();
415 throw std::length_error(omsg.str());
417 if( A.rows() != n ) {
418 std::ostringstream omsg;
420 <<
"MatrixKKTFullSpaceRelaxed::validate_and_set_matrices(...) : Error, "
421 <<
"The number of rows in the matrix A with rows = " << A.rows()
423 <<
" does not match the size of G with rows = cols = " << n;
424 throw std::length_error(omsg.str());
426 if( !(m < n) || n == 0 || m == 0 ) {
427 std::ostringstream omsg;
429 <<
"MatrixKKTFullSpaceRelaxed::validate_and_set_matrices(...) : Error, "
430 <<
"the size of the matrices G nxn and A nxm is not valid with "
431 <<
"n = " << n <<
" and m = " << m;
432 throw std::length_error(omsg.str());
435 const MatrixConvertToSparseFortranCompatible
436 *convG =
dynamic_cast<const MatrixConvertToSparseFortranCompatible*
>(&G);
438 std::ostringstream omsg;
440 <<
"MatrixKKTFullSpaceRelaxed::validate_and_set_matrices(...) : Error, "
441 <<
"The matrix G with concrete type " <<
typeName(G)
442 <<
" does not support the MatrixConvertToSparseFortranCompatible "
444 throw InvalidMatrixType(omsg.str());
446 const MatrixConvertToSparseFortranCompatible
447 *convA =
dynamic_cast<const MatrixConvertToSparseFortranCompatible*
>(&
A);
449 std::ostringstream omsg;
451 <<
"MatrixKKTFullSpaceRelaxed::validate_and_set_matrices(...) : Error, "
452 <<
"The matrix A with concrete type " <<
typeName(A)
453 <<
" does not support the MatrixConvertToSparseFortranCompatible "
455 throw InvalidMatrixType(omsg.str());
AbstractLinAlgPack::size_type size_type
std::string typeName(const T &t)
EPrintMoreOrLess print_what_
FortranTypes::f_int f_int
void set_uninitialized()
Set the matrix to uninitialized.
void coor_extract_nonzeros(EExtractRegion extract_region, const FortranTypes::f_int len_Aval, FortranTypes::f_dbl_prec Aval[], const FortranTypes::f_int len_Aij, FortranTypes::f_int Arow[], FortranTypes::f_int Acol[], const FortranTypes::f_int row_offset, const FortranTypes::f_int col_offset) const
const LAPACK_C_Decl::f_int LAPACK_C_Decl::f_dbl_prec * A
void validate_and_set_matrices(const MatrixOp &G, const MatrixOp &A)
Validate the types and sizes of G and A, set the member pointers G_ and A_ and return the conversion ...
FortranTypes::f_int num_nonzeros(EExtractRegion extract_region) const
void Vp_StMtV(DVectorSlice *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2, value_type beta) const
(2) vs_lhs = alpha * op(M_rhs1) * vs_rhs2 + beta * vs_lhs (BLAS xGEMV)
void release_memory()
Clear all allocated storage.
MatrixOp & operator=(const MatrixOp &m)
MatrixKKTFullSpaceRelaxed(const direct_solver_ptr_t &direct_solver=0)
const LAPACK_C_Decl::f_int & M
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta=1.0)
v_lhs = alpha * op(M_rhs1) * v_rhs2 + beta * v_lhs (BLAS xGEMV)
const MatrixConvertToSparseFortranCompatible * convG_
void assert_matrices_set() const
void V_InvMtV(DVectorSlice *v_lhs, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2) const
(1) v_lhs = inv(op(M_rhs1)) * vs_rhs2
void initialize(const MatrixOp &G, const MatrixOp &A, std::ostream *out=0, EPrintMoreOrLess print_what=PRINT_LESS, ERunTests test_what=NO_TESTS)
Initialize the nonrelaxed matrix.
void assert_initialized() const
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
void initialize_relaxed(const MatrixOp &G, const MatrixOp &A, const DVectorSlice &c, value_type bigM=1e+10, std::ostream *out=0, EPrintMoreOrLess print_what=PRINT_LESS, ERunTests test_what=NO_TESTS)
Initialize the relaxed matrix.
AbstractLinAlgPack::value_type value_type
std::ostream & output(std::ostream &out) const
void Vp_MtV_assert_sizes(size_type v_lhs_size, size_type m_rhs1_rows, size_type m_rhs1_cols, BLAS_Cpp::Transp trans_rhs1, size_type v_rhs2_size)
v_lhs += op(m_rhs1) * v_rhs2
FortranTypes::f_dbl_prec f_dbl_prec
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const MatrixConvertToSparseFortranCompatible * convA_