MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / Shape

Class Shape

gpu.hpp:55–74  ·  view source on GitHub ↗

* @brief 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. * * @code * Shape shape = {256, 256}; * @endcode */

Source from the content-addressed store, hash-verified

53 * @endcode
54 */
55struct Shape {
56 static constexpr size_t kMaxRank = 8; // Maximum rank of a tensor, avoids
57 // dynamic allocation for shape data
58 std::array<size_t, kMaxRank> data = {0};
59 size_t rank = 0;
60 inline Shape() = default;
61 inline Shape(std::initializer_list<size_t> dims) {
62 assert(dims.size() <= kMaxRank);
63 std::copy(dims.begin(), dims.end(), data.begin());
64 rank = dims.size();
65 }
66 inline size_t &operator[](size_t index) {
67 assert(index < rank);
68 return data[index];
69 }
70 inline const size_t &operator[](size_t index) const {
71 assert(index < rank);
72 return data[index];
73 }
74};
75
76/**
77 * @brief Returns the number of elements in a tensor with the given shape,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected