Belle II Software  release-05-02-19
PlainMatrixUtil.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/numerics/PlainMatrix.h>
13 
14 namespace Belle2 {
19  namespace TrackFindingCDC {
20 
22  struct PlainMatrixUtil {
23 
25  template <class T, int M>
26  static PlainMatrix<T, M, M> Diag(const PlainMatrix<T, M, 1>& diagEntries)
27  {
28  PlainMatrix<T, M, M> result{{}}; // Value initialize to zero
29  for (size_t s = 0, i = 0; s < result.size(); s += M + 1, ++i)
30  result[s] = diagEntries(i, 0);
31  return result;
32  }
33 
35  template <class T, int K, int L, int M, int N>
38  {
39  const int nRows = K + M;
40  // const int nCols = L + N;
41  PlainMatrix < T, K + M, L + N > result{{}}; // Value initialize to zero
42 
43  const int nARows = K;
44  const int nACols = L;
45  for (int iACol = 0; iACol < nACols; ++iACol) {
46  std::copy(a.data() + iACol * nARows,
47  a.data() + (iACol + 1) * nARows,
48  result.data() + iACol * nRows);
49  }
50 
51  const int nBRows = M;
52  const int nBCols = N;
53  const int skipA = nACols * nRows;
54  const int skipFront = nARows;
55  for (int iBCol = 0; iBCol < nBCols; ++iBCol) {
56  std::copy(b.data() + iBCol * nBRows,
57  b.data() + (iBCol + 1) * nBRows,
58  result.data() + skipA + skipFront + iBCol * nRows);
59  }
60  return result;
61  }
62 
64  template <class T, int K, int M, int N>
65  static PlainMatrix < T, K + M, N >
66  VStack(const PlainMatrix<T, K, N>& a, const PlainMatrix<T, M, N>& b)
67  {
68  const int nRows = K + M;
69  const int nCols = N;
70  PlainMatrix < T, K + M, N > result;
71 
72  const int nARows = K;
73  const int nBRows = M;
74  const int skipFront = nARows;
75  for (int iCol = 0; iCol < nCols; ++iCol) {
76  std::copy(a.data() + iCol * nARows,
77  a.data() + (iCol + 1) * nARows,
78  result.data() + iCol * nRows);
79 
80  std::copy(b.data() + iCol * nBRows,
81  b.data() + (iCol + 1) * nBRows,
82  result.data() + skipFront + iCol * nRows);
83  }
84  return result;
85  }
86 
88  template <class T, int M, int L, int N>
89  static PlainMatrix < T, M, L + N >
90  HStack(const PlainMatrix<T, M, L>& a, const PlainMatrix<T, M, N>& b)
91  {
92  PlainMatrix < T, M, L + N > result;
93  std::copy(a.data(), a.data() + a.size(), result.data());
94  std::copy(b.data(), b.data() + b.size(), result.data() + a.size());
95  return result;
96  }
97  };
98  }
100 }
Belle2::TrackFindingCDC::PlainMatrixUtil::VStack
static PlainMatrix< T, K+M, N > VStack(const PlainMatrix< T, K, N > &a, const PlainMatrix< T, M, N > &b)
Construct a matrix from two independent blocks stacked vertically.
Definition: PlainMatrixUtil.h:74
Belle2::TrackFindingCDC::PlainMatrixUtil::BlockStack
static PlainMatrix< T, K+M, L+N > BlockStack(const PlainMatrix< T, K, L > &a, const PlainMatrix< T, M, N > &b)
Construct a matrix from two independent blocks stacked along the diagonal.
Definition: PlainMatrixUtil.h:45
Belle2::TrackFindingCDC::PlainMatrixUtil::HStack
static PlainMatrix< T, M, L+N > HStack(const PlainMatrix< T, M, L > &a, const PlainMatrix< T, M, N > &b)
Construct a matrix from two independent blocks stacked horizontally.
Definition: PlainMatrixUtil.h:98
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::PlainMatrixUtil::Diag
static PlainMatrix< T, M, M > Diag(const PlainMatrix< T, M, 1 > &diagEntries)
Construct a diagonal matrix - currently private as it is unused.
Definition: PlainMatrixUtil.h:34
Belle2::TrackFindingCDC::PlainMatrix
A matrix implementation to be used as an interface typ through out the track finder.
Definition: PlainMatrix.h:50