17#ifndef TMVA_DNN_ARCHITECTURES_CPU_CPUMATRIX
18#define TMVA_DNN_ARCHITECTURES_CPU_CPUMATRIX
33#if defined(DEBUG_TMVA_TCPUMATRIX)
46#define TMVA_DNN_PrintTCpuMatrix(mat, text) \
48 auto _dpointer = mat.GetRawDataPointer(); \
49 if (_dpointer == NULL) { \
50 std::cout << #mat << " is null pointer" << std::endl; \
53 auto _nrows = mat.GetNrows(); \
54 auto _ncols = mat.GetNcols(); \
55 std::cout << "---------------------" << text << " " << #mat << "(" << _nrows << "," << _ncols << ")" \
56 << "--------------------" << std::endl; \
57 for (size_t _i = 0; _i < _nrows; _i++) { \
58 for (size_t _j = 0; _j < _ncols; _j++) { \
59 std::cout << mat(_i, _j); \
60 if (_j < _ncols - 1) \
63 std::cout << std::endl; \
67#define TMVA_DNN_PrintTCpuMatrix(mat, text)
86template <
typename AFloat>
89 static std::vector<AFloat>
fOnes;
143 template <
typename Function_t>
144 void Map(Function_t &
f);
148 template <
typename Function_t>
181template <
typename AFloat>
186template <
typename AFloat>
192 const size_t minElements = 1000;
194 if (nElements <= minElements)
196 if (nElements < nCpu * minElements) {
197 size_t nt = nElements / minElements;
198 return nElements / nt;
200 return nElements / nCpu;
206template <
typename AFloat>
207template <
typename Function_t>
210 AFloat *data = GetRawDataPointer();
211 size_t nelements = GetNoElements();
214 auto ff = [data, &nsteps, &nelements, &
f](
UInt_t workerID) {
215 size_t jMax = std::min(workerID + nsteps, nelements);
216 for (
size_t j = workerID; j < jMax; ++j) {
217 data[j] =
f(data[j]);
222 if (nsteps < nelements) {
235template <
typename AFloat>
236template <
typename Function_t>
239 AFloat *dataB = GetRawDataPointer();
240 const AFloat *dataA =
A.GetRawDataPointer();
242 size_t nelements = GetNoElements();
246 auto ff = [&dataB, &dataA, &nsteps, &nelements, &
f](
UInt_t workerID) {
247 size_t jMax = std::min(workerID + nsteps, nelements);
248 for (
size_t j = workerID; j < jMax; ++j) {
249 dataB[j] =
f(dataA[j]);
253 if (nsteps < nelements) {
264template <
typename AFloat>
267 for (
size_t j = 0; j < fNCols; j++) {
268 for (
size_t i = 0; i < fNRows; i++) {
#define TMVA_DNN_PrintTCpuMatrix(mat, text)
A pseudo container class which is a generator of indices.
Executor & GetThreadExecutor()
Get executor class for multi-thread usage In case when MT is not enabled will return a serial executo...
static Config & Instance()
static function: returns TMVA instance
TCpuMatrix(TCpuMatrix &&)=default
static std::vector< AFloat > fOnes
Vector filled with ones used for BLAS calls.
TCpuMatrix & operator=(const TCpuMatrix &)=default
TCpuMatrix(const TCpuBuffer< AFloat > &buffer, size_t m, size_t n)
Construct a m-times-n matrix from the given buffer.
void MapFrom(Function_t &f, const TCpuMatrix &A)
Same as maps but takes the input values from the matrix A and writes the results in this matrix.
static size_t GetOnePointerSize()
void Zero()
Clear content of the matrix and initialize to zero elements.
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
AFloat & operator()(size_t i, size_t j)
static const AFloat * GetOnePointer()
TCpuMatrix(const TMatrixT< AFloat > &)
Construct a TCpuMatrix object by (deeply) copying from a TMatrixT<Double_t> matrix.
AFloat operator()(size_t i, size_t j) const
Return matrix element in row i and column j.
const AFloat * GetRawDataPointer() const
const TCpuBuffer< AFloat > & GetBuffer() const
static size_t GetNWorkItems(size_t nelements)
static void InitializeOneVector(size_t n)
TCpuMatrix & operator=(TCpuMatrix &&)=default
TCpuBuffer< AFloat > fBuffer
The buffer holding the matrix elements in column-major format.
TCpuBuffer< AFloat > & GetBuffer()
Returns pointer to a vector holding only ones with a guaranteed length of the number of columns of ev...
void Map(Function_t &f)
Map the given function over the matrix elements.
static Executor & GetThreadExecutor()
size_t GetNoElements() const
TCpuMatrix(const TCpuMatrix &)=default
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
create variable transformations