30class ConstTransposeSubMatrix
33 using NestedType = TMatrix;
34 using ScalarType =
typename NestedType::ScalarType;
35 using SelfType = ConstTransposeSubMatrix<NestedType, M, N>;
37 static auto constexpr kRows = M;
38 static auto constexpr kCols = N;
39 static bool constexpr bRowMajor = NestedType::bRowMajor;
41 PBAT_HOST_DEVICE ConstTransposeSubMatrix(NestedType
const& _A,
int _ib = 0,
int _jb = 0)
42 : A(_A), ib(_ib), jb(_jb)
45 NestedType::kRows >= M and NestedType::kCols >= N and M > 0 and N > 0,
46 "Invalid submatrix dimensions");
49 PBAT_HOST_DEVICE
constexpr auto Rows()
const {
return kRows; }
50 PBAT_HOST_DEVICE
constexpr auto Cols()
const {
return kCols; }
52 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const {
return A(ib + i, jb + j); }
55 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
56 PBAT_HOST_DEVICE ScalarType operator[](
auto i)
const {
return (*
this)(i); }
58 template <auto S, auto T>
59 PBAT_HOST_DEVICE
auto Slice(
int i,
int j)
const
61 return ConstTransposeSubMatrix<SelfType, S, T>(*
this, i, j);
63 PBAT_HOST_DEVICE
auto Col(
int j)
const {
return Slice<kRows, 1>(0, j); }
64 PBAT_HOST_DEVICE
auto Row(
int i)
const {
return Slice<1, kCols>(i, 0); }
73class TransposeSubMatrix
76 using NestedType = TMatrix;
77 using ScalarType =
typename NestedType::ScalarType;
78 using SelfType = TransposeSubMatrix<NestedType, M, N>;
80 static auto constexpr kRows = M;
81 static auto constexpr kCols = N;
82 static bool constexpr bRowMajor = NestedType::bRowMajor;
84 PBAT_HOST_DEVICE TransposeSubMatrix(NestedType& _A,
int _ib = 0,
int _jb = 0)
85 : A(_A), ib(_ib), jb(_jb)
88 NestedType::kRows >= M and NestedType::kCols >= N and M > 0 and N > 0,
89 "Invalid submatrix dimensions");
92 template <
class TOtherMatrix>
93 PBAT_HOST_DEVICE SelfType& operator=(TOtherMatrix&& B)
95 Assign(*
this, std::forward<TOtherMatrix>(B));
99 PBAT_HOST_DEVICE
constexpr auto Rows()
const {
return kRows; }
100 PBAT_HOST_DEVICE
constexpr auto Cols()
const {
return kCols; }
102 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const {
return A(ib + i, jb + j); }
103 PBAT_HOST_DEVICE ScalarType& operator()(
auto i,
auto j) {
return A(ib + i, jb + j); }
106 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
107 PBAT_HOST_DEVICE ScalarType& operator()(
auto i) {
return (*
this)(i % kRows, i / kRows); }
108 PBAT_HOST_DEVICE ScalarType operator[](
auto i)
const {
return (*
this)(i); }
109 PBAT_HOST_DEVICE ScalarType& operator[](
auto i) {
return (*
this)(i); }
111 template <auto S, auto T>
112 PBAT_HOST_DEVICE
auto Slice(
int i,
int j)
114 return TransposeSubMatrix<SelfType, S, T>(*
this, i, j);
116 PBAT_HOST_DEVICE
auto Col(
int j) {
return Slice<kRows, 1>(0, j); }
117 PBAT_HOST_DEVICE
auto Row(
int i) {
return Slice<1, kCols>(i, 0); }
119 template <auto S, auto T>
120 PBAT_HOST_DEVICE
auto Slice(
int i,
int j)
const
124 PBAT_HOST_DEVICE
auto Col(
int j)
const {
return Slice<kRows, 1>(0, j); }
125 PBAT_HOST_DEVICE
auto Row(
int i)
const {
return Slice<1, kCols>(i, 0); }
130 void SetConstant(
auto k) { AssignScalar(*
this, k); }
141 using NestedType = TMatrix;
142 using ScalarType =
typename NestedType::ScalarType;
143 using SelfType = TransposeView<NestedType>;
145 static auto constexpr kRows = NestedType::kCols;
146 static auto constexpr kCols = NestedType::kRows;
147 static bool constexpr bRowMajor = not NestedType::bRowMajor;
149 PBAT_HOST_DEVICE TransposeView(NestedType& _A) : A(_A) {}
151 template <
class TOtherMatrix>
152 PBAT_HOST_DEVICE SelfType& operator=(TOtherMatrix&& B)
154 Assign(*
this, std::forward<TOtherMatrix>(B));
158 PBAT_HOST_DEVICE
void SetConstant(ScalarType k)
160 using IntegerType = std::remove_const_t<
decltype(kCols)>;
162 [&]<IntegerType... I>(IntegerType j, std::integer_sequence<IntegerType, I...>) {
163 (((*this)(I, j) = k), ...);
165 auto fCols = [&]<IntegerType... J>(std::integer_sequence<IntegerType, J...>) {
166 (fRows(J, std::make_integer_sequence<IntegerType, kRows>()), ...);
168 fCols(std::make_integer_sequence<IntegerType, kCols>());
171 PBAT_HOST_DEVICE
constexpr auto Rows()
const {
return A.Cols(); }
172 PBAT_HOST_DEVICE
constexpr auto Cols()
const {
return A.Rows(); }
174 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const {
return A(j, i); }
175 PBAT_HOST_DEVICE ScalarType& operator()(
auto i,
auto j) {
return A(j, i); }
178 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
179 PBAT_HOST_DEVICE ScalarType& operator()(
auto i) {
return (*
this)(i % kRows, i / kRows); }
180 PBAT_HOST_DEVICE ScalarType operator[](
auto i)
const {
return (*
this)(i); }
181 PBAT_HOST_DEVICE ScalarType& operator[](
auto i) {
return (*
this)(i); }
183 template <auto S, auto T>
184 PBAT_HOST_DEVICE
auto Slice(
auto i,
auto j)
188 PBAT_HOST_DEVICE
auto Col(
auto j) {
return Slice<kRows, 1>(0, j); }
189 PBAT_HOST_DEVICE
auto Row(
auto i) {
return Slice<1, kCols>(i, 0); }
191 template <auto S, auto T>
192 PBAT_HOST_DEVICE
auto Slice(
auto i,
auto j)
const
196 PBAT_HOST_DEVICE
auto Col(
auto j)
const {
return Slice<kRows, 1>(0, j); }
197 PBAT_HOST_DEVICE
auto Row(
auto i)
const {
return Slice<1, kCols>(i, 0); }
199 PBAT_HOST_DEVICE NestedType
const& Transpose()
const {
return A; }
200 PBAT_HOST_DEVICE NestedType& Transpose() {
return A; }
202 void SetConstant(
auto k) { AssignScalar(*
this, k); }
209class ConstTransposeView
212 using NestedType = TMatrix;
213 using ScalarType =
typename NestedType::ScalarType;
214 using SelfType = ConstTransposeView<NestedType>;
216 static auto constexpr kRows = NestedType::kCols;
217 static auto constexpr kCols = NestedType::kRows;
218 static bool constexpr bRowMajor = not NestedType::bRowMajor;
220 PBAT_HOST_DEVICE ConstTransposeView(NestedType
const& _A) : A(_A) {}
222 PBAT_HOST_DEVICE
constexpr auto Rows()
const {
return A.Cols(); }
223 PBAT_HOST_DEVICE
constexpr auto Cols()
const {
return A.Rows(); }
225 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const {
return A(j, i); }
228 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
230 template <auto S, auto T>
231 PBAT_HOST_DEVICE
auto Slice(
auto i,
auto j)
const
235 PBAT_HOST_DEVICE
auto Col(
auto j)
const {
return Slice<kRows, 1>(0, j); }
236 PBAT_HOST_DEVICE
auto Row(
auto i)
const {
return Slice<1, kCols>(i, 0); }
238 PBAT_HOST_DEVICE NestedType
const& Transpose()
const {
return A; }