20 namespace TrackFindingCDC {
39 template <
class T,
int M,
int N>
42 static_assert(M > 0,
"Dimensions must be greater zero");
43 static_assert(N > 0,
"Dimensions must be greater zero");
46 static const int S = M * N;
56 assert(
m_values.size() >= values.size());
57 std::copy(values.begin(), values.end(),
m_values.begin());
77 for (
int s = 0; s < M * N; s += M + 1)
78 result.m_values[s] = 1;
86 result.m_values.fill(t);
118 return m_values.operator[](j * M + i);
124 return m_values.operator[](j * M + i);
130 for (
int i = 0; i < rhs.
rows(); ++i) {
131 out << rhs(i, 0) <<
", ";
132 for (
int j = 1; j < rhs.
cols(); ++j) {
144 std::transform(
begin(),
end(), rhs.
begin(), result.begin(), std::plus<T>());
152 std::transform(
begin(),
end(), rhs.
begin(), result.begin(), std::minus<T>());
161 for (
int m = 0; m < M; ++m) {
162 for (
int o = 0; o < O; ++o) {
163 for (
int n = 0; n < N; ++n) {
175 std::transform(
begin(),
end(), result.begin(), [&rhs](
const T & t) { return t / rhs; });
183 std::transform(rhs.
begin(), rhs.
end(), result.begin(), [&lhs](
const T & t) {
190 template <
int K,
int L>
193 assert(
K + i <= M &&
"Selected block reaches outside of the matrix");
194 assert(L + j <= N &&
"Selected block reaches outside of the matrix");
197 const int skipFront = j * M + i;
198 for (
int iCol = 0; iCol < L; ++iCol) {
199 std::copy(
begin() + skipFront + iCol * M,
200 begin() + skipFront + iCol * M +
K,
201 result.data() + iCol * L);
210 return block<K, N>(0, 0);
217 return block<K, N>(M -
K, 0);
A matrix implementation to be used as an interface typ through out the track finder.
static const int S
Total number of elements.
const T * end() const
The end const_iterator of the flattened values.
static constexpr size_t size()
Total number of values in the matrix.
PlainMatrix(std::initializer_list< T > values)
Construct from initialiser list - also for value initialisation.
PlainMatrix< T, K, N > tail() const
Get the K bottom rows of the matrix.
static PlainMatrix< T, M, N > Constant(T t)
Construct a matrix with all elements set to a constant.
T operator()(int i, int j=0) const
Constant element access at the given row i and column j.
static constexpr int cols()
Total number of columns in the matrix.
PlainMatrix(std::array< T, S > values)
Construct from the given values.
static constexpr int rows()
Total number of rows in the matrix.
const T * data() const
Constant access to the flat value array.
PlainMatrix< T, K, L > block(int i=0, int j=0) const
Get the K x L block from the matrix starting at the element at position (i, j)
static PlainMatrix< T, M, N > Identity()
Construct an identity matrix.
PlainMatrix< T, M, N > operator+(const PlainMatrix< T, M, N > &rhs) const
Elementwise addition of two matrices.
friend std::ostream & operator<<(std::ostream &out, const PlainMatrix< T, M, N > &rhs)
Output operator for debugging purposes.
T * begin()
The begin iterator of the flattened values.
T * end()
The end iterator of the flattened values.
static PlainMatrix< T, M, N > Zero()
Construct a matrix initialized with zeros.
friend PlainMatrix< T, M, N > operator/(T lhs, PlainMatrix< T, M, N > &rhs)
Elementwise division of a number by the elements of the matrix.
PlainMatrix< T, M, N > operator/(T rhs) const
Elementwise division of the elements of the matrix by a number.
PlainMatrix< T, K, N > head() const
Get the K top rows of the matrix.
PlainMatrix< T, M, O > operator*(const PlainMatrix< T, N, O > &rhs) const
Naive matrix multiplication.
T operator[](int s) const
Constant flat element access at the given row i and column j.
PlainMatrix()=default
Default initializing of the matrix.
T & operator()(int i, int j=0)
Element access at the given row i and column j.
T & operator[](int s)
Flat element access at the given row i and column j.
T * data()
Access to the flat value array.
PlainMatrix< T, M, N > operator-(const PlainMatrix< T, M, N > &rhs) const
Elementwise subtraction of two matrices.
std::array< T, M *N > m_values
Memory of the flat value content.
const T * begin() const
The begin const_iterator of the flattened values.
Abstract base class for different kinds of events.