53 namespace AbstractLinAlgPack {
100 const char msg_err[] =
"MatrixSparseCOORSerial::set_buffer(...) : Error,!";
118 if( nz && check_input ) {
204 <<
"Sparse " << rows <<
" x " <<
cols <<
" matrix with "
205 <<
nz <<
" nonzero entries:\n";
208 *itr_val_end = itr_val +
nz_;
212 for(; itr_val != itr_val_end; ++itr_val, ++itr_ivect, ++itr_jvect)
213 out << *itr_val <<
":" << *itr_ivect <<
":" << *itr_jvect <<
" ";
216 if( rows *
cols <= 400 ) {
217 out <<
"Converted to dense =\n";
249 namespace rcp = MemMngPack;
251 const char msg_err_head[] =
"MatrixSparseCOORSerial::reinitialize(...) : Error";
274 max_nz <=
max_nz_, std::invalid_argument
275 ,msg_err_head <<
"Buffers set up by client in set_buffers() only allows storage for "
276 "max_nz_ = " <<
max_nz_ <<
" nonzero entries while client requests storage for "
277 "max_nz = " << max_nz <<
" nonzero entries!" );
290 rows_ == 0 ||
cols_ == 0, std::invalid_argument
291 ,
"MatrixSparseCOORSerial::reset_to_load_values(...) : Error, "
292 "this matrix is not initialized so it can't be rest to load "
293 "new values for nonzero entries." );
311 ,
"MatrixSparseCOORSerial::get_load_nonzeros_buffers(...) : Error, "
312 "You must call commit_load_nonzeros_buffers() between calls to this method!" );
314 max_nz_load <= 0 || max_nz_load >
max_nz_ -
nz_, std::invalid_argument
315 ,
"MatrixSparseCOORSerial::get_load_nonzeros_buffers(...) : Error, "
316 "The number of nonzeros to load max_nz_load = " << max_nz_load <<
" can not "
321 ,
"MatrixSparseCOORSerial::get_load_nonzeros_buffers(...) : Error, "
322 "reset_to_load_values() was called and therefore the structure of the matrix "
325 !
reload_val_only_ && (row_i == NULL || col_j == NULL), std::invalid_argument
326 ,
"MatrixSparseCOORSerial::get_load_nonzeros_buffers(...) : Error, "
327 "both *row_i and *col_j must be non-NULL since reinitialize() was called" );
347 ,
"MatrixSparseCOORSerial::commit_load_nonzeros_buffers(...) : Error, "
348 "You must call get_load_nonzeros_buffers() before calling this method!" );
351 ,
"MatrixSparseCOORSerial::commit_load_nonzeros_buffers(...) : Error, "
352 "You can not commit more nonzero entries than you requested buffer space for in "
353 "get_load_nonzeros_buffers(...)!" );
357 ,
"MatrixSparseCOORSerial::commit_load_nonzeros_buffers(...) : Error, "
358 "This is not the buffer I give you in get_load_nonzeros_buffers(...)!" );
361 ,
"MatrixSparseCOORSerial::commit_load_nonzeros_buffers(...) : Error, "
362 "reset_to_load_values() was called and therefore the structure of the matrix "
373 ,
"MatrixSparseCOORSerial::finish_construction() : Error, the number of nonzeros on"
375 " and does not agree with the number of nonzero values = " <<
nz_ <<
" loaded this time!" );
382 i < 1 ||
rows_ < i, std::logic_error
383 ,
"MatrixSparseCOORSerial::finish_construction(true) : Error, "
384 "row_i[" << k <<
"] = " << i <<
" is not in the range [1,rows] = [1,"<<
rows_<<
"]!" );
386 j < 1 ||
cols_ < j, std::logic_error
387 ,
"MatrixSparseCOORSerial::finish_construction(true) : Error, "
388 "col_j[" << k <<
"] = " << j <<
" is not in the range [1,cols] = [1,"<<
cols_<<
"]!" );
398 #define VALIDATE_ROW_COL_IN_RANGE() \
399 TEUCHOS_TEST_FOR_EXCEPTION( \
400 i < 1 || rows_ < i, std::invalid_argument \
401 ,err_msg_head<<", i = inv_row_perm[(row_i["<<k<<"]=="<<*row_i<<")-1] = "<<i<<" > rows = "<<rows_ ); \
402 TEUCHOS_TEST_FOR_EXCEPTION( \
403 j < 1 || cols_ < j, std::invalid_argument \
404 ,err_msg_head<<", j = inv_col_perm[(col_j["<<k<<"]=="<<*col_j<<")-1] = "<<j<<" > rows = "<<cols_ );
406 #define VALIDATE_ROW_COL_IN_RANGE()
420 const char err_msg_head[] =
"MatrixSparseCOORSerial::count_nonzeros(...): Error";
424 ,err_msg_head <<
", the client requests a count for unique "
425 "elements but this sparse matrix object is not allowed to assume this!" );
428 row_rng = RangePack::full_range(row_rng_in,1,
rows_),
429 col_rng = RangePack::full_range(col_rng_in,1,
rows_),
430 row_rng_full(1,
rows_),
431 col_rng_full(1,
cols_);
438 if( dl == -row_rng.
ubound() + col_rng.lbound() && du == +col_rng.ubound() - row_rng.
lbound() ) {
440 if( row_rng == row_rng_full && col_rng == col_rng_full ) {
446 if( inv_row_perm == NULL && inv_col_perm == NULL ) {
453 cnt_nz += row_rng.
in_range(i) && col_rng.in_range(j) ? 1 : 0;
456 else if ( inv_row_perm != NULL && inv_col_perm == NULL ) {
460 i = inv_row_perm[(*row_i)-1],
463 cnt_nz += row_rng.
in_range(i) && col_rng.in_range(j) ? 1 : 0;
466 else if ( inv_row_perm == NULL && inv_col_perm != NULL ) {
471 j = inv_col_perm[(*col_j)-1];
473 cnt_nz += row_rng.
in_range(i) && col_rng.in_range(j) ? 1 : 0;
480 i = inv_row_perm[(*row_i)-1],
481 j = inv_col_perm[(*col_j)-1];
483 cnt_nz += row_rng.
in_range(i) && col_rng.in_range(j) ? 1 : 0;
514 const char err_msg_head[] =
"MatrixSparseCOORSerial::count_nonzeros(...): Error";
518 ,err_msg_head <<
", the client requests extraction of unique "
519 "elements but this sparse matrix object can not guarantee this!" );
522 row_rng = RangePack::full_range(row_rng_in,1,
rows_),
523 col_rng = RangePack::full_range(col_rng_in,1,
rows_),
524 row_rng_full(1,
rows_),
525 col_rng_full(1,
cols_);
534 if( dl == -row_rng.
ubound() + col_rng.lbound() && du == +col_rng.ubound() - row_rng.
lbound() ) {
536 if( row_rng == row_rng_full && col_rng == col_rng_full ) {
538 if( inv_row_perm == NULL && inv_col_perm == NULL ) {
545 *Arow++ = *row_i + row_offset;
546 *Acol++ = *col_j + col_offset;
556 if( inv_row_perm == NULL && inv_col_perm == NULL ) {
563 if( row_rng.
in_range(i) && col_rng.in_range(j) ) {
568 *Arow++ = i + row_offset;
569 *Acol++ = j + col_offset;
574 else if( inv_row_perm != NULL && inv_col_perm == NULL ) {
578 i = inv_row_perm[(*row_i)-1],
581 if( row_rng.
in_range(i) && col_rng.in_range(j) ) {
586 *Arow++ = i + row_offset;
587 *Acol++ = j + col_offset;
592 else if( inv_row_perm == NULL && inv_col_perm != NULL ) {
597 j = inv_col_perm[(*col_j)-1];
599 if( row_rng.
in_range(i) && col_rng.in_range(j) ) {
604 *Arow++ = i + row_offset;
605 *Acol++ = j + col_offset;
614 i = inv_row_perm[(*row_i)-1],
615 j = inv_col_perm[(*col_j)-1];
617 if( row_rng.
in_range(i) && col_rng.in_range(j) ) {
622 *Arow++ = i + row_offset;
623 *Acol++ = j + col_offset;
void reset_to_load_values()
Reinitialize internal counter to load new nonzero values.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
void commit_load_nonzeros_buffers(size_type nz_commit, value_type **val, index_type **row_i, index_type **col_j)
RTOp_index_type index_type
void finish_construction(bool test_setup)
Coordinate matrix subclass.
Entries must have unique row and column indexes.
RTOp_value_type value_type
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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.
release_resource_ptr_t release_resource_
Subclass to delete dynamically allocated memory with delete[].
const release_resource_ptr_t & release_resource() const
std::ostream & output(std::ostream &out) const
virtual std::ostream & output(std::ostream &out) const
Virtual output function.
const VectorSpace & space_rows() const
VectorSpaceSerial space_rows_
void Vp_StMtV(VectorMutable *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta) const
Templated class that supports the COOMatrixTemplateInterface template interface.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
. One-based subregion index range class.
void set_buffers(size_type max_nz, value_type *val, index_type *row_i, index_type *col_j, const release_resource_ptr_t &release_resource, size_type rows=0, size_type cols=0, size_type nz=0, bool check_input=false)
Give memory to use to store nonzero elements.
RTOp_index_type size_type
Abstract interface for objects that represent a space for mutable coordinate vectors.
T_To & dyn_cast(T_From &from)
Extract a constant DenseLinAlgPack::DVectorSlice view of a Vector object.
void coor_extract_nonzeros(EElementUniqueness element_uniqueness, const index_type inv_row_perm[], const index_type inv_col_perm[], const Range1D &row_rng, const Range1D &col_rng, index_type dl, index_type du, value_type alpha, const index_type len_Aval, value_type Aval[], const index_type len_Aij, index_type Arow[], index_type Acol[], const index_type row_offset, const index_type col_offset) const
#define VALIDATE_ROW_COL_IN_RANGE()
const LAPACK_C_Decl::f_int & M
void get_load_nonzeros_buffers(size_type max_nz_load, value_type **val, index_type **row_i, index_type **col_j)
bool in_range(Index i) const
Return true if the index is in range.
~ReleaseValRowColArrays()
const f_int f_dbl_prec a[]
Base class for all matrices that support basic matrix operations.
void Vp_StCOOMtV(DVectorSlice *vs_lhs, value_type alpha, const T_COOM &coom_rhs1, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs += alpha * op(coom_rhs1) * vs_rhs2 (BLAS xGEMV) (time = O(coom_rhs.nz(), space = O(1)) ...
Index lbound() const
Return lower bound of the range.
Entries allowed with duplicate row and column indexes with the understanding that the values are summ...
void initialize(size_type dim)
Initialize given the dimension of the vector space.
bool resource_is_bound() const
Overridden from ReleaseResource.
void Vt_S(DVectorSlice *vs_lhs, value_type alpha)
vs_lhs *= alpha (BLAS xSCAL) (*** Note that alpha == 0.0 is handeled as vs_lhs = 0.0)
size_type reload_val_only_nz_last_
Abstract interface for mutable coordinate vectors {abstract}.
void make_storage_unique()
VectorSpaceSerial space_cols_
void Vp_MtV_assert_compatibility(VectorMutable *v_lhs, const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs += op(m_rhs1) * v_rhs2
Extract a non-const DenseLinAlgPack::DVectorSlice view of a VectorMutable object. ...
void set_uninitialized()
Release all owned memory and make uninitialized.
EAssumeElementUniqueness element_uniqueness_
MatrixSparseCOORSerial()
Let this allocate its own memory.
MatrixOp & operator=(const MatrixOp &M)
const VectorSpace & space_cols() const
void reinitialize(size_type rows, size_type cols, size_type max_nz, EAssumeElementUniqueness element_uniqueness)
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return columns of a possible transposed matrix.
static release_resource_ptr_t release_resource_null_
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
index_type count_nonzeros(EElementUniqueness element_uniqueness, const index_type inv_row_perm[], const index_type inv_col_perm[], const Range1D &row_rng, const Range1D &col_rng, index_type dl, index_type du) const