DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ArrayEigenUniMatrixBatch_DeviceView.hpp
Go to the documentation of this file.
1#pragma once
2/// @file ArrayEigenUniMatrixBatch_DeviceView.hpp
3/// @brief Device-callable view for @ref DNDS::ArrayEigenUniMatrixBatch "ArrayEigenUniMatrixBatch" (rows of
4/// identically-shaped matrix batches, variable batch count per row).
5
6#include "../DeviceView.hpp"
7
8namespace DNDS
9{
10 /**
11 * @brief `a * b` if both are compile-time sizes, @ref DynamicSize if either
12 * is `Eigen::Dynamic`, otherwise a sentinel.
13 * @details Helper used by @ref DNDS::ArrayEigenUniMatrixBatchDeviceView "ArrayEigenUniMatrixBatchDeviceView" to compute
14 * the underlying @ref DNDS::ParArray "ParArray" row width from the matrix shape.
15 */
16 template <int a, int b>
18 {
19 if constexpr (a >= 0 && b >= 0)
20 {
21 return a * b;
22 }
23 if constexpr (a == Eigen::Dynamic || b == Eigen::Dynamic)
24 {
25 return DynamicSize;
26 }
27 return DNDS_ROWSIZE_MIN;
28 }
29
30 /**
31 * @brief Device-callable view onto @ref DNDS::ArrayEigenUniMatrixBatch "ArrayEigenUniMatrixBatch" rows.
32 *
33 * @details `operator()(i, j)` returns an `Eigen::Map<Matrix<real, _n_row, _n_col>>`
34 * pointing at the `j`-th matrix of row `i`'s batch. `BatchSize(i)` reports
35 * the batch count (not the raw CSR width).
36 */
37 template <DeviceBackend B, class real_T, int _n_row, int _n_col>
38 class ArrayEigenUniMatrixBatchDeviceView : public ArrayDeviceView<B, real_T, NonUniformSize>
39 {
40 static_assert(_n_row >= 0 || _n_row == Eigen::Dynamic, "invalid _n_row");
41 static_assert(_n_col >= 0 || _n_col == Eigen::Dynamic, "invalid _n_col");
42
44 using t_base::t_base;
45
47
48 using t_EigenMatrix = Eigen::Matrix<std::remove_cv_t<real_T>, _n_row, _n_col,
49 Eigen::AutoAlign |
50 ((_n_row == 1 && _n_col != 1) ? Eigen ::RowMajor : (_n_col == 1 && _n_row != 1) ? Eigen ::ColMajor // ColMajor except for row-vector
51 : Eigen ::ColMajor)>;
52 using t_EigenMap_const = Eigen::Map<const t_EigenMatrix, Eigen::Unaligned>; // default no buffer align and stride
53 using t_EigenMap =
54 std::conditional_t<std::is_const_v<real_T>,
55 t_EigenMap_const,
56 Eigen::Map<t_EigenMatrix, Eigen::Unaligned>>; // default no buffer align and stride
57
58 private:
59 int _row_dynamic = _n_row > 0 ? _n_row : 0;
60 int _col_dynamic = _n_col > 0 ? _n_col : 0;
61 int _m_size = this->Rows() * this->Cols(); //! extra data!
62
63 public:
65
67
69 int n_row_dynamic, int n_col_dynamic, int n_m_size)
70 : t_base(base_view), _row_dynamic(n_row_dynamic), _col_dynamic(n_col_dynamic), _m_size(n_m_size) {}
71
72 DNDS_DEVICE_CALLABLE [[nodiscard]] int Rows() const { return _n_row > 0 ? _n_row : _row_dynamic; }
73 DNDS_DEVICE_CALLABLE [[nodiscard]] int Cols() const { return _n_col > 0 ? _n_col : _col_dynamic; }
74 DNDS_DEVICE_CALLABLE [[nodiscard]] int MSize() const
75 {
76 if constexpr (_n_row >= 0 && _n_col >= 0)
77 return _n_row * _n_col;
78 else
79 return _m_size;
80 }
81
83 {
84 return this->RowSize(i);
85 }
86
88 {
89 rowsize row_size_c = this->t_base::RowSize(i);
90 DNDS_assert(MSize() != 0 && row_size_c % MSize() == 0);
91 return row_size_c / MSize();
92 }
93
95 {
96 DNDS_assert(j >= 0 && j < this->RowSize(i));
97 // if constexpr (_n_row >= 0 && _n_col >= 0)
98 return {t_base::operator[](i) + MSize() * j, Rows(), Cols()};
99 }
100
101 DNDS_DEVICE_CALLABLE t_EigenMap_const operator()(index i, rowsize j) const
102 {
103 DNDS_assert(j >= 0 && j < this->RowSize(i));
104 // if constexpr (_n_row >= 0 && _n_col >= 0)
105 return {static_cast<const t_base &>(*this).operator[](i) + MSize() * j, Rows(), Cols()};
106 }
107 };
108}
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
Definition Defines.hpp:83
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_ROWSIZE_MIN
Definition Defines.hpp:119
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
Non-owning device-callable view of an Array, specialised per DeviceBackend.
Device-callable view onto ArrayEigenUniMatrixBatch rows.
DNDS_DEVICE_CALLABLE rowsize RowSize(index i) const
DNDS_DEVICE_CALLABLE t_EigenMap_const operator()(index i, rowsize j) const
DNDS_DEVICE_CALLABLE t_EigenMap operator()(index i, rowsize j)
DNDS_DEVICE_CALLABLE rowsize BatchSize(index i) const
T * operator[](index iRow)
Raw row pointer. iRow == Size() is allowed for past-the-end queries (useful for computing buffer end ...
DNDS_DEVICE_CALLABLE rowsize RowSize() const
Uniform row width for fixed layouts (asserts otherwise).
the host side operators are provided as implemented
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
Definition Defines.hpp:109
DNDS_CONSTANT const rowsize DynamicSize
Template parameter flag: "row width is set at runtime but uniform".
Definition Defines.hpp:277
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107
constexpr rowsize EigenSize_Mul_RowSize()
a * b if both are compile-time sizes, DynamicSize if either is Eigen::Dynamic, otherwise a sentinel.
tVec b(NCells)