Struct Shape

Struct Documentation

struct Shape

Shape class mainly defines the shape or dimensionality of the node.

Basically, Shape is a wrapper of a std::vector. Its size is the number of dimension. E.g., shape={2,3} means 2D matrix with dim[0]=2 and dim[1]=3. WHen the index is negative, the real index is size() + index. It implements most common functions demanded by operations, e.g., resize(), slice(), and broadcast().

Public Functions

Shape()
Shape(std::initializer_list<int> il)
Shape(std::vector<int> &&shape)
Shape(const Shape &shape)
Shape &operator=(const Shape &p)
size_t size() const
void resize(size_t n)
const int *data() const
int *data()
void set(int i, int val)
void set(size_t i, int val)
void set(int i, size_t val)
void set(size_t i, size_t val)
int &dim(int i)
const int &dim(int i) const
int &dim(size_t i)
const int &dim(size_t i) const
int operator[](int i) const
int operator[](int i)
int operator[](size_t i) const
int operator[](size_t i)
int back() const
int &back()
int stride(int i) const
template<typename T = int>
T elements() const
void dims(int i, std::vector<int> &d) const
auto begin()
auto begin() const
auto end()
auto end() const
auto rbegin()
auto rbegin() const
auto rend()
auto rend() const
bool operator==(const Shape &other) const
bool operator!=(const Shape &other) const
std::string toString() const
operator std::string() const
int axis(int ax) const
Slice slice(Slice slice, int ax) const
size_t hash() const

Public Static Functions

static Shape broadcast(const std::vector<Shape> &shapes)
template<typename T>
static Shape broadcast(const std::initializer_list<T> &il)
template<typename T>
static Shape broadcast(const std::vector<T> &nodes)

Friends

std::ostream &operator<<(std::ostream &strm, const Shape &shape)