Project
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
17#ifndef ALICEO2_TPC_VECTOR_H_
18#define ALICEO2_TPC_VECTOR_H_
19
20#include <Vc/vector>
21#include <Vc/Memory>
22
23namespace o2
24{
25namespace tpc
26{
27
28template <typename DataT, size_t N>
29class Vector
30{
31 using VDataT = Vc::Vector<DataT>;
32
33 public:
35 Vector() = default;
36
38 Vector(Vc::Memory<VDataT, N>&& dataVector) : mDataVector(std::move(dataVector)) {}
39
41 const DataT operator[](size_t i) const { return mDataVector.scalar(i); }
42 DataT& operator[](size_t i) { return mDataVector.scalar(i); }
43
45 void setVector(const size_t j, const VDataT& vector) { mDataVector.vector(j) = vector; }
46
48 const VDataT getVector(const size_t j) const { return mDataVector.vector(j); }
49
51 size_t getvectorsCount() const { return mDataVector.vectorsCount(); }
52
53 private:
54 Vc::Memory<VDataT, N> mDataVector{};
55};
56
57template <typename DataT, size_t N>
58inline Vector<DataT, N> operator*(const std::array<Vc::Memory<Vc::Vector<DataT>, N>, N>& a, const Vector<DataT, N>& b)
59{
60 using V = Vc::Vector<DataT>;
61 // resulting vector c
63 for (size_t i = 0; i < N; ++i) {
64 V c_ij{};
65 for (size_t j = 0; j < a[i].vectorsCount(); ++j) {
66 c_ij += a[i].vector(j) * b.getVector(j);
67 }
68 c[i] = c_ij.sum();
69 }
70 return c;
71}
72
73template <typename DataT, size_t N>
75{
77 for (size_t j = 0; j < a.getvectorsCount(); ++j) {
78 c.setVector(j, Vc::floor(a.getVector(j)));
79 }
80 return c;
81}
82
83template <typename DataT, size_t N>
85{
86 // resulting matrix c
88 for (size_t j = 0; j < a.getvectorsCount(); ++j) {
89 c.setVector(j, a.getVector(j) - b.getVector(j));
90 }
91 return c;
92}
93
94template <typename DataT, size_t N>
96{
97 // resulting matrix c
99 for (size_t j = 0; j < b.getvectorsCount(); ++j) {
100 c.setVector(j, a * b.getVector(j));
101 }
102 return c;
103}
104
105// compute the sum of one Vector
106template <typename DataT, size_t N>
108{
109 // resulting matrix c
110 Vc::Vector<DataT> b = a.getVector(0);
111 for (size_t j = 1; j < a.getvectorsCount(); ++j) {
112 b += a.getVector(j);
113 }
114 return b.sum();
115}
116
117// multiply each row from a vector with the row from a second vector
118template <typename DataT, size_t N>
120{
121 // resulting matrix c
123 for (size_t j = 0; j < a.getvectorsCount(); ++j) {
124 c.setVector(j, a.getVector(j) * b.getVector(j));
125 }
126 return c;
127}
128
129} // namespace tpc
130} // namespace o2
131
132#endif
int32_t i
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Vector()=default
default constructor
DataT & operator[](size_t i)
Definition Vector.h:42
Vector(Vc::Memory< VDataT, N > &&dataVector)
constructor
Definition Vector.h:38
const DataT operator[](size_t i) const
operator access
Definition Vector.h:41
size_t getvectorsCount() const
Definition Vector.h:51
void setVector(const size_t j, const VDataT &vector)
sets the vector with index j
Definition Vector.h:45
const VDataT getVector(const size_t j) const
Definition Vector.h:48
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
Vector< DataT, N > floor_vec(const Vector< DataT, N > &a)
Definition Vector.h:74
Vector< DataT, N > operator*(const std::array< Vc::Memory< Vc::Vector< DataT >, N >, N > &a, const Vector< DataT, N > &b)
Definition Vector.h:58
CalDet< T > operator-(const CalDet< T > &c1, const CalDet< T > &c2)
Definition CalDet.h:448
DataT sum(const Vector< DataT, N > &a)
Definition Vector.h:107
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.