17 #ifndef TMVA_DNN_ARCHITECTURES_CPU_CPUTENSOR
18 #define TMVA_DNN_ARCHITECTURES_CPU_CPUTENSOR
39 template <
typename AFloat>
65 if (memlayout == MemoryLayout::RowMajor)
73 {depth, height,
width, bsize}, memlayout)
75 if (memlayout == MemoryLayout::RowMajor)
92 for (
size_t i = 0; i < this->
GetSize(); ++i) container[i] = data[i];
115 if (this->
GetLayout() == MemoryLayout::ColumnMajor) {
116 shape.insert(shape.end(),dim-2, 1);
118 shape.insert(shape.begin(), dim - 2, 1);
158 return (this->
GetMemoryLayout() == MemoryLayout::ColumnMajor) ? shape.back() : shape.front();
164 if (shape.size() == 2)
return 1;
165 return (this->
GetMemoryLayout() == MemoryLayout::ColumnMajor) ? shape.front() : shape[1];
171 if (shape.size() == 2)
return shape[0];
172 if (shape.size() == 3)
return (this->
GetMemoryLayout() == MemoryLayout::ColumnMajor) ? shape[0] : shape[1] ;
173 if (shape.size() >= 4)
return shape[2] ;
180 if (shape.size() == 2)
return shape[1];
181 if (shape.size() == 3)
return (this->
GetMemoryLayout() == MemoryLayout::ColumnMajor) ? shape[1] : shape[2] ;
182 if (shape.size() >= 4)
return shape[3] ;
202 for (
auto& shape_i : shape){
207 assert(ndims <= 2 && shape.size() > 1);
215 x.ReshapeInplace(shape);
225 Shape_t sliced_shape = (layout == MemoryLayout::RowMajor) ?
Shape_t(shape.begin() + 1, shape.end())
226 :
Shape_t(shape.begin(), shape.end() - 1);
228 size_t buffsize = (layout == MemoryLayout::RowMajor) ? this->
GetStrides().front() : this->
GetStrides().back();
229 size_t offset = i * buffsize;
239 return At(i).GetMatrix();
246 for (
size_t i = 0; i < this->
GetSize(); ++i)
254 assert(shape.size() == 2);
264 assert(shape.size() == 3);
267 ? (*(this->
GetContainer()))[i * shape[1] * shape[2] + j * shape[2] + k]
268 : (*(this->
GetContainer()))[i * shape[0] * shape[1] + k * shape[0] + j];
275 assert(shape.size() == 2);
277 : (this->
GetData())[j * shape[0] + i];
283 assert(shape.size() == 3);
286 ? (this->
GetData())[i * shape[1] * shape[2] + j * shape[2] + k]
287 : (this->
GetData())[i * shape[0] * shape[1] + k * shape[0] + j];
292 template <
typename Function_t>
293 void Map(Function_t &
f);
297 template <
typename Function_t>
306 for (
size_t i = 0; i < this->
GetSize(); i++)
307 std::cout << (this->
GetData())[i] <<
" ";
308 std::cout << std::endl;
312 std::string memlayout = (
GetLayout() == MemoryLayout::RowMajor) ?
"RowMajor" :
"ColMajor";
313 std::cout <<
name <<
" shape : { ";
315 for (
size_t i = 0; i < shape.size() - 1; ++i)
316 std::cout << shape[i] <<
" , ";
317 std::cout << shape.back() <<
" } "
318 <<
" Layout : " << memlayout << std::endl;
323 template <
typename AFloat>
324 template <
typename Function_t>
327 AFloat *data = GetRawDataPointer();
328 size_t nelements = GetNoElements();
331 auto ff = [data, &nsteps, &nelements, &
f](
UInt_t workerID) {
332 size_t jMax = std::min(workerID + nsteps, nelements);
333 for (
size_t j = workerID; j < jMax; ++j) {
334 data[j] =
f(data[j]);
339 if (nsteps < nelements) {
352 template <
typename AFloat>
353 template <
typename Function_t>
356 AFloat *dataB = GetRawDataPointer();
357 const AFloat *dataA =
A.GetRawDataPointer();
359 size_t nelements = GetNoElements();
363 auto ff = [&dataB, &dataA, &nsteps, &nelements, &
f](
UInt_t workerID) {
364 size_t jMax = std::min(workerID + nsteps, nelements);
365 for (
size_t j = workerID; j < jMax; ++j) {
366 dataB[j] =
f(dataA[j]);
370 if (nsteps < nelements) {