mxnet
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
nnvm::Layout Class Reference

#include <layout.h>

Collaboration diagram for nnvm::Layout:
Collaboration graph

Public Types

using LayoutDim = char
 
using iterator = std::vector< LayoutDim >::const_iterator
 
using reverse_iterator = std::vector< LayoutDim >::const_reverse_iterator
 

Public Member Functions

 Layout ()
 default constructor More...
 
 Layout (const std::string &layout)
 construct from a string. More...
 
 Layout (const Layout &s)
 copy constructor from another layout More...
 
 Layout (Layout &&src)
 move constructor from Layout More...
 
Layoutoperator= (const Layout &src)
 assignment from another layout. More...
 
Layoutoperator= (Layout &&src)
 assignment from rvalue of another layout. More...
 
Layoutoperator= (const std::string &src)
 assignment from string. More...
 
bool operator== (const Layout &s) const
 
bool operator!= (const Layout &s) const
 
Layout operator+ (const Layout &other) const
 Append the current layout by another. More...
 
void swap (Layout &other)
 Swap current object with other. More...
 
bool convertible (const Layout &dst) const
 Two layouts are convertible only if they have same set of super-dimensions. e.g., NCHW, NCHW16c, NHWC are convertible between each other, but NCHW, CHW, OIHW are not. More...
 
Layout sublayout (size_t pos, size_t len) const
 Returns a sublayout which is the portion of the object that starts at dimension pos and spans len dimensions (or until the end of the layout, whichever comes first). More...
 
Layout reverse () const
 
Layout split (LayoutDim dim, size_t target_pos, uint32_t size) const
 Split dim by size and put the sub-dimension to position target_pos. More...
 
iterator begin () const
 
iterator end () const
 
reverse_iterator rbegin () const
 
reverse_iterator rend () const
 
size_t ndim () const
 
std::string at (size_t i) const
 The description of the i-th dimension. If it is a sub-dimension, the size will be returned as well, e.g., 16c. Otherwise a single character is returned, e.g., C. More...
 
int32_t indexof (LayoutDim dim) const
 return the index of the input dimension. If it is not found in the layout or the layout is undefined, return -1. More...
 
int64_t subsizeof (LayoutDim dim) const
 
bool contains (LayoutDim dim) const
 Whether the layout contains a dimension. More...
 
LayoutDim operator[] (size_t i) const
 
bool defined () const
 
const std::string & name () const
 
void Save (dmlc::JSONWriter *writer) const
 Write layout in JSON format. More...
 
void Load (dmlc::JSONReader *reader)
 Load layout from JSON. More...
 

Static Public Member Functions

static bool is_superdim (LayoutDim dim)
 Check whether a given dimension is a super-dimension. More...
 
static bool is_subdim (LayoutDim dim)
 Check whether a given dimension is a sub-dimension. More...
 
static LayoutDim to_superdim (LayoutDim dim)
 Convert a given dimension to super-dimension. More...
 
static LayoutDim to_subdim (LayoutDim dim)
 Convert a given dimension to sub-dimension. More...
 
static const LayoutUndef ()
 Return an undefined layout. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Layout &l)
 allow output string of layout to ostream More...
 

Member Typedef Documentation

using nnvm::Layout::iterator = std::vector<LayoutDim>::const_iterator
using nnvm::Layout::reverse_iterator = std::vector<LayoutDim>::const_reverse_iterator

Constructor & Destructor Documentation

nnvm::Layout::Layout ( )
inline

default constructor

nnvm::Layout::Layout ( const std::string &  layout)
inline

construct from a string.

Parameters
layoutinput in layout convention: upper case indicates a dimension and the corresponding lower case with factor size indicates the split dimension. return undefined layout if "__undef__" is passed.
nnvm::Layout::Layout ( const Layout s)
inline

copy constructor from another layout

Parameters
sthe source layout
nnvm::Layout::Layout ( Layout &&  src)
inline

move constructor from Layout

Parameters
srcthe source layout

Member Function Documentation

std::string nnvm::Layout::at ( size_t  i) const
inline

The description of the i-th dimension. If it is a sub-dimension, the size will be returned as well, e.g., 16c. Otherwise a single character is returned, e.g., C.

Parameters
iThe position
Returns
the description of the dimension.
iterator nnvm::Layout::begin ( ) const
inline
Returns
begin iterator
bool nnvm::Layout::contains ( LayoutDim  dim) const
inline

Whether the layout contains a dimension.

Parameters
dimdimension to be checked.
Returns
Whether the layout contains the dimension.
bool nnvm::Layout::convertible ( const Layout dst) const
inline

Two layouts are convertible only if they have same set of super-dimensions. e.g., NCHW, NCHW16c, NHWC are convertible between each other, but NCHW, CHW, OIHW are not.

Parameters
dstthe target layout
Returns
Whether can be converted to dst layout.
bool nnvm::Layout::defined ( ) const
inline
Returns
whether the layout is defined
iterator nnvm::Layout::end ( ) const
inline
Returns
end iterator
int32_t nnvm::Layout::indexof ( LayoutDim  dim) const
inline

return the index of the input dimension. If it is not found in the layout or the layout is undefined, return -1.

Parameters
dimthe input dimension.
Returns
the index or -1 if not found.
static bool nnvm::Layout::is_subdim ( LayoutDim  dim)
inlinestatic

Check whether a given dimension is a sub-dimension.

Parameters
diminput dimension
Returns
Whether a given dimension is a sub-dimension.
static bool nnvm::Layout::is_superdim ( LayoutDim  dim)
inlinestatic

Check whether a given dimension is a super-dimension.

Parameters
diminput dimension
Returns
Whether a given dimension is a super-dimension.
void nnvm::Layout::Load ( dmlc::JSONReader reader)
inline

Load layout from JSON.

Parameters
readerJSONReader
const std::string& nnvm::Layout::name ( ) const
inline
Returns
the string description of the layout
size_t nnvm::Layout::ndim ( void  ) const
inline
Returns
number of dimensions
bool nnvm::Layout::operator!= ( const Layout s) const
inline
Returns
whether two layout not equal
Parameters
sthe layout to compare against
Layout nnvm::Layout::operator+ ( const Layout other) const
inline

Append the current layout by another.

Parameters
otherthe layout to be appended
Returns
a new layout
Layout& nnvm::Layout::operator= ( const Layout src)
inline

assignment from another layout.

Parameters
srcsource layout
Returns
reference of self
Layout& nnvm::Layout::operator= ( Layout &&  src)
inline

assignment from rvalue of another layout.

Parameters
srcsource layout
Returns
reference of self
Layout& nnvm::Layout::operator= ( const std::string &  src)
inline

assignment from string.

Parameters
srcsource layout
Returns
reference of self
bool nnvm::Layout::operator== ( const Layout s) const
inline
Returns
whether two layout equals
Parameters
sthe layout to compare against
LayoutDim nnvm::Layout::operator[] ( size_t  i) const
inline
reverse_iterator nnvm::Layout::rbegin ( ) const
inline
Returns
rbegin iterator
reverse_iterator nnvm::Layout::rend ( ) const
inline
Returns
rend iterator
Layout nnvm::Layout::reverse ( ) const
inline
Returns
A newly constructed reversed Layout object.
void nnvm::Layout::Save ( dmlc::JSONWriter writer) const
inline

Write layout in JSON format.

Parameters
writerJSONWriter
Layout nnvm::Layout::split ( LayoutDim  dim,
size_t  target_pos,
uint32_t  size 
) const
inline

Split dim by size and put the sub-dimension to position target_pos.

Parameters
dimThe source dimension to be split. It must be a super-dimension.
target_posThe target position of the newly split sub-dimension.
sizesize of the sub-dimension.
Returns
A newly constructed Layout object.
Layout nnvm::Layout::sublayout ( size_t  pos,
size_t  len 
) const
inline

Returns a sublayout which is the portion of the object that starts at dimension pos and spans len dimensions (or until the end of the layout, whichever comes first).

Parameters
posThe start position.
lenThe length of the sub-layout.
Returns
A newly constructed Layout object.
int64_t nnvm::Layout::subsizeof ( LayoutDim  dim) const
inline
Parameters
dimthe input super-dimension or sub-dimension.
Returns
the size of the sub-dimension of dim (if dim is a super-dimension), or the size of dim itself (if dim is a sub-dimension). Return -1 if dim is not in the layout or the layout is undefined.
void nnvm::Layout::swap ( Layout other)
inline

Swap current object with other.

Parameters
otheranother object to be swapped.
static LayoutDim nnvm::Layout::to_subdim ( LayoutDim  dim)
inlinestatic

Convert a given dimension to sub-dimension.

Parameters
diminput dimension
Returns
The converted description.
static LayoutDim nnvm::Layout::to_superdim ( LayoutDim  dim)
inlinestatic

Convert a given dimension to super-dimension.

Parameters
diminput dimension
Returns
The converted description.
static const Layout& nnvm::Layout::Undef ( )
inlinestatic

Return an undefined layout.

Returns
a (global) undefined layout.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Layout l 
)
friend

allow output string of layout to ostream

Parameters
osthe output stream
lthe layout
Returns
the ostream

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