 |
Belle II Software
release-05-02-19
|
22 namespace TrackFindingCDC {
41 template <
class T,
int M,
int N>
44 static_assert(M > 0,
"Dimensions must be greater zero");
45 static_assert(N > 0,
"Dimensions must be greater zero");
48 static const int S = M * N;
55 explicit PlainMatrix(std::initializer_list<T> values)
58 assert(
m_values.size() >= values.size());
59 std::copy(values.begin(), values.end(),
m_values.begin());
76 static PlainMatrix<T, M, N>
Identity()
79 for (
int s = 0; s < M * N; s += M + 1)
80 result.m_values[s] = 1;
88 result.m_values.fill(t);
100 const T*
data()
const
132 for (
int i = 0; i < rhs.rows(); ++i) {
133 out << rhs(i, 0) <<
", ";
134 for (
int j = 1; j < rhs.cols(); ++j) {
143 PlainMatrix<T, M, N>
operator+(
const PlainMatrix<T, M, N>& rhs)
const
145 PlainMatrix<T, M, N> result;
146 std::transform(
begin(),
end(), rhs.begin(), result.begin(), std::plus<T>());
154 std::transform(
begin(),
end(), rhs.begin(), result.begin(), std::minus<T>());
163 for (
int m = 0; m < M; ++m) {
164 for (
int o = 0; o < O; ++o) {
165 for (
int n = 0; n < N; ++n) {
174 PlainMatrix<T, M, N>
operator/(T rhs)
const
176 PlainMatrix<T, M, N> result;
177 std::transform(
begin(),
end(), result.begin(), [&rhs](
const T & t) { return t / rhs; });
185 std::transform(rhs.begin(), rhs.end(), result.begin(), [&lhs](
const T & t) {
192 template <
int K,
int L>
195 assert(K + i <= M &&
"Selected block reaches outside of the matrix");
196 assert(L + j <= N &&
"Selected block reaches outside of the matrix");
199 const int skipFront = j * M + i;
200 for (
int iCol = 0; iCol < L; ++iCol) {
201 std::copy(
begin() + skipFront + iCol * M,
202 begin() + skipFront + iCol * M + K,
203 result.data() + iCol * L);
210 PlainMatrix<T, K, N>
head()
const
212 return block<K, N>(0, 0);
217 PlainMatrix<T, K, N>
tail()
const
219 return block<K, N>(M - K, 0);
223 static constexpr
size_t size()
229 static constexpr
int rows()
235 static constexpr
int cols()
254 const T*
begin()
const
static PlainMatrix< T, M, N > Zero()
Construct a matrix initialized with zeros.
static constexpr int cols()
Total number of columns in the matrix.
T * end()
The end iterator of the flattened values.
T & operator[](int s)
Flat element access at the given row i and column j.
PlainMatrix< T, K, N > head() const
Get the K top rows of the matrix.
T * begin()
The begin iterator of the flattened values.
friend std::ostream & operator<<(std::ostream &out, const PlainMatrix< T, M, N > &rhs)
Output operator for debugging purposes.
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)
PlainMatrix< T, K, N > tail() const
Get the K bottom rows of the matrix.
T * data()
Access to the flat value array.
Abstract base class for different kinds of events.
std::array< T, M *N > m_values
Memory of the flat value content.
PlainMatrix< T, M, N > operator+(const PlainMatrix< T, M, N > &rhs) const
Elementwise addition of two matrices.
static constexpr int rows()
Total number of rows in the matrix.
static PlainMatrix< T, M, N > Constant(T t)
Construct a matrix with all elements set to a constant.
PlainMatrix< T, M, O > operator*(const PlainMatrix< T, N, O > &rhs) const
Naive matrix multiplication.
PlainMatrix< T, M, N > operator/(T rhs) const
Elementwise division of the elements of the matrix by a number.
PlainMatrix< T, M, N > operator-(const PlainMatrix< T, M, N > &rhs) const
Elementwise subtraction of two matrices.
A matrix implementation to be used as an interface typ through out the track finder.
static constexpr size_t size()
Total number of values in the matrix.
static const int S
Total number of elements.
PlainMatrix()=default
Default initializing of the matrix.
static PlainMatrix< T, M, N > Identity()
Construct an identity matrix.
T & operator()(int i, int j=0)
Element access at the given row i and column j.
PlainMatrix(std::initializer_list< T > values)
Construct from initialiser list - also for value initialisation.