44 #include "AbstractLinAlgPack_GenPermMatrixSliceOp.hpp"
45 #include "AbstractLinAlgPack_SpVectorOp.hpp"
46 #include "AbstractLinAlgPack_SpVectorClass.hpp"
47 #include "DenseLinAlgPack_DVectorClass.hpp"
48 #include "AbstractLinAlgPack_LinAlgOpPackHack.hpp"
49 #include "DenseLinAlgPack_AssertOp.hpp"
51 void AbstractLinAlgPack::V_StMtV(
52 SpVector* y, value_type a,
const GenPermMatrixSlice& P
57 namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
58 using DenseLinAlgPack::MtV_assert_sizes;
60 MtV_assert_sizes( P.rows(), P.cols(), P_trans, x.dim() );
62 y->resize(
BLAS_Cpp::rows( P.rows(), P.cols(), P_trans ), P.nz() );
64 typedef SpVector::element_type ele_t;
66 if( P.is_identity() ) {
67 for(
size_type i = 1; i <= P.nz(); ++i ) {
68 const value_type x_j = x(i);
70 y->add_element( ele_t( i, a * x_j ) );
74 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
78 const value_type x_j = x(j);
80 y->add_element( ele_t( i, a * x_j ) );
84 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
88 const value_type x_j = x(j);
90 y->add_element( ele_t( i, a * x_j ) );
93 if( P.ordered_by() == GPMSIP::BY_ROW_AND_COL
94 || ( P_trans ==
no_trans && P.ordered_by() == GPMSIP::BY_ROW )
95 || ( P_trans ==
trans && P.ordered_by() == GPMSIP::BY_COL ) )
97 y->assume_sorted(
true);
101 void AbstractLinAlgPack::V_StMtV(
102 SpVector* y, value_type a,
const GenPermMatrixSlice& P
107 namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
108 using DenseLinAlgPack::MtV_assert_sizes;
109 MtV_assert_sizes( P.rows(), P.cols(), P_trans, x.dim() );
111 y->resize(
BLAS_Cpp::rows( P.rows(), P.cols(), P_trans ), P.nz() );
113 typedef SpVector::element_type ele_t;
114 const SpVectorSlice::element_type *ele_ptr;
116 if( P.is_identity() ) {
117 AbstractLinAlgPack::add_elements( y, 1.0, x(1,P.nz()) );
120 else if( x.is_sorted() ) {
122 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
126 if( ele_ptr = x.lookup_element(j) )
127 y->add_element( ele_t( i, a * ele_ptr->value() ) );
131 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
135 if( ele_ptr = x.lookup_element(j) )
136 y->add_element( ele_t( i, a * ele_ptr->value() ) );
143 if( P.ordered_by() == GPMSIP::BY_ROW_AND_COL
144 || ( P_trans ==
no_trans && P.ordered_by() == GPMSIP::BY_ROW )
145 || ( P_trans ==
trans && P.ordered_by() == GPMSIP::BY_COL ) )
147 y->assume_sorted(
true);
152 SpVector* y, value_type a,
const GenPermMatrixSlice& P
157 namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
158 using DenseLinAlgPack::Vp_MtV_assert_sizes;
160 Vp_MtV_assert_sizes( y->dim(), P.rows(), P.cols(), P_trans, x.dim() );
162 typedef SpVector::element_type ele_t;
164 const bool was_sorted = y->is_sorted();
166 if( P.is_identity() ) {
167 for(
size_type i = 1; i <= P.nz(); ++i ) {
168 const value_type x_j = x(i);
170 y->add_element( ele_t( i, a * x_j ) );
174 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
178 const value_type x_j = x(j);
180 y->add_element( ele_t( i, a * x_j ) );
184 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
188 const value_type x_j = x(j);
190 y->add_element( ele_t( i, a * x_j ) );
194 ( P.ordered_by() == GPMSIP::BY_ROW_AND_COL
195 || ( P_trans ==
no_trans && P.ordered_by() == GPMSIP::BY_ROW )
196 || ( P_trans ==
trans && P.ordered_by() == GPMSIP::BY_COL ) ) )
198 y->assume_sorted(
true);
203 DVectorSlice* y, value_type a,
const GenPermMatrixSlice& P
207 using DenseLinAlgPack::Vp_MtV_assert_sizes;
208 Vp_MtV_assert_sizes( y->dim(), P.rows(), P.cols(), P_trans, x.dim() );
215 if( P.is_identity() ) {
223 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
231 for( GenPermMatrixSlice::const_iterator itr = P.begin(); itr != P.end(); ++itr ) {
241 DVectorSlice* y, value_type a,
const GenPermMatrixSlice& P
248 namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
250 using DenseLinAlgPack::Vp_MtV_assert_sizes;
252 Vp_MtV_assert_sizes( y->dim(), P.rows(), P.cols(), P_trans, x.dim() );
259 if( P.is_identity() ) {
263 else if( x.is_sorted() ) {
264 const SpVectorSlice::difference_type x_off = x.offset();
265 if( P_trans ==
no_trans && P.ordered_by() == GPMSIP::BY_COL ) {
268 else if( ( P_trans ==
trans && P.ordered_by() == GPMSIP::BY_ROW )
269 || P.ordered_by() == GPMSIP::BY_ROW_AND_COL )
271 GenPermMatrixSlice::const_iterator
274 SpVectorSlice::const_iterator
277 while( P_itr != P_end && x_itr != x_end ) {
279 i =
rows(P_itr->row_i(),P_itr->col_j(),P_trans),
280 j =
cols(P_itr->row_i(),P_itr->col_j(),P_trans);
281 if( j < x_itr->index() + x_off ) {
285 else if( j > x_itr->index() + x_off ) {
290 (*y)(i) += a * x_itr->value();
309 AbstractLinAlgPack::GenPermMatrixSliceIteratorPack::EOrderedBy
311 AbstractLinAlgPack::GenPermMatrixSliceIteratorPack::EOrderedBy P_ordered_by
316 namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
319 switch( P_ordered_by ) {
320 case GPMSIP::BY_ROW_AND_COL:
321 opP_ordered_by = GPMSIP::BY_ROW_AND_COL;
324 opP_ordered_by = P_trans ==
no_trans ? GPMSIP::BY_ROW : GPMSIP::BY_COL;
327 opP_ordered_by = P_trans ==
no_trans ? GPMSIP::BY_COL : GPMSIP::BY_COL;
329 case GPMSIP::UNORDERED:
330 opP_ordered_by = GPMSIP::UNORDERED;
335 return opP_ordered_by;
340 void AbstractLinAlgPack::intersection(
341 const GenPermMatrixSlice &P1
343 ,
const GenPermMatrixSlice &P2
349 ,GenPermMatrixSlice *Q
357 namespace GPMSIP = AbstractLinAlgPack::GenPermMatrixSliceIteratorPack;
364 DenseLinAlgPack::MtM_assert_sizes(
365 P1.rows(), P1.cols() , P1_trans, P2.rows(), P2.cols() , P2_trans );
368 opP1_rows =
rows(P1.rows(),P1.cols(),P1_trans),
369 opP1_cols =
cols(P1.rows(),P1.cols(),P1_trans),
370 opP2_rows =
rows(P2.rows(),P2.cols(),P2_trans),
371 opP2_cols =
cols(P2.rows(),P2.cols(),P2_trans);
373 opP1_ordered_by = ordered_by(P1.ordered_by(),P1_trans),
374 opP2_ordered_by = ordered_by(P2.ordered_by(),P2_trans);
378 if( !P1.nz() || !P2.nz() ) {
381 Q->initialize(opP1_rows,opP2_cols,GenPermMatrixSlice::ZERO_MATRIX);
385 if( P1.is_identity() && P2.is_identity() ) {
389 Q->initialize(opP1_rows,opP2_cols,GenPermMatrixSlice::IDENTITY_MATRIX);
393 if( P1.is_identity() || P2.is_identity() ) {
400 if( ( opP1_ordered_by == GPMSIP::BY_COL || opP1_ordered_by == GPMSIP::BY_ROW_AND_COL )
401 && ( opP2_ordered_by == GPMSIP::BY_ROW || opP2_ordered_by == GPMSIP::BY_ROW_AND_COL ) )
408 GenPermMatrixSlice::const_iterator
413 while( P1_itr != P1_end && P2_itr != P2_end ) {
415 opP1_col_j =
cols(P1_itr->row_i(),P1_itr->col_j(),P1_trans),
416 opP2_row_i =
rows(P2_itr->row_i(),P2_itr->col_j(),P2_trans);
417 if( opP1_col_j < opP2_row_i ) {
421 if( opP1_col_j > opP2_row_i ) {
439 const GenPermMatrixSlice
440 &oP1 = opP1_cols > opP2_rows ? P1 : P2,
441 &oP2 = opP1_cols > opP2_rows ? P2 : P1;
443 oP1_trans = opP1_cols > opP2_rows ? P1_trans :
trans_not(P1_trans),
444 oP2_trans = opP1_cols > opP2_rows ? P2_trans :
trans_not(P2_trans);
446 typedef std::vector<size_type> oP2_col_j_lookup_t;
447 oP2_col_j_lookup_t oP2_col_j_lookup(
rows(oP2.rows(),oP2.rows(),oP2_trans));
448 std::fill( oP2_col_j_lookup.begin(), oP2_col_j_lookup.end(), 0 );
450 GenPermMatrixSlice::const_iterator
453 while( itr != itr_end ) {
454 oP2_col_j_lookup[
rows(itr->row_i(),itr->col_j(),oP2_trans)]
455 =
cols(itr->row_i(),itr->col_j(),oP2_trans);
463 GenPermMatrixSlice::const_iterator
466 while( itr != itr_end ) {
468 oP2_col_j = oP2_col_j_lookup[
cols(itr->row_i(),itr->col_j(),oP1_trans)];
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
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)
Transp trans_not(Transp _trans)
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)