76 T my_min(
const T& v1,
const T& v2 ) {
return v1 < v2 ? v1 : v2; }
79 const char* ordered_by_str(
82 switch( ordered_by ) {
88 return "BY_ROW_AND_COL";
100 :
public std::binary_function<
101 AbstractLinAlgPack::GenPermMatrixSliceIteratorPack::row_col_value_type<T>
102 ,AbstractLinAlgPack::GenPermMatrixSliceIteratorPack::row_col_value_type<T>
117 :
public std::binary_function<
118 AbstractLinAlgPack::GenPermMatrixSliceIteratorPack::row_col_value_type<T>
119 ,AbstractLinAlgPack::GenPermMatrixSliceIteratorPack::row_col_value_type<T>
140 namespace AbstractLinAlgPack {
143 : rows_(0), cols_(0), nz_(0)
170 namespace GPMSIP = GenPermMatrixSliceIteratorPack;
173 std::ostringstream omsg;
174 omsg <<
"\nGenPermMatrixSlice::initialize(...) : Error: ";
178 const size_type *ordered_sequence = NULL;
182 row_i[k-1] >= row_i[k], std::invalid_argument
183 ,
"GenPermMatrixSlice::initialize(...) : Error: "
184 "row_i[" << k-1 <<
"] = " << row_i[k-1]
185 <<
" >= row_i[" << k <<
"] = " << row_i[k]
186 <<
"\nThis is not sorted by row!" );
192 col_j[k-1] >= col_j[k], std::invalid_argument
193 ,
"GenPermMatrixSlice::initialize(...) : Error: "
194 "col_j[" << k-1 <<
"] = " << col_j[k-1]
195 <<
" >= col_j[" << k <<
"] = " << col_j[k]
196 <<
"\nThis is not sorted by column!" );
207 row_i_ = nz ? row_i : NULL;
208 col_j_ = nz ? col_j : NULL;
223 namespace GPMSIP = GenPermMatrixSliceIteratorPack;
226 ,
"GenPermMatrixSlice::initialize_and_sort(...) : Error, "
227 "ordered_by == GPMSIP::BY_ROW_AND_COL, we can not sort by row and column!" );
229 std::ostringstream omsg;
230 omsg <<
"\nGenPermMatrixSlice::initialize_and_sort(...) : Error:\n";
236 typedef GPMSIP::row_col_iterator<size_type> row_col_itr_t;
238 row_col_itr = row_col_itr_t( row_off, col_off, row_i, col_j, nz );
240 std::stable_sort( row_col_itr, row_col_itr + nz
241 , imp_row_less<size_type>() );
244 std::stable_sort( row_col_itr, row_col_itr + nz
245 , imp_col_less<size_type>() );
248 initialize(rows,cols,nz,row_off,col_off,ordered_by,row_i,col_j,test_setup);
260 namespace QPMSIP = GenPermMatrixSliceIteratorPack;
261 if( col_j < 1 ||
cols_ < col_j )
263 "GenPermMatrixSlice::lookup_row_i(col_j) : Error, "
264 "col_j is out of bounds" );
268 return col_j <=
nz_ ? col_j : 0;
280 namespace QPMSIP = GenPermMatrixSliceIteratorPack;
281 if( row_i < 1 ||
rows_ < row_i )
283 "GenPermMatrixSlice::lookup_col_j(row_i) : Error, "
284 "row_i is out of bounds" );
288 return row_i <=
nz_ ? row_i : 0;
313 namespace GPMSIP = GenPermMatrixSliceIteratorPack;
320 ,
"GenPermMatrixSlice::initialize_and_sort(...) : Error, "
321 "ordered_by == GPMSIP::BY_ROW_AND_COL, we can not sort by row and column!" );
324 "GenPermMatrixSlice::create_submatrix(...) : Error, "
325 "The range argument can not be rng.full_range() == true" );
328 ,
"GenPermMatrixSlice::create_submatrix(...) : Error, "
329 "rng.ubound() can not be larger than this->rows()" );
332 ,
"GenPermMatrixSlice::create_submatrix(...) : Error, "
333 "rng.ubound() can not be larger than this->cols()" );
336 ,
"GenPermMatrixSlice::create_submatrix(...) : Error, "
337 "You can have ordered_by == GPMSIP::UNORDERED" );
349 switch( ordered_by ) {
353 TEUCHOS_TEST_FOR_EXCEPTION(
357 ,
"GenPermMatrixSlice::create_submatrix(...) : Error, "
358 <<
"nz = " <<
nz() <<
" > 1 and "
359 <<
"ordered_by = " << ordered_by_str(ordered_by)
360 <<
" != this->ordered_by() = "
385 *l = std::lower_bound( search_k, search_k +
nz()
386 , rng.
lbound() - search_k_off );
392 *
u = std::upper_bound( search_k, search_k +
nz()
393 , rng.
ubound() - search_k_off );
405 if( k_u - k_l > 0 && k_u !=
nz() + 1 ) {
439 ,std::ostringstream &omsg
442 namespace GPMSIP = GenPermMatrixSliceIteratorPack;
445 nz > rows * cols, std::invalid_argument
446 ,omsg.str() <<
"nz = " << nz <<
" can not be greater than rows * cols = "
447 << rows <<
" * " << cols <<
" = " << rows *
cols );
452 row_i[k] + row_off < 1 || rows < row_i[k] + row_off, std::invalid_argument
453 ,omsg.str() <<
"row_i[" << k <<
"] + row_off = " << row_i[k] <<
" + " << row_off
454 <<
" = " << (row_i[k] + row_off)
455 <<
" is out of range [1,rows] = [1," << rows <<
"]" );
457 col_j[k] + col_off < 1 || cols < col_j[k] + col_off, std::invalid_argument
458 ,omsg.str() <<
"col_j[" << k <<
"] + col_off = " << col_j[k] <<
" + " << col_off
459 <<
" = " << (col_j[k] + col_off)
460 <<
" is out of range [1,cols] = [1," << cols <<
"]" );
474 ,
"GenPermMatrixSlice::validate_not_identity() : "
475 "Error, this->is_identity() is true" );
GenPermMatrixSlice()
Construct to an uninitialzied, unsized matrix.
Teuchos::Ordinal size_type
Typedef for the size type of elements that are used by the library.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Index size() const
Return the size of the range (ubound() - lbound() + 1)
void initialize(index_type rows, index_type cols, EIdentityOrZero type)
Initialize an identity or zero permutation.
Index ubound() const
Return upper bound of the range.
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return rows of a possible transposed matrix.
const_iterator end() const
Return the end of this->const_iterator_begin().
Internal storage for the iterator of the row and column indices.
void bind(const GenPermMatrixSlice &gpms)
Bind the view of another GenPermMatrixSlice object.
void validate_not_identity() const
. One-based subregion index range class.
This is a full random access iterator for accessing row and colunmn indices.
RTOp_index_type size_type
static void validate_input_data(index_type rows, index_type cols, index_type nz, difference_type row_off, difference_type col_off, EOrderedBy ordered_by, const index_type row_i[], const index_type col_j[], std::ostringstream &omsg)
const GenPermMatrixSlice create_submatrix(const Range1D &rng, EOrderedBy ordered_by) const
Create a submatrix by row, by column.
const_iterator begin() const
Return a random access iterator for accessing which row and column that each nonzero 1...
bool full_range() const
Returns true if the range represents the entire region (constructed from Range1D()) ...
const index_type * row_i_
ptrdiff_t difference_type
Index lbound() const
Return lower bound of the range.
void swap(row_col_value_type< T > &v1, row_col_value_type< T > &v2)
Swap row_col_value_type<T> objects.
External storage of a row and column indice. This is required for creating a temporary in an assignme...
const index_type * col_j_
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return columns of a possible transposed matrix.
const f_int f_dbl_prec const f_int f_int const f_int f_int const f_dbl_prec & u
EOrderedBy ordered_by() const
index_type lookup_row_i(index_type col_j) const
Lookup the ith row index for the nonzero entry in the jth column if it exists.
void initialize_and_sort(index_type rows, index_type cols, index_type nz, difference_type row_off, difference_type col_off, EOrderedBy ordered_by, index_type row_i[], index_type col_j[], bool test_setup=false)
Initialize and sort.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
index_type lookup_col_j(index_type row_i) const
Lookup the jth column index for the nonzero entry in the ith row if it exists.
Concrete matrix type to represent general permutation (mapping) matrices.
GenPermMatrixSliceIteratorPack::row_col_iterator< const index_type > const_iterator