58 return std::is_trivially_copyable_v<T> || Meta::is_fixed_data_real_eigen_matrix_v<T>;
75 template <
class T,
rowsize _row_size = 1,
rowsize _row_max = _row_size,
88 static_assert(
sizeof_T <= (1024ULL * 1024ULL * 1024ULL),
"Row size larger than 1G");
89 static_assert(array_comp_acceptable<T>(),
"Do not put in a non trivially copyable type ");
94 static_assert(
al ==
NoAlign ||
al >= 1,
"Align bad");
112 else if constexpr (
rm >= 0)
134 Layout =
"TABLE_StaticFixed";
136 Layout =
"TABLE_Fixed";
138 Layout =
"TABLE_StaticMax";
140 Layout =
"TABLE_Max";
141 return Layout +
"__" +
158 Layout =
"TABLE_StaticFixed";
160 Layout =
"TABLE_Fixed";
162 Layout =
"TABLE_StaticMax";
164 Layout =
"TABLE_Max";
165 return Layout +
"__" + std::to_string(
sizeof_T) +
166 "_" + std::to_string(_row_size) +
167 "_" + std::to_string(_row_max) +
168 "_" + std::to_string(_align);
181 Layout =
"TABLE_StaticFixed";
183 Layout =
"TABLE_Fixed";
185 Layout =
"TABLE_StaticMax";
187 Layout =
"TABLE_Max";
188 return Layout +
"__" + std::to_string(
sizeof_T) +
192 "_" + std::to_string(_align);
202 auto sz = strings.size();
203 return std::make_tuple(std::stoi(strings[sz - 4]), std::stoi(strings[sz - 3]), std::stoi(strings[sz - 2]), std::stoi(strings[sz - 1]));
214 if (
rs >= 0 && _row_size >= 0 &&
rs != _row_size)
216 if (
rm >= 0 && _row_max >= 0 &&
rm != _row_max)
234 template <
class T,
rowsize _row_size = 1,
rowsize _row_max = _row_size,
272 std::conditional_t<_dataLayout == TABLE_Max || _dataLayout == TABLE_Fixed, rowsize, EmptyNoDefault>
276 std::conditional_t<_dataLayout == CSR, t_dataUncompressed *, EmptyNoDefault>
_p_dataUncompressed =
nullptr;
283 const
index *n_rowstart,
index n_rowstart_size,
355 "iRow invalid: %lld / %lld", iRow,
_size);
362 "iRow invalid: %lld / %lld", iRow,
_size);
365 return static_cast<rowsize>(pDiff);
382 auto rs_cur = (*_p_dataUncompressed).at(iRow).size();
383 return static_cast<rowsize>(rs_cur);
430 "query position i[%lld] out of range [0, %lld)",
433 "query position j[%lld] out of range [0, %lld)",
437 pos = iRow *
rs + iCol;
439 pos = iRow *
rm + iCol;
447 "iRow invalid, %lld / %lld", iRow,
_size);
453 "pos in data not valid, %lld / %lld", pos,
_data_size);
468 return (*_p_dataUncompressed).at(iRow).at(iCol);
477 return const_cast<T &
>(
at(iRow, iCol));
483 return at(iRow, iCol);
502 "iRow invalid, %lld / %lld", iRow,
_size);
528 static_assert(((T *)(NULL) - (T *)(NULL)) == 0);
534 return (*_p_dataUncompressed).at(iRow).data();
544 return static_cast<const T *
>(
const_cast<self_type *
>(
this)->
operator[](iRow));
559 if (this->
Size() == 0)
561 if constexpr (_dataLayout ==
CSR)
604 operator std::vector<T>() const
606 return {ptr, ptr + row_size};
612 std::copy(
r.begin(),
r.end(), ptr);
618 std::copy(
r.cbegin(),
r.cend(), ptr);
637 template <
class Derived>
652 auto dthis =
static_cast<const Derived *
>(
this);
653 return dthis->getView();
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
#define DNDS_DEVICE_CALLABLE
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE_NO_EMPTY_CTOR(T, T_Self)
Assertion / error-handling macros and supporting helper functions.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
#define DNDS_HD_assert(cond)
Host-only expansion of DNDS_HD_assert (equivalent to DNDS_assert).
#define DNDS_HD_assert_infof(cond, info,...)
Host-only expansion of DNDS_HD_assert_infof.
CRTP base for row-granularity iterators over an Array / ArrayView.
DNDS_DEVICE_CALLABLE auto operator[](difference_type n) const
DNDS_DEVICE_CALLABLE Derived operator+(difference_type n) const
std::random_access_iterator_tag iterator_category
std::ptrdiff_t difference_type
DNDS_DEVICE_CALLABLE auto operator[](difference_type n)
DNDS_DEVICE_CALLABLE difference_type operator-(const Derived &R) const
DNDS_DEVICE_CALLABLE auto getView() const
DNDS_DEVICE_CALLABLE bool operator!=(const Derived &R) const
DNDS_DEVICE_CALLABLE bool operator>=(const Derived &R) const
DNDS_DEVICE_CALLABLE bool operator>(const Derived &R) const
DNDS_DEVICE_CALLABLE bool operator<=(const Derived &R) const
DNDS_DEVICE_CALLABLE Derived & operator++()
DNDS_DEVICE_CALLABLE bool operator==(const Derived &R) const
DNDS_DEVICE_CALLABLE Derived operator-(difference_type n) const
DNDS_DEVICE_CALLABLE Derived operator--(int)
DNDS_DEVICE_CALLABLE index RowSize() const
DNDS_DEVICE_CALLABLE bool operator<(const Derived &R) const
DNDS_DEVICE_CALLABLE Derived & operator-=(difference_type n)
DNDS_DEVICE_CALLABLE Derived & operator+=(difference_type n)
DNDS_DEVICE_CALLABLE Derived operator++(int)
DNDS_DEVICE_CALLABLE Derived & operator--()
Compile-time layout descriptor deducing the concrete DataLayout from element type and row-size templa...
static bool ArraySignatureIsCompatible(const std::string &v)
Whether a stored signature can be read into this array type.
static std::tuple< int, int, int, int > ParseArraySignatureTuple(const std::string &v)
Parse a signature string into (sizeof_T, row_size, row_max, align).
static std::string GetArraySignatureRelaxed()
Signature with _row_size / _row_max replaced by DynamicSize.
static const DataLayout _dataLayout
static constexpr DataLayout _GetDataLayout()
Deduce the DataLayout tag from the template parameters.
static const size_t sizeof_T
static std::string GetArrayName()
Human-readable type identifier including element typeid, sizes, and alignment.
static std::string GetArraySignature()
Compiler-independent identifier used by serializers to tag an array.
Non-owning view of a single row: {pointer, size}.
DNDS_DEVICE_CALLABLE T * cend() const
DNDS_DEVICE_CALLABLE T * begin()
DNDS_DEVICE_CALLABLE rowsize size() const
DNDS_DEVICE_CALLABLE RowView(T *n_ptr, rowsize siz)
DNDS_DEVICE_CALLABLE T * end()
DNDS_DEVICE_CALLABLE void assign_value(const RowView &r)
DNDS_DEVICE_CALLABLE RowView(const RowView &)=default
DNDS_DEVICE_CALLABLE T & operator[](rowsize j)
DNDS_DEVICE_CALLABLE ~RowView()=default
DNDS_DEVICE_CALLABLE RowView()=default
DNDS_DEVICE_CALLABLE T * cbegin() const
DNDS_DEVICE_CALLABLE T operator[](rowsize j) const
void operator=(const std::vector< index > &r)
Non-owning, device-callable view onto an Array.
const T & at(index iRow, rowsize iCol) const
Bounds-checked element read (not device-callable because CSR decompressed uses std::vector::at which ...
T * operator[](index iRow)
Raw row pointer. iRow == Size() is allowed for past-the-end queries (useful for computing buffer end ...
DNDS_DEVICE_CALLABLE T * get_rowstart_pointer_compressed(index iRow)
DNDS_DEVICE_CALLABLE bool operator==(const self_type &R) const
Pointer equality (two views referring to the same buffer).
std::conditional_t< _dataLayout==CSR, t_dataUncompressed *, EmptyNoDefault > _p_dataUncompressed
const T * operator[](index iRow) const
Const row pointer; see the non-const overload.
std::vector< std::vector< T > > t_dataUncompressed
DNDS_DEVICE_CALLABLE index Size() const
Number of rows in the viewed array.
const T & operator()(index iRow, rowsize iCol=0) const
2D indexed access (read-only).
DNDS_DEVICE_CALLABLE bool isCompressed() const
Whether the underlying array is in the compressed (flat) form (always true for non-CSR).
DNDS_DEVICE_CALLABLE T * data()
Raw pointer to the start of the flat data buffer.
DNDS_DEVICE_CALLABLE rowsize RowSize() const
Uniform row width for fixed layouts (asserts otherwise).
std::conditional_t< _dataLayout==TABLE_Max||_dataLayout==TABLE_Fixed, rowsize, EmptyNoDefault > _row_size_dynamic
DNDS_DEVICE_CALLABLE rowsize RowSize_Compressed(index iRow) const
std::conditional_t< _dataLayout==CSR, const index *, std::conditional_t< _dataLayout==TABLE_Max||_dataLayout==TABLE_StaticMax, const rowsize *, EmptyNoDefault > > _rowstart_or_rowsize
DNDS_DEVICE_CALLABLE rowsize RowSizeField(index iRow) const
Per-row "field" size for CSR (= actual row width).
DNDS_DEVICE_CALLABLE rowsize RowSize(index iRow) const
Per-row width. Handles CSR compressed and decompressed modes.
T & operator()(index iRow, rowsize iCol=0)
2D indexed access (writable). See at.
DNDS_DEVICE_CALLABLE rowsize RowSizeMax() const
Maximum row width (TABLE_*Max only).
DNDS_DEVICE_CALLABLE const T & at_compressed(index iRow, rowsize iCol) const
DNDS_DEVICE_CALLABLE rowsize RowSizeField() const
"Logical" row-field width used by derived Eigen arrays; see Array::RowSizeField.
DNDS_DEVICE_CALLABLE size_t DataSize() const
Size of the flat data buffer in T elements.
the host side operators are provided as implemented
constexpr bool isTABLE_Fixed(DataLayout lo)
Whether the layout has a uniform row width (no per-row size needed).
DNDS_CONSTANT const index UnInitIndex
Sentinel "not initialised" index value (= INT64_MIN).
DNDS_CONSTANT const rowsize NoAlign
Alignment flag: no padding applied to rows (the only currently-supported value).
constexpr bool isTABLE_Dynamic(DataLayout lo)
Whether the layout carries a runtime row-size parameter.
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
constexpr bool isTABLE(DataLayout lo)
Whether the layout uses a TABLE (padded) representation (vs CSR).
DNDS_CONSTANT const rowsize DynamicSize
Template parameter flag: "row width is set at runtime but uniform".
DataLayout
Enumeration of the five concrete data layouts supported by Array.
@ ErrorLayout
Invalid combination of template parameters.
@ TABLE_StaticFixed
Fixed row width, known at compile time.
@ TABLE_Max
Padded variable rows; max width set at runtime.
@ CSR
Compressed Sparse Row (flat buffer + row-start index).
@ TABLE_StaticMax
Padded variable rows; max width fixed at compile time.
@ TABLE_Fixed
Fixed row width, set at runtime (uniform across rows).
DNDS_CONSTANT const rowsize NonUniformSize
Template parameter flag: "each row has an independent width".
std::string RowSize_To_PySnippet(rowsize rs)
Encode a rowsize constant as a short Python-binding snippet: "<number>" for fixed,...
constexpr bool isTABLE_Max(DataLayout lo)
Whether the layout is a padded-max variant (uses _pRowSizes).
constexpr bool array_comp_acceptable()
Whether T is legal as an Array element type (trivially copyable or a fixed-size real Eigen matrix)....
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
std::vector< std::string > splitSStringClean(const std::string &str, char delim)
std::string Align_To_PySnippet(rowsize al)
Encode an alignment value as a Python-binding snippet: "N" for NoAlign, the number otherwise.
DNDS_CONSTANT const rowsize UnInitRowsize
Sentinel "not initialised" rowsize value (= INT32_MIN).
constexpr bool isTABLE_Static(DataLayout lo)
Whether the layout has a compile-time row-size constant.
Empty placeholder type without a default constructor; accepts any assignment.
Eigen::Matrix< real, 5, 1 > v
Eigen::Vector3d n(1.0, 0.0, 0.0)