gpu.cpp 0.1.0
 
Loading...
Searching...
No Matches
gpu::Shape Struct Reference

Represents the shape of a tensor. More...

#include <gpu.h>

Public Member Functions

 Shape ()=default
 
 Shape (std::initializer_list< size_t > dims)
 
size_t & operator[] (size_t index)
 
const size_t & operator[] (size_t index) const
 

Public Attributes

std::array< size_t, kMaxRankdata = {0}
 
size_t rank = 0
 

Static Public Attributes

static constexpr size_t kMaxRank = 8
 

Detailed Description

Represents the shape of a tensor.

The rank of the tensor is the number of dimensions in the shape. The data array stores the size of each dimension. For now, we limit the rank to 8 to avoid dynamic allocation.

Shape shape = {256, 256};
Represents the shape of a tensor.
Definition gpu.h:49

Definition at line 49 of file gpu.h.

Constructor & Destructor Documentation

◆ Shape() [1/2]

gpu::Shape::Shape ( )
inlinedefault

◆ Shape() [2/2]

gpu::Shape::Shape ( std::initializer_list< size_t > dims)
inline

Definition at line 55 of file gpu.h.

55 {
56 assert(dims.size() <= kMaxRank);
57 std::copy(dims.begin(), dims.end(), data.begin());
58 rank = dims.size();
59 }
size_t rank
Definition gpu.h:53
std::array< size_t, kMaxRank > data
Definition gpu.h:52
static constexpr size_t kMaxRank
Definition gpu.h:50

Member Function Documentation

◆ operator[]() [1/2]

size_t & gpu::Shape::operator[] ( size_t index)
inline

Definition at line 60 of file gpu.h.

60 {
61 assert(index < rank);
62 return data[index];
63 }

◆ operator[]() [2/2]

const size_t & gpu::Shape::operator[] ( size_t index) const
inline

Definition at line 64 of file gpu.h.

64 {
65 assert(index < rank);
66 return data[index];
67 }

Member Data Documentation

◆ data

std::array<size_t, kMaxRank> gpu::Shape::data = {0}

Definition at line 52 of file gpu.h.

52{0};

◆ kMaxRank

size_t gpu::Shape::kMaxRank = 8
staticconstexpr

Definition at line 50 of file gpu.h.

◆ rank

size_t gpu::Shape::rank = 0

Definition at line 53 of file gpu.h.


The documentation for this struct was generated from the following file: