21 template<
typename COL_TYPE,
typename INDEX_TYPE,
template<
typename >
class BUFFER_TYPE >
34 template<
typename >
class BUFFER_TYPE >
37 using ColTypeNC = std::remove_const_t< COL_TYPE >;
59 ColTypeNC
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, ColTypeNC
const nCols, INDEX_TYPE
const initialRowCapacity )
378 bool insertNonZero( INDEX_TYPE
const row, ColTypeNC
const col, T
const & entry )
393 ColTypeNC
const *
const cols,
394 T
const *
const entriesToInsert,
395 ColTypeNC
const ncols )
412 template<
typename POLICY >
415 { ParentClass::template setValues< POLICY >( value ); }
423 template<
typename AtomicPolicy >
426 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
427 T
const *
const LVARRAY_RESTRICT vals,
428 ColTypeNC
const nCols )
const 429 { ParentClass::template addToRow< AtomicPolicy >( row, cols, vals, nCols ); }
435 template<
typename AtomicPolicy >
438 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
439 T
const *
const LVARRAY_RESTRICT vals,
440 ColTypeNC
const nCols )
const 441 { ParentClass::template addToRowBinarySearch< AtomicPolicy >( row, cols, vals, nCols ); }
447 template<
typename AtomicPolicy >
450 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
451 T
const *
const LVARRAY_RESTRICT vals,
452 ColTypeNC
const nCols )
const 453 { ParentClass::template addToRowLinearSearch< AtomicPolicy >( row, cols, vals, nCols ); }
459 template<
typename AtomicPolicy >
462 ColTypeNC
const *
const LVARRAY_RESTRICT cols,
463 T
const *
const LVARRAY_RESTRICT vals,
464 ColTypeNC
const nCols )
const 465 { ParentClass::template addToRowBinarySearchUnsorted< AtomicPolicy >( row, cols, vals, nCols ); }
490 { ParentClass::template setName< decltype( *this ) >( name ); }
519 INDEX_TYPE
const row, T
const *
const entriesToInsert ):
537 COL_TYPE *
incrementSize( COL_TYPE *
const curPtr, INDEX_TYPE
const nToAdd )
556 void insert( INDEX_TYPE
const pos )
const 567 void set( INDEX_TYPE
const pos, INDEX_TYPE
const colPos )
const 582 void insert( INDEX_TYPE
const nLeftToInsert,
583 INDEX_TYPE
const colPos,
584 INDEX_TYPE
const pos,
585 INDEX_TYPE
const prevPos )
const #define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:79
This class implements a compressed row storage sparsity pattern.
Definition: CRSMatrix.hpp:22
INDEX_TYPE insertNonZeros(INDEX_TYPE const row, ColTypeNC const *const cols, T const *const entriesToInsert, ColTypeNC const ncols)
Insert a non-zero entries into the given row.
Definition: CRSMatrix.hpp:392
void assimilate(SparsityPattern< COL_TYPE, INDEX_TYPE, BUFFER_TYPE > &&src)
Steal the resources from a SparsityPattern.
Definition: CRSMatrix.hpp:133
This class provides a view into a compressed row storage sparsity pattern.
Definition: SparsityPatternView.hpp:61
INDEX_TYPE const m_rowCapacity
The non zero capacity of the row.
Definition: CRSMatrix.hpp:602
LVARRAY_HOST_DEVICE constexpr COL_TYPE const * getColumns() const
Definition: SparsityPatternView.hpp:296
LVARRAY_HOST_DEVICE constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &&=delete
Overload for rvalues that is deleted.
T const *const m_entriesToInsert
A pointer to the entries to insert.
Definition: CRSMatrix.hpp:608
LVARRAY_HOST_DEVICE bool removeNonZero(INDEX_TYPE const row, ColTypeNC const col) const
Remove a non-zero entry at the given position.
Definition: CRSMatrixView.hpp:329
LVARRAY_HOST_DEVICE T const * getEntries() const
Definition: CRSMatrixView.hpp:256
void insert(INDEX_TYPE const nLeftToInsert, INDEX_TYPE const colPos, INDEX_TYPE const pos, INDEX_TYPE const prevPos) const
Used with the sortedArrayManipulation::insertSorted routine this callback signals that the given colu...
Definition: CRSMatrix.hpp:582
#define LVARRAY_ERROR_IF(EXP, MSG)
Abort execution if EXP is true.
Definition: Macros.hpp:155
void setName(std::string const &name)
Set the name associated with this CRSMatrix which is used in the chai callback.
Definition: CRSMatrix.hpp:489
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const
Definition: CRSMatrixView.hpp:165
BUFFER_TYPE< INDEX_TYPE > m_offsets
Definition: ArrayOfArraysView.hpp:965
void move(MemorySpace const space, bool const touch=true) const
Move this matrix to the given memory space and touch the values, sizes and offsets.
Definition: CRSMatrixView.hpp:564
LVARRAY_HOST_DEVICE constexpr ArraySlice< T, 1, 0, INDEX_TYPE_NC > getSetValues(INDEX_TYPE const i) const
Definition: ArrayOfSetsView.hpp:346
void assimilate(SparsityPatternView &&src)
Steal the resources of src, clearing it in the process.
Definition: SparsityPatternView.hpp:422
CRSMatrix & m_crsM
The CRSMatrix the call back is associated with.
Definition: CRSMatrix.hpp:593
BUFFER_TYPE< T > m_values
Definition: ArrayOfArraysView.hpp:972
CRSMatrix(INDEX_TYPE const nrows=0, ColTypeNC const ncols=0, INDEX_TYPE const initialRowCapacity=0)
Constructor.
Definition: CRSMatrix.hpp:58
CRSMatrix & operator=(CRSMatrix &&src)
Default move assignment operator, performs a shallow copy.
Definition: CRSMatrix.hpp:119
BUFFER_TYPE< SIZE_TYPE > m_sizes
Holds the size of each array.
Definition: ArrayOfArraysView.hpp:968
COL_TYPE * incrementSize(COL_TYPE *const curPtr, INDEX_TYPE const nToAdd)
Callback signaling that the size of the row has increased.
Definition: CRSMatrix.hpp:537
void resize(INDEX_TYPE const nRows, ColTypeNC const nCols, INDEX_TYPE const initialRowCapacity)
Set the dimensions of the matrix.
Definition: CRSMatrix.hpp:351
void compress(BUFFERS &... buffers)
Compress the arrays so that the values of each array are contiguous with no extra capacity in between...
Definition: ArrayOfArraysView.hpp:669
Contains the implementation of LvArray::CRSMatrixView.
void resize(INDEX_TYPE const nrows, COL_TYPE const ncols, INDEX_TYPE_NC initialRowCapacity, BUFFERS &... buffers)
Resize the SparsityPattern to the given size.
Definition: SparsityPatternView.hpp:437
COL_TYPE_NC m_numCols
The number of columns in the matrix.
Definition: SparsityPatternView.hpp:452
LVARRAY_HOST_DEVICE constexpr std::enable_if< std::is_signed< INDEX_TYPE >::value, bool >::type isPositive(INDEX_TYPE const i)
Definition: arrayManipulation.hpp:82
INDEX_TYPE const m_rowNNZ
The number of non zeros in the row.
Definition: CRSMatrix.hpp:599
~CRSMatrix()
Destructor, frees the entries, values (columns), sizes and offsets Buffers.
Definition: CRSMatrix.hpp:85
void zero() const
Use memset to set all the values in the matrix to 0.
Definition: CRSMatrixView.hpp:392
void reserveNonZeros(INDEX_TYPE const nnz)
Reserve space to hold at least the given total number of non zero entries.
Definition: CRSMatrix.hpp:309
BUFFER_TYPE< T > m_entries
Holds the entries of the matrix, of length numNonZeros().
Definition: CRSMatrixView.hpp:596
CRSMatrixView & operator=(CRSMatrixView const &)=default
Default copy assignment operator.
LVARRAY_HOST_DEVICE constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &
Definition: CRSMatrixView.hpp:210
This class provides the callbacks for the ArrayManipulation sorted routines.
Definition: CRSMatrix.hpp:508
void resizeFromRowCapacities(INDEX_TYPE const nRows, ColTypeNC const nCols, INDEX_TYPE const *const rowCapacities)
Clears the matrix and creates a new matrix with the given number of rows and columns.
Definition: CRSMatrix.hpp:177
void dynamicallyGrowRow(INDEX_TYPE const row, INDEX_TYPE const newNNZ)
Increase the capacity of a row to accommodate at least the given number of non zero entries...
Definition: CRSMatrix.hpp:501
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE_NC const numRows() const
Definition: SparsityPatternView.hpp:197
LVARRAY_HOST_DEVICE INDEX_TYPE_NC numNonZeros() const
Definition: SparsityPatternView.hpp:211
void move(MemorySpace const space, bool const touch=true) const
Move this matrix to the given memory space and touch the values, sizes and offsets.
Definition: CRSMatrix.hpp:480
INDEX_TYPE IndexType
The integer type used for indexing.
Definition: ArrayOfArraysView.hpp:188
void insert(INDEX_TYPE const pos) const
Used with sortedArrayManipulation::insert routine this callback signals that the column was inserted ...
Definition: CRSMatrix.hpp:556
void setValues(T const &value) const
Set all the entries in the matrix to the given value.
Definition: CRSMatrix.hpp:414
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const
Definition: CRSMatrixView.hpp:195
LVARRAY_HOST_DEVICE bool empty() const
Definition: SparsityPatternView.hpp:250
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const &
Definition: CRSMatrix.hpp:224
camp::resources::Platform MemorySpace
an alias for camp::resources::Platform.
Definition: bufferManipulation.hpp:31
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE_NC const nonZeroCapacity() const
Definition: SparsityPatternView.hpp:234
Contains functions for manipulating a contiguous array of values.
constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const &
Definition: CRSMatrix.hpp:202
void addToRowBinarySearchUnsorted(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Definition: CRSMatrix.hpp:461
The top level namespace.
Definition: Array.hpp:24
LVARRAY_HOST_DEVICE void reserve(BUFFER &buf, std::ptrdiff_t const size, MemorySpace const space, std::ptrdiff_t const newCapacity)
Reserve space in the buffer for at least the given capacity.
Definition: bufferManipulation.hpp:230
void addToRow(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix. The columns must be sorted...
Definition: CRSMatrix.hpp:425
CRSMatrix & operator=(CRSMatrix const &src)
Copy assignment operator, performs a deep copy.
Definition: CRSMatrix.hpp:101
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE INDEX_TYPE_NC removeNonZeros(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, ColTypeNC const ncols) const
Remove non-zero entries from the given row.
Definition: CRSMatrixView.hpp:342
void compress()
Compress the CRSMatrix so that the non-zeros and values of each row are contiguous with no extra capa...
Definition: CRSMatrix.hpp:360
CallBacks(CRSMatrix &crsM, INDEX_TYPE const row, T const *const entriesToInsert)
Constructor.
Definition: CRSMatrix.hpp:518
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.
Definition: ArrayOfArraysView.hpp:830
COL_TYPE ColType
The integer type used to enumerate the columns.
Definition: SparsityPatternView.hpp:79
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE const * getOffsets() const
Definition: SparsityPatternView.hpp:289
INDEX_TYPE_NC m_numArrays
The number of arrays contained.
Definition: ArrayOfArraysView.hpp:961
bool insertNonZero(INDEX_TYPE const row, ColTypeNC const col, T const &entry)
Insert a non-zero entry at the given position.
Definition: CRSMatrix.hpp:378
void addToRowBinarySearch(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Definition: CRSMatrix.hpp:437
void free(BUFFERS &... buffers)
Destroy all the objects held by this array and free all associated memory.
Definition: ArrayOfArraysView.hpp:806
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
Definition: arrayManipulation.hpp:152
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:326
void setCapacityOfArray(INDEX_TYPE const i, INDEX_TYPE const newCapacity, BUFFERS &... buffers)
Set the capacity of the given array.
Definition: ArrayOfArraysView.hpp:877
CRSMatrix(CRSMatrix const &src)
Copy constructor, performs a deep copy.
Definition: CRSMatrix.hpp:72
LVARRAY_HOST_DEVICE ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
Definition: CRSMatrixView.hpp:244
std::pair< BUFFER_TYPE< U > &, BUFFER_TYPE< U > const & > PairOfBuffers
Alias for a std::pair of buffers.
Definition: ArrayOfArraysView.hpp:608
LVARRAY_HOST_DEVICE constexpr COL_TYPE const numColumns() const
Definition: SparsityPatternView.hpp:204
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.
Definition: CRSMatrix.hpp:318
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const &
Definition: CRSMatrix.hpp:246
LVARRAY_HOST_DEVICE LVARRAY_FORCE_INLINE constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
Definition: math.hpp:313
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const
Definition: CRSMatrixView.hpp:180
void addToRowLinearSearch(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, ColTypeNC const nCols) const
Add to the given entries, the entries must already exist in the matrix.
Definition: CRSMatrix.hpp:449
void setRowCapacity(INDEX_TYPE const row, INDEX_TYPE newCapacity)
Set the non zero capacity of the given row.
Definition: CRSMatrix.hpp:335
void reserveValues(INDEX_TYPE const newValueCapacity, BUFFERS &... buffers)
Reserve space for the given number of values.
Definition: ArrayOfArraysView.hpp:652
T * m_entries
A pointer to the entries of the row.
Definition: CRSMatrix.hpp:605
INDEX_TYPE const m_row
The row the call back is assocated with.
Definition: CRSMatrix.hpp:596
LVARRAY_HOST_DEVICE bool insertIntoSetImpl(INDEX_TYPE const i, COL_TYPE const &value, CALLBACKS &&cbacks) const
Helper function to insert a value into the given set.
Definition: ArrayOfSetsView.hpp:364
This class implements a compressed row storage matrix.
Definition: CRSMatrix.hpp:35
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:478
T EntryType
The type of the entries in the matrix.
Definition: CRSMatrixView.hpp:93
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600
This class provides a view into a compressed row storage matrix.
Definition: CRSMatrixView.hpp:75