LvArray
CRSMatrixView.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 #include "SparsityPatternView.hpp"
16 #include "arrayManipulation.hpp"
17 #include "ArraySlice.hpp"
18 #include "umpireInterface.hpp"
19 #include "math.hpp"
20 
21 namespace LvArray
22 {
23 
24 namespace internal
25 {
26 
34 template< typename POLICY, typename T >
36 void atomicAdd( POLICY, T * const acc, T const & val )
37 { RAJA::atomicAdd< POLICY >( acc, val ); }
38 
48 template< typename T >
49 LVARRAY_HOST_DEVICE constexpr inline
50 void atomicAdd( RAJA::seq_atomic, T * acc, T const & val )
51 { *acc += val; }
52 
53 } // namespace internal
54 
70 template< typename T,
71  typename COL_TYPE,
72  typename INDEX_TYPE,
73  template< typename > class BUFFER_TYPE
74  >
75 class CRSMatrixView : protected SparsityPatternView< COL_TYPE, INDEX_TYPE, BUFFER_TYPE >
76 {
77  using ColTypeNC = std::remove_const_t< COL_TYPE >;
78 
81 
83  using typename ParentClass::INDEX_TYPE_NC;
84 
85  using typename ParentClass::SIZE_TYPE;
86 
87 public:
88  static_assert( !std::is_const< T >::value ||
89  (std::is_const< COL_TYPE >::value && std::is_const< INDEX_TYPE >::value),
90  "When T is const COL_TYPE and INDEX_TYPE must also be const." );
91 
93  using EntryType = T;
94  using typename ParentClass::ColType;
95  using typename ParentClass::IndexType;
96 
100 
107  CRSMatrixView() = default;
108 
113  CRSMatrixView( CRSMatrixView const & ) = default;
114 
119  CRSMatrixView( CRSMatrixView && ) = default;
120 
130  LVARRAY_HOST_DEVICE constexpr inline
131  CRSMatrixView( INDEX_TYPE const nRows,
132  ColTypeNC const nCols,
133  BUFFER_TYPE< INDEX_TYPE > const & offsets,
134  BUFFER_TYPE< SIZE_TYPE > const & nnz,
135  BUFFER_TYPE< COL_TYPE > const & columns,
136  BUFFER_TYPE< T > const & entries ):
137  ParentClass( nRows, nCols, offsets, nnz, columns ),
138  m_entries( entries )
139  {}
140 
145  inline
146  CRSMatrixView & operator=( CRSMatrixView const & ) = default;
147 
152  inline
153  CRSMatrixView & operator=( CRSMatrixView && ) = default;
154 
158 
163  LVARRAY_HOST_DEVICE constexpr inline
165  toView() const
166  {
168  numColumns(),
169  this->m_offsets,
170  this->m_sizes,
171  this->m_values,
172  this->m_entries );
173  }
174 
178  LVARRAY_HOST_DEVICE constexpr inline
181  {
183  numColumns(),
184  this->m_offsets,
185  this->m_sizes,
186  this->m_values,
187  this->m_entries );
188  }
189 
193  LVARRAY_HOST_DEVICE constexpr inline
195  toViewConst() const
196  {
198  numColumns(),
199  this->m_offsets,
200  this->m_sizes,
201  this->m_values,
202  this->m_entries );
203  }
204 
208  LVARRAY_HOST_DEVICE constexpr inline
211  {
213  numColumns(),
214  this->m_offsets,
215  this->m_sizes,
216  this->m_values );
217  }
218 
220 
224 
226  using ParentClass::numRows;
227  using ParentClass::numColumns;
228  using ParentClass::numNonZeros;
229  using ParentClass::nonZeroCapacity;
230  using ParentClass::empty;
231 
233 
237 
243  LVARRAY_HOST_DEVICE inline
244  ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries( INDEX_TYPE const row ) const
245  {
247  return ArraySlice< T, 1, 0, INDEX_TYPE_NC >( m_entries.data() + this->m_offsets[ row ],
248  &this->m_sizes[ row ],
249  nullptr );
250  }
251 
255  LVARRAY_HOST_DEVICE inline
256  T const * getEntries() const
257  {
258  return m_entries.data();
259  }
260 
261 
262  template< typename POLICY >
263  inline
264  bool NaNCheck( ) const
265  {
266  RAJA::ReduceMax< typename RAJAHelper< POLICY >::ReducePolicy, int > anyNaN( 0 );
268  RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, numRows() ),
269  [view, anyNaN] LVARRAY_HOST_DEVICE ( INDEX_TYPE const row )
270  {
271  forValuesInSlice( view[row], [&anyNaN] ( T const & value )
272  {
273  anyNaN.max( std::isnan( value ) ? 1 : 0 );
274  } );
275  } );
276  return anyNaN.get() == 1;
277  }
278 
279 
280  using ParentClass::getColumns;
281  using ParentClass::getOffsets;
282  using ParentClass::getSizes;
283 
285 
289 
300  LVARRAY_HOST_DEVICE inline
301  bool insertNonZero( INDEX_TYPE const row, ColTypeNC const col, T const & entry ) const
302  { return ParentClass::insertIntoSetImpl( row, col, CallBacks( *this, row, &entry ) ); }
303 
315  LVARRAY_HOST_DEVICE inline
316  INDEX_TYPE_NC insertNonZeros( INDEX_TYPE const row,
317  ColTypeNC const * const LVARRAY_RESTRICT cols,
318  T const * const LVARRAY_RESTRICT entriesToInsert,
319  ColTypeNC const ncols ) const
320  { return ParentClass::insertIntoSetImpl( row, cols, cols + ncols, CallBacks( *this, row, entriesToInsert ) ); }
321 
328  LVARRAY_HOST_DEVICE inline
329  bool removeNonZero( INDEX_TYPE const row, ColTypeNC const col ) const
330  { return ParentClass::removeFromSetImpl( row, col, CallBacks( *this, row, nullptr )); }
331 
341  LVARRAY_HOST_DEVICE inline
342  INDEX_TYPE_NC removeNonZeros( INDEX_TYPE const row,
343  ColTypeNC const * const LVARRAY_RESTRICT cols,
344  ColTypeNC const ncols ) const
345  {
346  T * const entries = getEntries( row );
347  INDEX_TYPE const rowNNZ = numNonZeros( row );
348  INDEX_TYPE const nRemoved = ParentClass::removeFromSetImpl( row, cols, cols + ncols, CallBacks( *this, row, nullptr ) );
349 
350  arrayManipulation::destroy( entries + rowNNZ - nRemoved, nRemoved );
351 
352  return nRemoved;
353  }
354 
356 
360 
367  template< typename POLICY >
368  inline void setValues( T const & value ) const
369  {
371  RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, numRows() ),
372  [view, value] LVARRAY_HOST_DEVICE ( INDEX_TYPE const row )
373  {
374  INDEX_TYPE const nnz = view.numNonZeros( row );
375  ArraySlice< T, 1, 0, INDEX_TYPE_NC > const entries = view.getEntries( row );
376 
377  for( INDEX_TYPE_NC i = 0; i < nnz; ++i )
378  { entries[ i ] = value; }
379  } );
380  }
381 
392  inline void zero() const
393  {
394  #if !defined( LVARRAY_USE_UMPIRE )
395  LVARRAY_ERROR_IF_NE_MSG( m_entries.getPreviousSpace(), MemorySpace::host, "Without Umpire only host memory is supported." );
396  #endif
397 
398  if( m_entries.capacity() > 0 )
399  {
400  ParentClass::move( m_entries.getPreviousSpace(), false );
401  m_entries.move( m_entries.getPreviousSpace(), true );
402 
403  size_t const numBytes = m_entries.capacity() * sizeof( T );
404 
405  umpireInterface::memset( m_entries.data(), 0, numBytes );
406 
407  }
408  }
409 
422  template< typename AtomicPolicy >
423  LVARRAY_HOST_DEVICE inline
424  void addToRow( INDEX_TYPE const row,
425  ColTypeNC const * const LVARRAY_RESTRICT cols,
426  T const * const LVARRAY_RESTRICT vals,
427  ColTypeNC const nCols ) const
428  {
429  INDEX_TYPE const nnz = numNonZeros( row );
430  if( nCols < nnz / 4 && nnz > 64 )
431  {
432  addToRowBinarySearch< AtomicPolicy >( row, cols, vals, nCols );
433  }
434  else
435  {
436  addToRowLinearSearch< AtomicPolicy >( row, cols, vals, nCols );
437  }
438  }
439 
452  template< typename AtomicPolicy >
453  LVARRAY_HOST_DEVICE inline
454  void addToRowBinarySearch( INDEX_TYPE const row,
455  ColTypeNC const * const LVARRAY_RESTRICT cols,
456  T const * const LVARRAY_RESTRICT vals,
457  ColTypeNC const nCols ) const
458  {
460 
461  INDEX_TYPE const nnz = numNonZeros( row );
462  COL_TYPE const * const columns = getColumns( row );
463  T * const entries = getEntries( row );
464 
465  INDEX_TYPE_NC curPos = 0;
466  for( INDEX_TYPE_NC i = 0; i < nCols; ++i )
467  {
468  INDEX_TYPE const pos = sortedArrayManipulation::find( columns + curPos, nnz - curPos, cols[ i ] ) + curPos;
469  LVARRAY_ASSERT_GT( nnz, pos );
470  LVARRAY_ASSERT_EQ( columns[ pos ], cols[ i ] );
471 
472  internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
473  curPos = pos + 1;
474  }
475  }
476 
489  template< typename AtomicPolicy >
490  LVARRAY_HOST_DEVICE inline
491  void addToRowLinearSearch( INDEX_TYPE const row,
492  ColTypeNC const * const LVARRAY_RESTRICT cols,
493  T const * const LVARRAY_RESTRICT vals,
494  ColTypeNC const nCols ) const
495  {
497 
498  INDEX_TYPE const nnz = numNonZeros( row );
499  COL_TYPE const * const columns = getColumns( row );
500  T * const entries = getEntries( row );
501 
502  INDEX_TYPE_NC curPos = 0;
503  for( INDEX_TYPE_NC i = 0; i < nCols; ++i )
504  {
505  for( INDEX_TYPE_NC j = curPos; j < nnz; ++j )
506  {
507  if( columns[ j ] == cols[ i ] )
508  {
509  curPos = j;
510  break;
511  }
512  }
513  LVARRAY_ASSERT_EQ( columns[ curPos ], cols[ i ] );
514  internal::atomicAdd( AtomicPolicy{}, entries + curPos, vals[ i ] );
515  ++curPos;
516  }
517  }
518 
530  template< typename AtomicPolicy >
531  LVARRAY_HOST_DEVICE inline
532  void addToRowBinarySearchUnsorted( INDEX_TYPE const row,
533  ColTypeNC const * const LVARRAY_RESTRICT cols,
534  T const * const LVARRAY_RESTRICT vals,
535  ColTypeNC const nCols ) const
536  {
537  INDEX_TYPE const nnz = numNonZeros( row );
538  COL_TYPE const * const columns = getColumns( row );
539  T * const entries = getEntries( row );
540 
541  for( INDEX_TYPE_NC i = 0; i < nCols; ++i )
542  {
543  INDEX_TYPE const pos = sortedArrayManipulation::find( columns, nnz, cols[ i ] );
544  LVARRAY_ASSERT_GT( nnz, pos );
545  LVARRAY_ASSERT_EQ( columns[ pos ], cols[ i ] );
546 
547  internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
548  }
549  }
550 
552 
556 
564  void move( MemorySpace const space, bool const touch=true ) const
565  {
566  ParentClass::move( space, touch );
567  m_entries.move( space, touch );
568  }
569 
571 
572 protected:
573 
578  CRSMatrixView( bool ):
579  ParentClass( true ),
580  m_entries( true )
581  {}
582 
588  template< typename U >
589  void setName( std::string const & name )
590  {
591  ParentClass::template setName< U >( name );
592  m_entries.template setName< U >( name + "/entries" );
593  }
594 
596  BUFFER_TYPE< T > m_entries;
597 
598 private:
599 
604  class CallBacks
605  {
606 public:
607 
614  LVARRAY_HOST_DEVICE inline
615  CallBacks( CRSMatrixView const & crsMV,
616  INDEX_TYPE const row, T const * const entriesToInsert ):
617  m_crsMV( crsMV ),
618  m_row( row ),
619  m_rowNNZ( crsMV.numNonZeros( row ) ),
620  m_rowCapacity( crsMV.nonZeroCapacity( row ) ),
621  m_entries( crsMV.getEntries( row ) ),
622  m_entriesToInsert( entriesToInsert )
623  {}
624 
633  LVARRAY_HOST_DEVICE inline
634  ColTypeNC * incrementSize( ColTypeNC * const curPtr, INDEX_TYPE const nToAdd ) const
635  {
636  LVARRAY_UNUSED_VARIABLE( curPtr );
637 #ifdef LVARRAY_BOUNDS_CHECK
638  LVARRAY_ERROR_IF_GT_MSG( m_rowNNZ + nToAdd, m_rowCapacity, "CRSMatrixView cannot do reallocation." );
639 #else
640  LVARRAY_DEBUG_VAR( nToAdd );
641 #endif
642  return m_crsMV.getSetValues( m_row );
643  }
644 
651  LVARRAY_HOST_DEVICE inline
652  void insert( INDEX_TYPE const insertPos ) const
653  { arrayManipulation::emplace( m_entries, m_rowNNZ, insertPos, m_entriesToInsert[0] ); }
654 
663  LVARRAY_HOST_DEVICE inline
664  void set( INDEX_TYPE const pos, ColTypeNC const colPos ) const
665  { new (&m_entries[ pos ]) T( m_entriesToInsert[ colPos ] ); }
666 
677  LVARRAY_HOST_DEVICE inline
678  void insert( INDEX_TYPE const nLeftToInsert,
679  ColTypeNC const colPos,
680  ColTypeNC const pos,
681  ColTypeNC const prevPos ) const
682  {
683  arrayManipulation::shiftUp( m_entries, prevPos, pos, nLeftToInsert );
684  new (&m_entries[pos + nLeftToInsert - 1]) T( m_entriesToInsert[colPos] );
685  }
686 
693  LVARRAY_HOST_DEVICE inline
694  void remove( ColTypeNC removePos ) const
695  { arrayManipulation::erase( m_entries, m_rowNNZ, removePos ); }
696 
707  LVARRAY_HOST_DEVICE inline
708  void remove( INDEX_TYPE const nRemoved,
709  ColTypeNC const curPos,
710  ColTypeNC const nextPos ) const
711  { arrayManipulation::shiftDown( m_entries, nextPos, curPos + 1, nRemoved ); }
712 
713 private:
716 
718  INDEX_TYPE const m_row;
719 
721  INDEX_TYPE const m_rowNNZ;
722 
724  INDEX_TYPE const m_rowCapacity;
725 
727  T * const m_entries;
728 
730  T const * const m_entriesToInsert;
731  };
732 
733 };
734 
735 } /* namespace LvArray */
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:79
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
Definition: Macros.hpp:223
LVARRAY_HOST_DEVICE constexpr CRSMatrixView(INDEX_TYPE const nRows, ColTypeNC const nCols, BUFFER_TYPE< INDEX_TYPE > const &offsets, BUFFER_TYPE< SIZE_TYPE > const &nnz, BUFFER_TYPE< COL_TYPE > const &columns, BUFFER_TYPE< T > const &entries)
Construct a new CRSMatrixView from the given buffers.
Definition: CRSMatrixView.hpp:131
This class provides a view into a compressed row storage sparsity pattern.
Definition: SparsityPatternView.hpp:61
CRSMatrixView const & m_crsMV
A reference to the associated CRSMatrixView.
Definition: CRSMatrixView.hpp:715
INDEX_TYPE IndexType
The integer type used for indexing.
Definition: ArrayOfArraysView.hpp:188
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE std::ptrdiff_t find(T const *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, T const &value, Compare &&comp=Compare())
Definition: sortedArrayManipulation.hpp:411
#define ARRAYOFARRAYS_CHECK_BOUNDS(i)
Check that i is a valid array index.
Definition: ArrayOfArraysView.hpp:106
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
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const
Definition: CRSMatrixView.hpp:165
LVARRAY_HOST_DEVICE 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: CRSMatrixView.hpp:491
CRSMatrixView(bool)
Protected constructor to be used by the CRSMatrix class.
Definition: CRSMatrixView.hpp:578
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 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: CRSMatrixView.hpp:454
LVARRAY_HOST_DEVICE CallBacks(CRSMatrixView const &crsMV, INDEX_TYPE const row, T const *const entriesToInsert)
Constructor.
Definition: CRSMatrixView.hpp:615
LVARRAY_HOST_DEVICE 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: CRSMatrixView.hpp:532
This class provides the callbacks for the sortedArrayManipulation routines.
Definition: CRSMatrixView.hpp:604
#define LVARRAY_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
Definition: Macros.hpp:554
#define LVARRAY_ERROR_IF_NE_MSG(lhs, rhs, msg)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:344
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void forValuesInSlice(T &value, LAMBDA &&f)
Apply the given function to the given value.
Definition: sliceHelpers.hpp:31
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void insert(INDEX_TYPE const nLeftToInsert, ColTypeNC const colPos, ColTypeNC const pos, ColTypeNC const prevPos) const
Used with the sortedArrayManipulation::insertSorted routine this callback signals that the given colu...
Definition: CRSMatrixView.hpp:678
void setValues(T const &value) const
Set all the entries in the matrix to the given value.
Definition: CRSMatrixView.hpp:368
Contains the LvArray umpire interface. This is only used to keep umpire/ResourceManager.hpp out of the includes for most headers.
LVARRAY_HOST_DEVICE bool insertNonZero(INDEX_TYPE const row, ColTypeNC const col, T const &entry) const
Insert a non-zero entry at the given position.
Definition: CRSMatrixView.hpp:301
std::conditional_t< CONST_SIZES, INDEX_TYPE const, INDEX_TYPE_NC > SIZE_TYPE
The type contained by the m_sizes buffer.
Definition: ArrayOfArraysView.hpp:177
T *const m_entries
A pointer to the entries in the row.
Definition: CRSMatrixView.hpp:727
void zero() const
Use memset to set all the values in the matrix to 0.
Definition: CRSMatrixView.hpp:392
LVARRAY_HOST_DEVICE ColTypeNC * incrementSize(ColTypeNC *const curPtr, INDEX_TYPE const nToAdd) const
Callback signaling that the size of the row has increased.
Definition: CRSMatrixView.hpp:634
LVARRAY_HOST_DEVICE void insert(INDEX_TYPE const insertPos) const
Used with sortedArrayManipulation::insert routine this callback signals that the column was inserted ...
Definition: CRSMatrixView.hpp:652
BUFFER_TYPE< T > m_entries
Holds the entries of the matrix, of length numNonZeros().
Definition: CRSMatrixView.hpp:596
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void erase(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n=1)
Shift the values in the array at or above the given position down by the given amount overwriting the...
Definition: arrayManipulation.hpp:396
Contains the implementation of LvArray::ArraySlice.
LVARRAY_HOST_DEVICE constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &
Definition: CRSMatrixView.hpp:210
Contains the implementation of LvArray:SparsityPatternView.
INDEX_TYPE const m_row
The associated row.
Definition: CRSMatrixView.hpp:718
LVARRAY_HOST_DEVICE INDEX_TYPE_NC numNonZeros() const
Definition: SparsityPatternView.hpp:211
LVARRAY_HOST_DEVICE void atomicAdd(POLICY, T *const acc, T const &val)
Wrapper around RAJA::atomicAdd.
Definition: CRSMatrixView.hpp:36
Contains some portable math functions.
void setName(std::string const &name)
Set the name to be displayed whenever the underlying Buffer&#39;s user call back is called.
Definition: CRSMatrixView.hpp:589
INDEX_TYPE const m_rowCapacity
The non zero capacity of the row.
Definition: CRSMatrixView.hpp:724
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const
Definition: CRSMatrixView.hpp:195
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool isSortedUnique(ITER first, ITER const last, Compare &&comp=Compare())
Definition: sortedArrayManipulation.hpp:374
camp::resources::Platform MemorySpace
an alias for camp::resources::Platform.
Definition: bufferManipulation.hpp:31
Contains functions for manipulating a contiguous array of values.
#define LVARRAY_DEBUG_VAR(X)
Mark X as an debug variable, used to silence compiler warnings.
Definition: Macros.hpp:85
LVARRAY_HOST_DEVICE INDEX_TYPE_NC insertNonZeros(INDEX_TYPE const row, ColTypeNC const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT entriesToInsert, ColTypeNC const ncols) const
Insert a non-zero entries into the given row.
Definition: CRSMatrixView.hpp:316
T const *const m_entriesToInsert
A pointer to the entries to insert.
Definition: CRSMatrixView.hpp:730
The top level namespace.
Definition: Array.hpp:24
#define LVARRAY_ERROR_IF_GT_MSG(lhs, rhs, msg)
Raise a hard error if one value compares greater than the other.
Definition: Macros.hpp:376
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
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void shiftDown(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 down by the given amount overwriting the...
Definition: arrayManipulation.hpp:363
COL_TYPE ColType
The integer type used to enumerate the columns.
Definition: SparsityPatternView.hpp:79
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
LVARRAY_HOST_DEVICE ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
Definition: CRSMatrixView.hpp:244
LVARRAY_HOST_DEVICE 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: CRSMatrixView.hpp:424
INDEX_TYPE const m_rowNNZ
The number of non zero entries in the row.
Definition: CRSMatrixView.hpp:721
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:614
#define LVARRAY_HOST_DEVICE_HIP
Mark a function for both host and device usage when using HIP only.
Definition: Macros.hpp:602
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const
Definition: CRSMatrixView.hpp:180
typename ParentClass::INDEX_TYPE_NC INDEX_TYPE_NC
Since INDEX_TYPE should always be const we need an alias for the non const version.
Definition: ArrayOfSetsView.hpp:47
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_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
Definition: Macros.hpp:524
#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