44 #include "ConstrainedOptPack_MatrixHessianSuperBasic.hpp"
45 #include "ConstrainedOptPack_initialize_Q_R_Q_X.hpp"
46 #include "AbstractLinAlgPack_GenPermMatrixSliceOp.hpp"
47 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp"
48 #include "AbstractLinAlgPack_SpVectorOp.hpp"
49 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_MatrixOpOut.hpp"
50 #include "DenseLinAlgPack_DVectorClass.hpp"
51 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
52 #include "DenseLinAlgPack_AssertOp.hpp"
54 namespace LinAlgOpPack {
58 namespace ConstrainedOptPack {
69 ,
const EBounds bnd_fixed[]
70 ,
const B_RR_ptr_t& B_RR_ptr
71 ,
const B_RX_ptr_t& B_RX_ptr
73 ,
const B_XX_ptr_t& B_XX_ptr
76 using DenseLinAlgPack::Mp_M_assert_sizes;
85 if( 0 < n_R && n_R < n && i_x_free == NULL ) {
86 throw std::invalid_argument(
87 "MatrixHessianSuperBasic::initialize(...) : Error, "
88 "i_x_free can not be NULL when 0 < n_R < n" );
91 if( 0 < n_X && n_X < n && i_x_fixed == NULL ) {
92 throw std::invalid_argument(
93 "MatrixHessianSuperBasic::initialize(...) : Error, "
94 "i_x_fixed can not be NULL when 0 < n-n_R < n" );
97 if( 0 < n_X && bnd_fixed == NULL ) {
98 throw std::invalid_argument(
99 "MatrixHessianSuperBasic::initialize(...) : Error, "
100 "bnd_fixed can not be NULL when 0 < n-n_R" );
104 if( !B_RR_ptr.get() )
105 throw std::invalid_argument(
106 "MatrixHessianSuperBasic::initialize(...) : Error, "
107 "B_RR_ptr.get() can not be NULL when n_R > 0" );
108 Mp_M_assert_sizes( n_R, n_R,
no_trans, B_RR_ptr->rows(), B_RR_ptr->cols(),
no_trans );
112 if( B_RX_ptr.get() ) {
113 Mp_M_assert_sizes( n_R, n_X,
no_trans, B_RX_ptr->rows(), B_RX_ptr->cols(),
B_RX_trans );
118 if( !B_XX_ptr.get() )
119 throw std::invalid_argument(
120 "MatrixHessianSuperBasic::initialize(...) : Error, "
121 "B_XX_ptr.get() can not be NULL if n_R < n" );
122 Mp_M_assert_sizes( n_X, n_X,
no_trans, B_XX_ptr->rows(), B_XX_ptr->cols(),
no_trans );
126 const bool Q_R_is_idenity = (n_R == n && i_x_fixed == NULL );
127 if( Q_R_is_idenity ) {
128 Q_R_row_i_.resize(0);
129 Q_R_col_j_.resize(0);
132 Q_R_row_i_.resize(n_R);
133 Q_R_col_j_.resize(n_R);
135 Q_X_row_i_.resize(n_X);
136 Q_X_col_j_.resize(n_X);
137 bool test_setup =
true;
139 n_R,n_X,i_x_free,i_x_fixed,test_setup
140 ,!Q_R_is_idenity ? &Q_R_row_i_[0] : NULL
141 ,!Q_R_is_idenity ? &Q_R_col_j_[0] : NULL
143 ,n_X ? &Q_X_row_i_[0] : NULL
144 ,n_X ? &Q_X_col_j_[0] : NULL
149 bnd_fixed_.resize(n_X);
150 {
for(
size_type i = 0; i < n_X; ++i) bnd_fixed_[i] = bnd_fixed[i]; }
164 size_type MatrixHessianSuperBasic::rows()
const
173 ,
const DVectorSlice& x, value_type b
179 using AbstractLinAlgPack::V_MtV;
180 using LinAlgOpPack::V_MtV;
182 DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_, B_trans, x.size() );
189 if(
Q_R().is_identity() ) {
198 else if( n_R_ == 0 ) {
245 ,
const SpVectorSlice& x, value_type b
251 using AbstractLinAlgPack::V_MtV;
252 using LinAlgOpPack::V_MtV;
254 DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_, B_trans, x.size() );
261 if(
Q_R().is_identity() ) {
266 AbstractLinAlgPack::V_MtV( &Q_R_x,
Q_R(),
trans, x );
270 else if( n_R_ == 0 ) {
316 DVectorSlice* y, value_type a
319 ,
const DVectorSlice& x, value_type b )
const
324 using AbstractLinAlgPack::V_MtV;
326 using LinAlgOpPack::V_MtV;
327 namespace slap = AbstractLinAlgPack;
348 LinAlgOpPack::Vp_MtV_assert_sizes(y->size(),P.rows(),P.cols(),P_trans
350 LinAlgOpPack::Vp_MtV_assert_sizes(
BLAS_Cpp::cols( P.rows(), P.cols(), P_trans)
355 slap::V_MtV( &Q_RT_x,
Q_R(),
trans, x );
360 slap::V_MtV( &Q_XT_x,
Q_X(),
trans, x );
364 AbstractLinAlgPack::intersection( P, P_trans,
Q_R(),
no_trans, &P_Q_R_nz );
367 AbstractLinAlgPack::intersection( P, P_trans,
Q_X(),
no_trans, &P_Q_X_nz );
370 else if(b!=1.0)
Vt_S(y,b);
374 if( P_Q_R_nz && Q_RT_x.nz() ) {
380 if( P_Q_R_nz &&
B_RX_ptr().
get() && Q_XT_x.nz() ) {
386 if( P_Q_X_nz &&
B_RX_ptr().
get() && Q_RT_x.nz() ) {
392 if( P_Q_X_nz && Q_XT_x.nz() ) {
401 ,
const SpVectorSlice& x2 )
const
406 DenseLinAlgPack::Vp_MtV_assert_sizes( x1.size(),
rows(),
cols(), B_trans, x1.size() );
413 if(
Q_R().is_identity() ) {
417 if( x1.overlap(x2) == DenseLinAlgPack::SAME_MEM ) {
419 AbstractLinAlgPack::V_MtV( &Q_RT_x2,
Q_R(),
trans, x2 );
420 SpVectorSlice Q_RT_x2_slc = Q_RT_x2();
426 AbstractLinAlgPack::V_MtV( &Q_RT_x2,
Q_R(),
trans, x2 );
428 AbstractLinAlgPack::V_MtV( &Q_RT_x1,
Q_R(),
trans, x1 );
434 else if( n_R_ == 0 ) {
453 if( x1.overlap(x2) == DenseLinAlgPack::SAME_MEM ) {
457 AbstractLinAlgPack::V_MtV( &Q_RT_x1,
Q_R(),
trans, x1 );
460 AbstractLinAlgPack::V_MtV( &Q_XT_x1,
Q_X(),
trans, x1 );
461 SpVectorSlice Q_RT_x1_slc = Q_RT_x1();
462 SpVectorSlice Q_XT_x1_slc = Q_XT_x1();
476 Q_XT_x1_slc, *B_XX_ptr(),
no_trans, Q_XT_x1_slc )
492 throw std::logic_error(
493 "MatrixHessianSuperBasic::assert_initialized() : Error, "
494 "The matrix is not initialized yet" );
virtual void initialize(size_type n, size_type n_R, const size_type i_x_free[], const size_type i_x_fixed[], const EBounds bnd_fixed[], const B_RR_ptr_t &B_RR_ptr, const B_RX_ptr_t &B_RX_ptr, BLAS_Cpp::Transp B_RX_trans, const B_XX_ptr_t &B_XX_ptr)
Initialize the matrix.
value_type transVtMtV(const SpVectorSlice &sv_rhs1, BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice &sv_rhs3) const
MatrixHessianSuperBasic()
Constructs to uninitialized.
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
void Vp_StPtMtV(VectorMutable *v_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, const MatrixOp &M_rhs2, BLAS_Cpp::Transp M_rhs2_trans, const Vector &v_rhs3, value_type beta=1.0)
void Vp_StPtMtV(DVectorSlice *vs_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, BLAS_Cpp::Transp M_rhs2_trans, const DVectorSlice &sv_rhs3, value_type beta) const
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
const GenPermMatrixSlice & Q_X() const
const GenPermMatrixSlice & Q_R() const
value_type transVtMtV(const Vector &v_rhs1, const MatrixOp &M_rhs2, BLAS_Cpp::Transp trans_rhs2, const Vector &v_rhs3)
const B_RR_ptr_t & B_RR_ptr() const
void Vp_StMtV(DVectorSlice *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2, value_type beta) const
const B_XX_ptr_t & B_XX_ptr() const
const B_RX_ptr_t & B_RX_ptr() const
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)
Transp trans_not(Transp _trans)
void assert_initialized() const
BLAS_Cpp::Transp B_RX_trans() const
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)