17#ifndef TMVA_DNN_ARCHITECTURES_CPU_CPUMATRIX
18#define TMVA_DNN_ARCHITECTURES_CPU_CPUMATRIX
32#if defined(DEBUG_TMVA_TCPUMATRIX)
45#define TMVA_DNN_PrintTCpuMatrix(mat, text) \
47 auto _dpointer = mat.GetRawDataPointer(); \
48 if (_dpointer == NULL) { \
49 std::cout << #mat << " is null pointer" << std::endl; \
52 auto _nrows = mat.GetNrows(); \
53 auto _ncols = mat.GetNcols(); \
54 std::cout << "---------------------" << text << " " << #mat << "(" << _nrows << "," << _ncols << ")" \
55 << "--------------------" << std::endl; \
56 for (size_t _i = 0; _i < _nrows; _i++) { \
57 for (size_t _j = 0; _j < _ncols; _j++) { \
58 std::cout << mat(_i, _j); \
59 if (_j < _ncols - 1) \
62 std::cout << std::endl; \
66#define TMVA_DNN_PrintTCpuMatrix(mat, text)
85template <
typename AFloat>
88 static std::vector<AFloat>
fOnes;
147 template <
typename Function_t>
148 void Map(Function_t &
f);
152 template <
typename Function_t>
185template <
typename AFloat>
190template <
typename AFloat>
196 const size_t minElements = 1000;
198 if (nElements <= minElements)
200 if (nElements < nCpu * minElements) {
201 size_t nt = nElements / minElements;
202 return nElements / nt;
204 return nElements / nCpu;
210template <
typename AFloat>
211template <
typename Function_t>
214 AFloat *data = GetRawDataPointer();
215 size_t nelements = GetNoElements();
218 auto ff = [data, &nsteps, &nelements, &
f](
UInt_t workerID) {
219 size_t jMax = std::min(workerID + nsteps, nelements);
220 for (
size_t j = workerID; j < jMax; ++j) {
221 data[j] =
f(data[j]);
226 if (nsteps < nelements) {
239template <
typename AFloat>
240template <
typename Function_t>
243 AFloat *dataB = GetRawDataPointer();
246 size_t nelements = GetNoElements();
250 auto ff = [&dataB, &dataA, &nsteps, &nelements, &
f](
UInt_t workerID) {
251 size_t jMax = std::min(workerID + nsteps, nelements);
252 for (
size_t j = workerID; j < jMax; ++j) {
253 dataB[j] =
f(dataA[j]);
257 if (nsteps < nelements) {
268template <
typename AFloat>
271 for (
size_t j = 0; j < fNCols; j++) {
272 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 TCpuBuffer< AFloat > & GetDeviceBuffer() const
const AFloat * GetRawDataPointer() const
const TCpuBuffer< AFloat > & GetBuffer() const
static size_t GetNWorkItems(size_t nelements)
TCpuBuffer< AFloat > & GetDeviceBuffer()
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()
TCpuMatrix< AFloat > & operator=(const TMatrixT< AFloat > &)
copy from a TMAtrixT .
size_t GetNoElements() const
TCpuMatrix(const TCpuMatrix &)=default
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
create variable transformations