21 template<
typename COL_TYPE,
typename INDEX_TYPE,
template<
typename >
class BUFFER_TYPE >
34 template<
typename >
class BUFFER_TYPE >
59 INDEX_TYPE
const ncols=0,
60 INDEX_TYPE
const initialRowCapacity=0 ):
63 resize( nrows, ncols, initialRowCapacity );
131 template<
typename POLICY >
136 if( !std::is_trivially_destructible< T >::value )
139 RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0,
numRows() ),
154 RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0,
numRows() ),
157 T *
const rowEntries = view.
getEntries( row );
158 for( INDEX_TYPE i = 0; i < view.
numNonZeros( row ); ++i )
160 new ( rowEntries + i ) T();
176 template<
typename POLICY >
181 "COL_TYPE must be able to hold the range of columns: [0, " << nCols - 1 <<
"]." );
184 ParentClass::template resizeFromCapacities< POLICY >( nRows, rowCapacities, this->
m_entries );
214 toView()
const && =
delete;
351 void resize( INDEX_TYPE
const nRows, INDEX_TYPE
const nCols, INDEX_TYPE
const initialRowCapacity )
378 bool insertNonZero( INDEX_TYPE
const row, COL_TYPE
const col, T
const & entry )
393 COL_TYPE
const *
const cols,
394 T
const *
const entriesToInsert,
395 INDEX_TYPE
const ncols )
412 template<
typename POLICY >
415 { ParentClass::template setValues< POLICY >( value ); }
421 template<
typename AtomicPolicy >
424 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
425 T
const *
const LVARRAY_RESTRICT vals,
426 INDEX_TYPE
const nCols )
const 427 { ParentClass::template addToRow< AtomicPolicy >( row, cols, vals, nCols ); }
433 template<
typename AtomicPolicy >
436 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
437 T
const *
const LVARRAY_RESTRICT vals,
438 INDEX_TYPE
const nCols )
const 439 { ParentClass::template addToRowBinarySearch< AtomicPolicy >( row, cols, vals, nCols ); }
445 template<
typename AtomicPolicy >
448 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
449 T
const *
const LVARRAY_RESTRICT vals,
450 INDEX_TYPE
const nCols )
const 451 { ParentClass::template addToRowLinearSearch< AtomicPolicy >( row, cols, vals, nCols ); }
457 template<
typename AtomicPolicy >
460 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
461 T
const *
const LVARRAY_RESTRICT vals,
462 INDEX_TYPE
const nCols )
const 463 { ParentClass::template addToRowBinarySearchUnsorted< AtomicPolicy >( row, cols, vals, nCols ); }
488 { ParentClass::template setName< decltype( *this ) >( name ); }
499 void dynamicallyGrowRow( INDEX_TYPE
const row, INDEX_TYPE
const newNNZ )
517 INDEX_TYPE
const row, T
const *
const entriesToInsert ):
523 m_entriesToInsert( entriesToInsert )
535 COL_TYPE * incrementSize( COL_TYPE *
const curPtr, INDEX_TYPE
const nToAdd )
538 if( m_rowNNZ + nToAdd > m_rowCapacity )
540 m_crsM.dynamicallyGrowRow( m_row, m_rowNNZ + nToAdd );
544 return m_crsM.getSetValues( m_row );
554 void insert( INDEX_TYPE
const pos )
const 565 void set( INDEX_TYPE
const pos, INDEX_TYPE
const colPos )
const 566 {
new (&
m_entries[pos]) T( m_entriesToInsert[colPos] ); }
580 void insert( INDEX_TYPE
const nLeftToInsert,
581 INDEX_TYPE
const colPos,
582 INDEX_TYPE
const pos,
583 INDEX_TYPE
const prevPos )
const 586 new (&
m_entries[pos + nLeftToInsert - 1]) T( m_entriesToInsert[colPos] );
594 INDEX_TYPE
const m_row;
597 INDEX_TYPE
const m_rowNNZ;
600 INDEX_TYPE
const m_rowCapacity;
606 T
const *
const m_entriesToInsert;
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
This class implements a compressed row storage sparsity pattern.
constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const
void assimilate(SparsityPattern< COL_TYPE, INDEX_TYPE, BUFFER_TYPE > &&src)
Steal the resources from a SparsityPattern.
This class provides a view into a compressed row storage sparsity pattern.
bool insertNonZero(INDEX_TYPE const row, COL_TYPE const col, T const &entry)
Insert a non-zero entry at the given position.
INDEX_TYPE_NC removeNonZeros(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, INDEX_TYPE const ncols) const
Remove non-zero entries from the given row.
INDEX_TYPE_NC numNonZeros() const
constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const &
constexpr INDEX_TYPE_NC numColumns() const
void resize(INDEX_TYPE const nRows, INDEX_TYPE const nCols, INDEX_TYPE const initialRowCapacity)
Set the dimensions of the matrix.
void reserve(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newCapacity)
Reserve space in the buffer for at least the given capacity.
bool insertIntoSetImpl(INDEX_TYPE const i, COL_TYPE const &value, CALLBACKS &&cbacks) const
Helper function to insert a value into the given set.
CRSMatrix(INDEX_TYPE const nrows=0, INDEX_TYPE const ncols=0, INDEX_TYPE const initialRowCapacity=0)
Constructor.
#define LVARRAY_ERROR_IF(EXP, MSG)
Abort execution if EXP is true.
void setName(std::string const &name)
Set the name associated with this CRSMatrix which is used in the chai callback.
constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const
constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const
BUFFER_TYPE< INDEX_TYPE > m_offsets
void move(MemorySpace const space, bool const touch=true) const
Move this SparsityPattern to the given memory space and touch the values, sizes and offsets...
void addToRowBinarySearch(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix.
void assimilate(SparsityPatternView &&src)
Steal the resources of src, clearing it in the process.
BUFFER_TYPE< T > m_values
INDEX_TYPE insertNonZeros(INDEX_TYPE const row, COL_TYPE const *const cols, T const *const entriesToInsert, INDEX_TYPE const ncols)
Insert a non-zero entries into the given row.
void addToRowBinarySearchUnsorted(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix.
CRSMatrix & operator=(CRSMatrix &&src)
Default move assignment operator, performs a shallow copy.
void shiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position up by the given amount. New uninitialized values take their place.
BUFFER_TYPE< SIZE_TYPE > m_sizes
Holds the size of each array.
constexpr INDEX_TYPE const * getOffsets() const
void compress(BUFFERS &... buffers)
Compress the arrays so that the values of each array are contiguous with no extra capacity in between...
Contains the implementation of LvArray::CRSMatrixView.
constexpr std::enable_if< std::is_signed< INDEX_TYPE >::value, bool >::type isPositive(INDEX_TYPE const i)
void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
constexpr INDEX_TYPE_NC numRows() const
~CRSMatrix()
Destructor, frees the entries, values (columns), sizes and offsets Buffers.
constexpr INDEX_TYPE_NC nonZeroCapacity() const
void reserveNonZeros(INDEX_TYPE const nnz)
Reserve space to hold at least the given total number of non zero entries.
BUFFER_TYPE< T > m_entries
Holds the entries of the matrix, of length numNonZeros().
void resize(INDEX_TYPE const nrows, INDEX_TYPE const ncols, INDEX_TYPE_NC initialRowCapacity, BUFFERS &... buffers)
Resize the SparsityPattern to the given size.
CRSMatrixView & operator=(CRSMatrixView const &)=default
Default copy assignment operator.
constexpr ArraySlice< COL_TYPE const, 1, 0, INDEX_TYPE_NC > getColumns(INDEX_TYPE const row) const
ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
void move(MemorySpace const space, bool const touch=true) const
Move this SparsityPattern to the given memory space and touch the values, sizes and offsets...
INDEX_TYPE IndexType
The integer type used for indexing.
void emplace(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ARGS &&... args)
Insert into the array constructing the new value in place.
void setValues(T const &value) const
Set all the entries in the matrix to the given value.
void addToRowLinearSearch(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Contains functions for manipulating a contiguous array of values.
constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const &
MemorySpace
An enum containing the available memory spaces.
CRSMatrix & operator=(CRSMatrix const &src)
Copy assignment operator, performs a deep copy.
INDEX_TYPE_NC m_numCols
The number of columns in the matrix.
void compress()
Compress the CRSMatrix so that the non-zeros and values of each row are contiguous with no extra capa...
void setEqualTo(INDEX_TYPE const srcNumArrays, INDEX_TYPE const srcMaxOffset, BUFFER_TYPE< INDEX_TYPE > const &srcOffsets, BUFFER_TYPE< INDEX_TYPE > const &srcSizes, BUFFER_TYPE< COL_TYPE > const &srcValues, PAIRS_OF_BUFFERS &&... pairs)
Set this ArrayOfArraysView equal to the provided arrays.
COL_TYPE ColType
The integer type used to enumerate the columns.
INDEX_TYPE_NC m_numArrays
The number of arrays contained.
void free(BUFFERS &... buffers)
Destroy all the objects held by this array and free all associated memory.
constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &
bool removeNonZero(INDEX_TYPE const row, COL_TYPE const col) const
Remove a non-zero entry at the given position.
void setCapacityOfArray(INDEX_TYPE const i, INDEX_TYPE const newCapacity, BUFFERS &... buffers)
Set the capacity of the given array.
CRSMatrix(CRSMatrix const &src)
Copy constructor, performs a deep copy.
void resizeFromRowCapacities(INDEX_TYPE const nRows, INDEX_TYPE const nCols, INDEX_TYPE const *const rowCapacities)
Clears the matrix and creates a new matrix with the given number of rows and columns.
std::string string
String type.
std::pair< BUFFER_TYPE< U > &, BUFFER_TYPE< U > const & > PairOfBuffers
Alias for a std::pair of buffers.
void reserveNonZeros(INDEX_TYPE const row, INDEX_TYPE const nnz)
Reserve space to hold at least the given number of non zero entries in the given row.
void addToRow(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix. The columns must be sorted...
constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const &
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
void setRowCapacity(INDEX_TYPE const row, INDEX_TYPE newCapacity)
Set the non zero capacity of the given row.
void reserveValues(INDEX_TYPE const newValueCapacity, BUFFERS &... buffers)
Reserve space for the given number of values.
void insert(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ITERATOR first, std::ptrdiff_t const n)
Insert the given values into the array at the given position.
constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &&=delete
Overload for rvalues that is deleted.
This class implements a compressed row storage matrix.
T EntryType
The type of the entries in the matrix.
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
This class provides a view into a compressed row storage matrix.