1#ifndef PBAT_MATH_LINALG_MINI_STACK_H
2#define PBAT_MATH_LINALG_MINI_STACK_H
6#include "pbat/HostDevice.h"
16template <
class TLhsMatrix,
class TRhsMatrix>
20 using LhsNestedType = TLhsMatrix;
21 using RhsNestedType = TRhsMatrix;
22 using ScalarType =
typename LhsNestedType::ScalarType;
23 using SelfType = HorizontalStack<LhsNestedType, RhsNestedType>;
25 static auto constexpr kRows = LhsNestedType::kRows;
26 static auto constexpr kCols = LhsNestedType::kCols + RhsNestedType::kCols;
27 static bool constexpr bRowMajor = LhsNestedType::bRowMajor;
29 PBAT_HOST_DEVICE HorizontalStack(LhsNestedType
const& lhs, RhsNestedType
const& rhs)
30 : mLhs(lhs), mRhs(rhs)
33 LhsNestedType::kRows == RhsNestedType::kRows,
34 "lhs and rhs must have same rows");
37 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const
39 return (j < LhsNestedType::kCols) ? mLhs(i, j) : mRhs(i, j - LhsNestedType::kCols);
43 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
44 PBAT_HOST_DEVICE ScalarType operator[](
auto i)
const {
return (*
this)(i); }
46 PBAT_MINI_READ_API(SelfType)
49 LhsNestedType
const& mLhs;
50 RhsNestedType
const& mRhs;
53template <
class TLhsMatrix,
class TRhsMatrix>
57 using LhsNestedType = TLhsMatrix;
58 using RhsNestedType = TRhsMatrix;
59 using ScalarType =
typename LhsNestedType::ScalarType;
60 using SelfType = VerticalStack<LhsNestedType, RhsNestedType>;
62 static auto constexpr kRows = LhsNestedType::kRows + RhsNestedType::kRows;
63 static auto constexpr kCols = LhsNestedType::kCols;
64 static bool constexpr bRowMajor = LhsNestedType::bRowMajor;
66 PBAT_HOST_DEVICE VerticalStack(LhsNestedType
const& lhs, RhsNestedType
const& rhs)
67 : mLhs(lhs), mRhs(rhs)
70 LhsNestedType::kCols == RhsNestedType::kCols,
71 "lhs and rhs must have same columns");
74 PBAT_HOST_DEVICE ScalarType operator()(
auto i,
auto j)
const
76 return (i < LhsNestedType::kRows) ? mLhs(i, j) : mRhs(i - LhsNestedType::kRows, j);
80 PBAT_HOST_DEVICE ScalarType operator()(
auto i)
const {
return (*
this)(i % kRows, i / kRows); }
81 PBAT_HOST_DEVICE ScalarType operator[](
auto i)
const {
return (*
this)(i); }
83 PBAT_MINI_READ_API(SelfType)
86 LhsNestedType
const& mLhs;
87 RhsNestedType
const& mRhs;
90template <
class TLhsMatrix,
class TRhsMatrix>
91PBAT_HOST_DEVICE
auto HStack(TLhsMatrix&& A, TRhsMatrix&& B)
93 using LhsMatrixType = std::remove_cvref_t<TLhsMatrix>;
94 using RhsMatrixType = std::remove_cvref_t<TRhsMatrix>;
95 PBAT_MINI_CHECK_CMATRIX(LhsMatrixType);
96 PBAT_MINI_CHECK_CMATRIX(RhsMatrixType);
98 std::forward<TLhsMatrix>(A),
99 std::forward<TRhsMatrix>(B));
102template <
class TLhsMatrix,
class TRhsMatrix>
103PBAT_HOST_DEVICE
auto VStack(TLhsMatrix&& A, TRhsMatrix&& B)
105 using LhsMatrixType = std::remove_cvref_t<TLhsMatrix>;
106 using RhsMatrixType = std::remove_cvref_t<TRhsMatrix>;
107 PBAT_MINI_CHECK_CMATRIX(LhsMatrixType);
108 PBAT_MINI_CHECK_CMATRIX(RhsMatrixType);
109 return VerticalStack<LhsMatrixType, RhsMatrixType>(
110 std::forward<TLhsMatrix>(A),
111 std::forward<TRhsMatrix>(B));
Mini linear algebra related functionality.
Definition Assign.h:12
Linear Algebra related functionality.
Definition FilterEigenvalues.h:7
Math related functionality.
Definition Concepts.h:19
The main namespace of the library.
Definition Aliases.h:15