12 #ifndef RTOPPACK_SPARSE_SUB_VECTOR_T_HPP
13 #define RTOPPACK_SPARSE_SUB_VECTOR_T_HPP
16 #include "RTOpPack_Types.hpp"
17 #include "Teuchos_Assert.hpp"
102 template<
class Scalar>
107 :globalOffset_(0), subDim_(0), subNz_(0),
108 valuesStride_(0), indicesStride_(0), localOffset_(0),
113 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in,
114 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in,
115 const ArrayRCP<const Teuchos_Ordinal> &indices_in, ptrdiff_t indicesStride_in,
116 ptrdiff_t localOffset_in,
bool isSorted_in
118 :globalOffset_(globalOffset_in), subDim_(subDim_in), subNz_(subNz_in),
119 values_(values_in), valuesStride_(valuesStride_in), indices_(indices_in),
120 indicesStride_(indicesStride_in), localOffset_(localOffset_in), isSorted_(isSorted_in)
124 initialize(globalOffset_in, subDim_in, subNz_in, values_in, valuesStride_in,
125 indices_in, indicesStride_in, localOffset_in, isSorted_in);
130 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in,
131 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in
133 :globalOffset_(globalOffset_in), subDim_(subDim_in), subNz_(subDim_in),
134 values_(values_in), valuesStride_(valuesStride_in),
135 indicesStride_(0), localOffset_(0), isSorted_(true)
139 initialize(globalOffset_in, subDim_in, values_in, valuesStride_in);
145 values_(sv.
values()), valuesStride_(sv.stride()), indicesStride_(0),
146 localOffset_(0), isSorted_(true)
150 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in,
151 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in,
152 const ArrayRCP<const Teuchos_Ordinal> &indices_in, ptrdiff_t indicesStride_in,
153 ptrdiff_t localOffset_in,
bool isSorted_in
164 subNz_in*as<Teuchos_Ordinal>(std::abs(as<int>(valuesStride_in))));
168 subNz_in*as<Teuchos_Ordinal>(std::abs(as<int>(indicesStride_in))));
171 for (
int k = 0; k < subNz_in-1; ++k) {
172 const Teuchos_Ordinal idx_k = indices_in[k*indicesStride_in];
173 const Teuchos_Ordinal idx_kp1 = indices_in[(k+1)*indicesStride_in];
175 "Error indices["<<k<<
"]="<<idx_k<<
" >= indices["<<k+1<<
"]="<<idx_kp1
181 globalOffset_ = globalOffset_in;
185 valuesStride_ = valuesStride_in;
186 indices_ = indices_in;
187 indicesStride_ = indicesStride_in;
188 localOffset_ = localOffset_in;
189 isSorted_ = isSorted_in;
193 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in,
194 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in
197 initialize(globalOffset_in, subDim_in, subDim_in, values_in, valuesStride_in,
198 Teuchos::null, 0, 0,
true);
203 globalOffset_ = 0; subDim_ = 0; subNz_ = 0;
204 values_ = Teuchos::null; valuesStride_ = 0; indices_ = Teuchos::null;
205 indicesStride_ = 0; localOffset_ = 0; isSorted_ =
false;
208 void setGlobalOffset(Teuchos_Ordinal globalOffset_in) { globalOffset_ = globalOffset_in; }
212 Teuchos_Ordinal
subDim()
const {
return subDim_; }
215 Teuchos_Ordinal
subNz()
const {
return subNz_; }
218 const ArrayRCP<const Scalar>
values()
const {
return values_; }
225 const ArrayRCP<const Teuchos_Ordinal>
indices()
const {
return indices_; }
235 Teuchos_Ordinal globalOffset_;
236 Teuchos_Ordinal subDim_;
237 Teuchos_Ordinal subNz_;
238 ArrayRCP<const Scalar> values_;
239 ptrdiff_t valuesStride_;
240 ArrayRCP<const Teuchos_Ordinal> indices_;
241 ptrdiff_t indicesStride_;
242 ptrdiff_t localOffset_;
251 #endif // RTOPPACK_SPARSE_SUB_VECTOR_T_HPP
bool is_null(const boost::shared_ptr< T > &p)
void initialize(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in)
SparseSubVectorT(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in, const ArrayRCP< const Teuchos_Ordinal > &indices_in, ptrdiff_t indicesStride_in, ptrdiff_t localOffset_in, bool isSorted_in)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Class for a (sparse or dense) sub-vector.
SparseSubVectorT(const ConstSubVectorView< Scalar > &sv)
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
bool isSorted() const
If isSorted == false then the vector is not sorted, otherwise it is sorted (sparse vectors only)...
void initialize(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in, const ArrayRCP< const Teuchos_Ordinal > &indices_in, ptrdiff_t indicesStride_in, ptrdiff_t localOffset_in, bool isSorted_in)
ptrdiff_t localOffset() const
Offset of indices[] into local sub-vector (sparse vectors only).
Teuchos_Ordinal subNz() const
Number of nonzero elements (subNz == subDim for dense vectors).
const ArrayRCP< const Scalar > values() const
Array (size min{|valueStride*subNz|,1}) for the values in the vector.
Teuchos_Ordinal subDim() const
Dimension of the sub-vector.
void setGlobalOffset(Teuchos_Ordinal globalOffset_in)
SparseSubVectorT(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in)
ptrdiff_t indicesStride() const
Stride between indices in indices[] (sparse vectors only).
TypeTo as(const TypeFrom &t)
ptrdiff_t valuesStride() const
Stride between elements in values[].
Teuchos_Ordinal globalOffset() const
Offset for the sub-vector into the global vector.
const ArrayRCP< const Teuchos_Ordinal > indices() const
Array (size indicesStride*subNz) if not Teuchos::null) for the indices of the nonzero elements in the...
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)