48 #include "ConstrainedOptPack_MatrixSymPosDefBandedChol.hpp"
49 #include "DenseLinAlgPack_AssertOp.hpp"
50 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
51 #include "DenseLinAlgPack_BLAS_Cpp.hpp"
52 #include "MiReleaseResource_ref_count_ptr.h"
53 #include "MiWorkspacePack.h"
59 FORTRAN_FUNC_DECL_UL(
void,DPBTRF,dpbtrf)(
60 FORTRAN_CONST_CHAR_1_ARG(UPLO)
61 ,
const FortranTypes::f_int &N
62 ,
const FortranTypes::f_int &KD
63 ,FortranTypes::f_dbl_prec *AB
64 ,
const FortranTypes::f_int &LDAB
65 ,FortranTypes::f_int *INFO
68 FORTRAN_FUNC_DECL_UL(
void,DPBTRS,dpbtrs)(
69 FORTRAN_CONST_CHAR_1_ARG(UPLO)
70 ,
const FortranTypes::f_int &N
71 ,
const FortranTypes::f_int &KD
72 ,
const FortranTypes::f_int &NRHS
73 ,
const FortranTypes::f_dbl_prec AB[]
74 ,
const FortranTypes::f_int &LDAB
75 ,FortranTypes::f_dbl_prec *B
76 ,
const FortranTypes::f_int &LDB
77 ,FortranTypes::f_int *INFO
82 namespace ConstrainedOptPack {
88 ,
const release_resource_ptr_t& MB_release_resource_ptr
91 ,
const release_resource_ptr_t& UB_release_resource_ptr
97 initialize(n,kd,MB,MB_release_resource_ptr,MB_uplo
98 ,UB,UB_release_resource_ptr,UB_uplo,update_factor,scale);
105 ,
const release_resource_ptr_t& MB_release_resource_ptr
108 ,
const release_resource_ptr_t& UB_release_resource_ptr
118 throw std::invalid_argument(
119 "MatrixSymPosDefBandedChol::initialize(...): Error, "
120 "kd must be 0 if n == 0" );
122 throw std::invalid_argument(
123 "MatrixSymPosDefBandedChol::initialize(...): Error, "
124 "MB must be NULL if n == 0" );
125 if( MB_release_resource_ptr.get() != NULL )
126 throw std::invalid_argument(
127 "MatrixSymPosDefBandedChol::initialize(...): Error, "
128 "MB_release_resource_ptr.get() must be NULL if n == 0" );
130 throw std::invalid_argument(
131 "MatrixSymPosDefBandedChol::initialize(...): Error, "
132 "UB must be NULL if n == 0" );
133 if( UB_release_resource_ptr.get() != NULL )
134 throw std::invalid_argument(
135 "MatrixSymPosDefBandedChol::initialize(...): Error, "
136 "UB_release_resource_ptr.get() must be NULL if n == 0" );
140 throw std::invalid_argument(
141 "MatrixSymPosDefBandedChol::initialize(...): Error, "
142 "kd + 1 can not be larger than n" );
143 if( MB == NULL && UB == NULL )
144 throw std::invalid_argument(
145 "MatrixSymPosDefBandedChol::initialize(...): Error, "
146 "MB and UB can not both be NULL" );
147 if( MB != NULL && ( MB->rows() != kd + 1 || MB->cols() != n ) )
148 throw std::invalid_argument(
149 "MatrixSymPosDefBandedChol::initialize(...): Error, "
150 "MB is not the correct size" );
151 if( UB != NULL && ( UB->rows() != kd + 1 || UB->cols() != n ) )
152 throw std::invalid_argument(
153 "MatrixSymPosDefBandedChol::initialize(...): Error, "
154 "UB is not the correct size" );
162 MB_.bind(DMatrixSlice());
163 MB_release_resource_ptr_ = NULL;
164 MB_uplo_ = BLAS_Cpp::lower;
165 UB_.bind(DMatrixSlice());
166 UB_release_resource_ptr_ = NULL;
167 UB_uplo_ = BLAS_Cpp::lower;
174 if(MB) MB_.bind(*MB);
175 MB_release_resource_ptr_ = MB_release_resource_ptr;
177 if(UB) UB_.bind(*UB);
178 UB_release_resource_ptr_ = UB_release_resource_ptr;
180 factor_updated_ = UB && !update_factor;
184 update_factorization();
197 return (2 * kd_ + 1) * n_ - ( (kd_+1)*(kd_+1) - (kd_+1) );
202 return MatrixOp::output(out);
207 ,
const DVectorSlice& x, value_type b)
const
209 assert_initialized();
210 DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_,
BLAS_Cpp::no_trans, x.size() );
212 BLAS_Cpp::sbmv(MB_uplo_,n_,kd_,a,MB_.col_ptr(1),MB_.max_rows(),x.raw_ptr(),x.stride()
213 ,b,y->raw_ptr(),y->stride());
215 else if( UB_.rows() ) {
225 ,
const SpVectorSlice& x, value_type b)
const
227 assert_initialized();
232 DVectorSlice* y, value_type a
235 ,
const DVectorSlice& x, value_type b)
const
237 assert_initialized();
242 DVectorSlice* y, value_type a
245 ,
const SpVectorSlice& x, value_type b)
const
247 assert_initialized();
255 ,
const DVectorSlice& x)
const
260 assert_initialized();
262 DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_,
BLAS_Cpp::no_trans, x.size() );
264 update_factorization();
266 Workspace<value_type> t_ws(wss,y->size());
267 DVectorSlice t(&t_ws[0],t_ws.size());
271 FortranTypes::f_int info = 0;
272 FORTRAN_FUNC_CALL_UL(DPBTRS,dpbtrs)(
273 FORTRAN_CHAR_1_ARG_CALL(UB_uplo_ == BLAS_Cpp::upper ?
'U' :
'L')
274 , n_, kd_, 1, UB_.col_ptr(1), UB_.max_rows()
275 ,&t[0], t.size(), &info );
279 std::ostringstream omsg;
281 <<
"MatrixSymPosDefBandedChol::update_factorization(): Error, "
282 <<
"The " << -info <<
" argument passed to xPBTRF(...) is invalid!";
283 throw std::invalid_argument(omsg.str());
290 void MatrixSymPosDefBandedChol::assert_initialized()
const
293 throw std::logic_error(
"MatrixSymPosDefBandedChol::assert_initialized(): Error, "
294 "not initialized!" );
297 void MatrixSymPosDefBandedChol::update_factorization()
const
299 namespace rcp = MemMngPack;
301 namespace rmp = MemMngPack;
303 if( !factor_updated_ ) {
304 if(UB_.rows() == 0) {
307 typedef rmp::ReleaseResource_ref_count_ptr<DMatrix> UB_rel_ptr_t;
309 UB_rel_ptr_ptr_t UB_rel_ptr_ptr =
new UB_rel_ptr_t(
new DMatrix);
310 UB_rel_ptr_ptr->ptr->resize(kd_+1,n_);
311 UB_.bind( (*UB_rel_ptr_ptr->ptr)() );
312 UB_release_resource_ptr_ = Teuchos::rcp_implicit_cast<rmp::ReleaseResource>(UB_rel_ptr_ptr);
317 FortranTypes::f_int info = 0;
318 FORTRAN_FUNC_CALL_UL(DPBTRF,dpbtrf)(
319 FORTRAN_CHAR_1_ARG_CALL(UB_uplo_ == BLAS_Cpp::upper ?
'U' :
'L')
320 , n_, kd_, UB_.col_ptr(1), UB_.max_rows(), &info );
322 std::ostringstream omsg;
324 <<
"MatrixSymPosDefBandedChol::update_factorization(): Error, "
325 <<
"The " << -info <<
" argument passed to xPBTRF(...) is invalid!";
326 throw std::invalid_argument(omsg.str());
329 std::ostringstream omsg;
331 <<
"MatrixSymPosDefBandedChol::update_factorization(): Error, "
332 <<
"The leading minor of order " << info <<
" passed to xPBTRF(...) is not positive definite!";
333 throw std::invalid_argument(omsg.str());
335 factor_updated_ =
true;
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 &vs_rhs3, value_type beta) const
BLAS_Cpp::Uplo MB_uplo() const
std::ostream & output(std::ostream &out) const
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_StMtV(DVectorSlice *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2, value_type beta) const
void V_InvMtV(DVectorSlice *vs_lhs, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2) const
With throw exception if factorization is not allowed.
void initialize(size_type n=0, size_type kd=0, DMatrixSlice *MB=NULL, const release_resource_ptr_t &MB_release_resource_ptr=NULL, BLAS_Cpp::Uplo MB_uplo=BLAS_Cpp::lower, DMatrixSlice *UB=NULL, const release_resource_ptr_t &UB_release_resource_ptr=NULL, BLAS_Cpp::Uplo UB_uplo=BLAS_Cpp::lower, bool update_factor=false, value_type scale=1.0)
Initialize.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void M_StM(MatrixOp *M_lhs, value_type alpha, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs)
BLAS_Cpp::Uplo UB_uplo() 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)
MatrixSymPosDefBandedChol(size_type n=0, size_type kd=0, DMatrixSlice *MB=NULL, const release_resource_ptr_t &MB_release_resource_ptr=NULL, BLAS_Cpp::Uplo MB_uplo=BLAS_Cpp::lower, DMatrixSlice *UB=NULL, const release_resource_ptr_t &UB_release_resource_ptr=NULL, BLAS_Cpp::Uplo UB_uplo=BLAS_Cpp::lower, bool update_factor=false, value_type scale=1.0)
Construct and Initialize.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()