4.1.9. Shape¶
-
class
Shape
¶ Data structure to represent the shape of the node.
Examples: Shape() == Shape({1, 1, 1, …}, 1): scalar Shape({}) == Shape({1, 1, 1, …}, 1): scalar Shape({n}) == Shape({n, 1, 1, …}, 1): column vector Shape({n, m}) == Shape({n, m, 1, …}, 1): matrix Shape({…}, k): k-parallelized data (mini-batch)
Public Functions
-
Shape
(std::initializer_list<std::uint32_t> dims, std::uint32_t batch = 1)¶ Creates a new Shape object.
- Parameters
dims
: List of the dimension sizes.batch
: Batch size.
-
Shape
(const std::vector<std::uint32_t> &dims, std::uint32_t batch = 1)¶ Creates a new Shape object.
- Parameters
dims
: List of the dimension sizes.batch
: Batch size.
-
std::uint32_t
operator[]
(std::uint32_t i) const¶ Returns the size of the i-th dimension.
- Return
- Size of the i-th dimension.
- Parameters
i
: Dimension number to check.
-
const std::vector<std::uint32_t>
dims
() const¶ Returns the dimension array.
- Return
- Copy of the dimension array.
-
std::uint32_t
depth
() const¶ Returns the depth (length of non-1 dimensions) of the shape.
- Return
- The depth of the shape.
-
std::uint32_t
batch
() const¶ Returns the batch size.
- Return
- Batch size.
-
std::uint32_t
volume
() const¶ Returns the number of elements in each sample. This value is equal to the product of all dimensions.
- Return
- Number of elements.
-
std::uint32_t
lower_volume
(std::uint32_t dim) const¶ Returns the number of elements in 1 to specified dim.
- Return
dims[0] * dims[1] * ... * dims[dim-1]
- Parameters
dim
: Upper bound of the dimension.
-
std::uint32_t
size
() const¶ Returns the number of elements in all samples of the mini-batch. This value is equal to
batch() * volume()
.- Return
- Number of elements.
-
std::string
to_string
() const¶ Returns a string representation of the shape. The format is: “[n,m,…]xk”
- Return
- Encoded string.
-
bool
operator==
(const Shape &rhs) const¶ Compares this and other shape.
- Return
- true if this and rhs are same, false otherwise.
- Parameters
rhs
: Shape object to compare.
-
bool
operator!=
(const Shape &rhs) const¶ Compares this and other shape.
- Return
- true if this and rhs are not same, false otherwise.
- Parameters
rhs
: Shape object to compare.
-
bool
has_batch
() const¶ Checks whether the shape has minibatch or not.
- Return
- true if the shape has minibatch, false otherwise.
-
bool
has_compatible_batch
(const Shape &rhs) const¶ Checks whether two batch size is compatible (broadcastable) or not.
- Return
- true if both batch size is compatible, false otherwise.
- Parameters
rhs
: Shape object to compare.
-
bool
is_scalar
() const¶ Checks whether the shape is a scalar or not.
- Return
- true if the shape is a scalar, false otherwise.
-
bool
is_column_vector
() const¶ Checks whether the shape is a column vector or not.
- Return
- true if the shape is a column vector, false otherwise.
-
bool
is_matrix
() const¶ Checks whether the shape is a vector or a matrix, or not.
- Return
- true if the shape is a vector or a matrix, false otherwise.
-
bool
has_same_dims
(const Shape &rhs) const¶ Checks whether two shapes have completely same dimensions.
- Return
- true if both shape have same dimensions, false otherwise.
- Parameters
rhs
: Shape object to compare.
-
bool
has_same_loo_dims
(const Shape &rhs, std::uint32_t dim) const¶ Checks whether two shapes have same dimensions without an axis. (LOO: leave one out)
- Return
- true if both shape have same dimensions regardless the dimension
dim
, false otherwise. - Parameters
rhs
: Shape object to compare.dim
: Dimension to be ignored.
-
Shape
resize_dim
(std::uint32_t dim, std::uint32_t m) const¶ Creates a new shape which have one different dimension.
- Return
- New shape.
- Parameters
dim
: Dimension to be changed.m
: New size of the dimensiondim
.
-
Shape
resize_batch
(std::uint32_t batch) const¶ Creates a new shape which have specified batch size.
- Return
- New shape.
- Parameters
batch
: New batch size.
-
void
update_dim
(std::uint32_t dim, std::uint32_t m)¶ Directly updates a specified dimension.
- Parameters
dim
: Dimension to be updated.m
: New size of the dimensiondim
.
-
void
update_batch
(std::uint32_t batch)¶ Directly updates the batch size.
- Parameters
batch
: New batch size.
-