17#ifndef TMVA_DNN_ARCHITECTURES_CPU_CPUTENSOR
18#define TMVA_DNN_ARCHITECTURES_CPU_CPUTENSOR
39template <
typename AFloat>
65 if (memlayout == MemoryLayout::RowMajor)
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);
216 x.ReshapeInplace(shape);
226 Shape_t sliced_shape = (layout == MemoryLayout::RowMajor) ?
Shape_t(shape.begin() + 1, shape.end())
227 :
Shape_t(shape.begin(), shape.end() - 1);
229 size_t buffsize = (layout == MemoryLayout::RowMajor) ? this->
GetStrides().front() : this->
GetStrides().back();
230 size_t offset = i * buffsize;
240 return At(i).GetMatrix();
247 for (
size_t i = 0; i < this->
GetSize(); ++i)
255 assert(shape.size() == 2);
265 assert(shape.size() == 3);
268 ? (*(this->
GetContainer()))[i * shape[1] * shape[2] + j * shape[2] + k]
269 : (*(this->
GetContainer()))[i * shape[0] * shape[1] + k * shape[0] + j];
276 assert(shape.size() == 2);
278 : (this->
GetData())[j * shape[0] + i];
284 assert(shape.size() == 3);
287 ? (this->
GetData())[i * shape[1] * shape[2] + j * shape[2] + k]
288 : (this->
GetData())[i * shape[0] * shape[1] + k * shape[0] + j];
293 template <
typename Function_t>
294 void Map(Function_t &
f);
298 template <
typename Function_t>
307 for (
size_t i = 0; i < this->
GetSize(); i++)
308 std::cout << (this->
GetData())[i] <<
" ";
309 std::cout << std::endl;
313 std::string memlayout = (
GetLayout() == MemoryLayout::RowMajor) ?
"RowMajor" :
"ColMajor";
314 std::cout <<
name <<
" shape : { ";
316 for (
size_t i = 0; i < shape.size() - 1; ++i)
317 std::cout << shape[i] <<
" , ";
318 std::cout << shape.back() <<
" } "
319 <<
" Layout : " << memlayout << std::endl;
324template <
typename AFloat>
325template <
typename Function_t>
328 AFloat *
data = GetRawDataPointer();
329 size_t nelements = GetNoElements();
332 auto ff = [
data, &nsteps, &nelements, &
f](
UInt_t workerID) {
333 size_t jMax = std::min(workerID + nsteps, nelements);
334 for (
size_t j = workerID; j < jMax; ++j) {
340 if (nsteps < nelements) {
353template <
typename AFloat>
354template <
typename Function_t>
357 AFloat *dataB = GetRawDataPointer();
360 size_t nelements = GetNoElements();
364 auto ff = [&dataB, &dataA, &nsteps, &nelements, &
f](
UInt_t workerID) {
365 size_t jMax = std::min(workerID + nsteps, nelements);
366 for (
size_t j = workerID; j < jMax; ++j) {
367 dataB[j] =
f(dataA[j]);
371 if (nsteps < nelements) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
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
static size_t GetNWorkItems(size_t nelements)
size_t GetBufferUseCount() const
AFloat operator()(size_t i, size_t j, size_t k) const
TCpuTensor(size_t n, size_t m, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
constructors from n m
TCpuTensor(size_t bsize, size_t depth, size_t height, size_t width, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
constructors from batch size, depth, height, width
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
size_t GetNoElements() const
void Map(Function_t &f)
Map the given function over the matrix elements.
const TCpuBuffer< AFloat > & GetDeviceBuffer() const
TCpuTensor(size_t bsize, size_t depth, size_t hw, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
constructors from batch size, depth, height*width
TCpuMatrix< AFloat > operator[](size_t i) const
const AFloat * GetRawDataPointer() const
TCpuBuffer< AFloat > & GetDeviceBuffer()
AFloat & operator()(size_t i, size_t j, size_t k)
TCpuTensor(const TCpuBuffer< AFloat > &buffer, Shape_t shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
constructors from a TCpuBuffer and a shape
void MapFrom(Function_t &f, const TCpuTensor< AFloat > &A)
Same as maps but takes the input values from the tensor A and writes the results in this tensor.
AFloat operator()(size_t i, size_t j) const
TCpuTensor(const TCpuMatrix< AFloat > &matrix, size_t dim=3, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
constructors from a TCpuMatrix.
TCpuMatrix< AFloat > GetMatrix() const
TCpuTensor< AFloat > At(size_t i) const
TCpuTensor(Shape_t shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
constructors from a shape.
size_t GetFirstSize() const
void PrintShape(const char *name="Tensor") const
AFloat & operator()(size_t i, size_t j)
TCpuTensor< AFloat > At(size_t i)
friend class TCpuMatrix< AFloat >
MemoryLayout GetLayout() const
void Print(const char *name="Tensor") const
TCpuTensor< AFloat > Reshape(Shape_t shape) const
typename TMVA::Experimental::RTensor< AFloat >::Shape_t Shape_t
TCpuTensor(AFloat *data, const Shape_t &shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
RTensor is a container with contiguous memory and shape information.
void ReshapeInplace(const Shape_t &shape)
Reshape tensor in place.
MemoryLayout GetMemoryLayout() const
std::shared_ptr< Container_t > GetContainer()
const Shape_t & GetStrides() const
std::size_t GetSize() const
RTensor(Value_t *data, Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
Construct a tensor as view on data.
const Shape_t & GetShape() const
std::vector< std::size_t > Shape_t
MemoryLayout
Memory layout type (copy from RTensor.hxx)
create variable transformations