Open3D (C++ API)  0.18.0+5c982c7
Data Structures | Enumerations | Functions
open3d::ml::op_util Namespace Reference

Data Structures

class  DimValue
 Class for representing a possibly unknown dimension value. More...
 
class  Dim
 Class for dimensions for which the value should be inferred. More...
 
struct  DimXPlus
 
struct  DimXMinus
 
struct  DimXMultiply
 
struct  DimXDivide
 
struct  DimXOr
 
class  DimX
 Dim expression class. More...
 
struct  CountArgs
 

Enumerations

enum class  CSOpt {
  NONE = 0 , COMBINE_FIRST_DIMS , IGNORE_FIRST_DIMS , COMBINE_LAST_DIMS ,
  IGNORE_LAST_DIMS
}
 Check shape options. More...
 

Functions

DimValue UnknownValue ()
 
template<class TLeft , class TRight , class TOp >
bool operator== (DimValue a, DimX< TLeft, TRight, TOp > &&b)
 
bool operator== (DimValue a, Dim b)
 
template<class TLeft , class TRight , class TOp >
std::string GetString (DimX< TLeft, TRight, TOp > a, bool show_value=true)
 
std::string GetString (Dim a, bool show_value=true)
 
template<class TLeft , class TRight , class TOp >
int64_t GetValue (DimX< TLeft, TRight, TOp > a)
 
template<class TLeft , class TRight , class TOp >
int64_t GetValue (DimX< TLeft, TRight, TOp > a, int64_t unknown_dim_value)
 
int64_t GetValue (Dim a)
 
int64_t GetValue (Dim a, int64_t unknown_dim_value)
 
std::string CreateDimXString ()
 
template<class TDimX >
std::string CreateDimXString (TDimX dimex)
 
template<class TDimX , class... TArgs>
std::string CreateDimXString (TDimX dimex, TArgs... args)
 
template<class TDimX >
void CreateDimVector (std::vector< int64_t > &out, int64_t unknown_dim_value, TDimX dimex)
 
template<class TDimX , class... TArgs>
void CreateDimVector (std::vector< int64_t > &out, int64_t unknown_dim_value, TDimX dimex, TArgs... args)
 
template<class TDimX >
std::vector< int64_t > CreateDimVector (int64_t unknown_dim_value, TDimX dimex)
 
template<class TDimX , class... TArgs>
std::vector< int64_t > CreateDimVector (int64_t unknown_dim_value, TDimX dimex, TArgs... args)
 
template<class TLeft , class TRight , class TOp >
bool CheckDim (const DimValue &lhs, DimX< TLeft, TRight, TOp > &&rhs)
 
bool CheckDim (const DimValue &lhs, Dim d)
 
template<CSOpt Opt = CSOpt::NONE, class TDimX >
bool _CheckShape (const std::vector< DimValue > &shape, TDimX &&dimex)
 
template<CSOpt Opt = CSOpt::NONE, class TDimX , class... TArgs>
bool _CheckShape (const std::vector< DimValue > &shape, TDimX &&dimex, TArgs &&... args)
 
template<CSOpt Opt = CSOpt::NONE, class TDimX , class... TArgs>
std::tuple< bool, std::string > CheckShape (const std::vector< DimValue > &shape, TDimX &&dimex, TArgs &&... args)
 

Enumeration Type Documentation

◆ CSOpt

Check shape options.

Enumerator
NONE 
COMBINE_FIRST_DIMS 
IGNORE_FIRST_DIMS 
COMBINE_LAST_DIMS 
IGNORE_LAST_DIMS 

Function Documentation

◆ _CheckShape() [1/2]

template<CSOpt Opt = CSOpt::NONE, class TDimX >
bool open3d::ml::op_util::_CheckShape ( const std::vector< DimValue > &  shape,
TDimX &&  dimex 
)

◆ _CheckShape() [2/2]

template<CSOpt Opt = CSOpt::NONE, class TDimX , class... TArgs>
bool open3d::ml::op_util::_CheckShape ( const std::vector< DimValue > &  shape,
TDimX &&  dimex,
TArgs &&...  args 
)

◆ CheckDim() [1/2]

bool open3d::ml::op_util::CheckDim ( const DimValue lhs,
Dim  d 
)
inline

◆ CheckDim() [2/2]

template<class TLeft , class TRight , class TOp >
bool open3d::ml::op_util::CheckDim ( const DimValue lhs,
DimX< TLeft, TRight, TOp > &&  rhs 
)

◆ CheckShape()

template<CSOpt Opt = CSOpt::NONE, class TDimX , class... TArgs>
std::tuple<bool, std::string> open3d::ml::op_util::CheckShape ( const std::vector< DimValue > &  shape,
TDimX &&  dimex,
TArgs &&...  args 
)

Function for checking a shape with dim expressions. Usage example:

Dim depth("depth"); Dim height("height"); Dim width("width"); status = CheckShape({30,40}, height, width); // VALID, will assign values // to height and width

status = CheckShape({50,41}, height+20, width+1); // VALID, values match status = CheckShape({20,30,40}, depth+10, height, width); // VALID, will // assign 10 to depth

status = CheckShape({0},depth||0); // VALID, shape must match depth or 0 status = CheckShape({10}, depth||0); // VALID, shape must match depth or 0 status = CheckShape({123,10}, Dim(), depth); // VALID, first dim may be // anything

status = CheckShape<CSOpt::COMBINE_LAST_DIMS>({123,10,4}, Dim(), width); // VALID, width==40==10*4

status = CheckShape<CSOpt::COMBINE_FIRST_DIMS>( {10,2,2,123,456}, width, Dim(), Dim()); // VALID, width==40==10*2*2

status = CheckShape({70}, height+width); // VALID, works because height // and width have been initialized since the first call to CheckShape

status = CheckShape({1,2,3}, Dim(), Dim()); // INVALID, rank mismatch 3vs2 status = CheckShape({1,2,3}, depth, width, height); // INVALID, at least // one dim does not match

The options CSOpt::COMBINE_FIRST_DIMS and CSOpt::COMBINE_LAST_DIMS allow to match the rank of the dim expressions by combining the shape dimensions at the beginning or end. The options CSOpt::IGNORE_FIRST_DIMS and CSOpt::IGNORE_LAST_DIMS allow to ignore additional dimensions in the shape.

The shape to be checked may contain unknowns Dim A("A"); Dim B("B"); status = CheckShape({30, UnknownValue()}, A, B); // VALID, A is 30 and B // is still unknown

status = CheckShape<CSOpt::COMBINE_LAST_DIMS>({30,1,2,UnknownValue()},A,B); // VALID, A is 30 and B is still unknown

The following shows some limitations of the dim expressions Dim A("A"); Dim B("B"); status = CheckShape({30}, A+B); // THROWS EXCEPTION, illegal expression // because neither A or B is a constant

However, the following will work Dim A(20,"A"); Dim B("B"); status = CheckShape({30}, A+B); // VALID, B is now 10

This will work, too Dim A("A"); // uninitialized Dim B("B"); status = CheckShape({20}, A); // VALID, A is now 20 status = CheckShape({30}, A+B); // VALID, B is now 10

Multiplication and division are not allowed for unknown dims Dim A("A"); status = CheckShape({30}, 3*A); // THROWS EXCEPTION, although expression // seems reasonable status = CheckShape({20}, 3*A); // THROWS EXCEPTION, this // is the reason why mul/div is only allowed for known dims

Important, do not create objects of dim expressions, i.e., auto dimx = Dim("tmp") + 3; status = CheckShape({20}, dimx); // intended to not compile Assigning a value to dimx will assign a value to Dim("tmp") which has a shorter lifetime.

The return value is a tuple <bool,std::string>. If the bool is false then the shape is INVALID and the string contains an error message of the form "got [shape], expected [dim expressions]". If true then the shape is VALID and the error string is empty.

Note the goal of this function is to simplify checking tensor shapes. There may be cases where shapes cannot be checked with the provided functionality and you have to write custom shape checking code.

Parameters
shapeThis is the actual shape of an object.
argsThis is a list of dim expression

◆ CreateDimVector() [1/4]

template<class TDimX >
std::vector<int64_t> open3d::ml::op_util::CreateDimVector ( int64_t  unknown_dim_value,
TDimX  dimex 
)

◆ CreateDimVector() [2/4]

template<class TDimX , class... TArgs>
std::vector<int64_t> open3d::ml::op_util::CreateDimVector ( int64_t  unknown_dim_value,
TDimX  dimex,
TArgs...  args 
)

◆ CreateDimVector() [3/4]

template<class TDimX >
void open3d::ml::op_util::CreateDimVector ( std::vector< int64_t > &  out,
int64_t  unknown_dim_value,
TDimX  dimex 
)

◆ CreateDimVector() [4/4]

template<class TDimX , class... TArgs>
void open3d::ml::op_util::CreateDimVector ( std::vector< int64_t > &  out,
int64_t  unknown_dim_value,
TDimX  dimex,
TArgs...  args 
)

◆ CreateDimXString() [1/3]

std::string open3d::ml::op_util::CreateDimXString ( )
inline

◆ CreateDimXString() [2/3]

template<class TDimX >
std::string open3d::ml::op_util::CreateDimXString ( TDimX  dimex)

◆ CreateDimXString() [3/3]

template<class TDimX , class... TArgs>
std::string open3d::ml::op_util::CreateDimXString ( TDimX  dimex,
TArgs...  args 
)

◆ GetString() [1/2]

std::string open3d::ml::op_util::GetString ( Dim  a,
bool  show_value = true 
)
inline

◆ GetString() [2/2]

template<class TLeft , class TRight , class TOp >
std::string open3d::ml::op_util::GetString ( DimX< TLeft, TRight, TOp >  a,
bool  show_value = true 
)

◆ GetValue() [1/4]

int64_t open3d::ml::op_util::GetValue ( Dim  a)
inline

◆ GetValue() [2/4]

int64_t open3d::ml::op_util::GetValue ( Dim  a,
int64_t  unknown_dim_value 
)
inline

◆ GetValue() [3/4]

template<class TLeft , class TRight , class TOp >
int64_t open3d::ml::op_util::GetValue ( DimX< TLeft, TRight, TOp >  a)

◆ GetValue() [4/4]

template<class TLeft , class TRight , class TOp >
int64_t open3d::ml::op_util::GetValue ( DimX< TLeft, TRight, TOp >  a,
int64_t  unknown_dim_value 
)

◆ operator==() [1/2]

bool open3d::ml::op_util::operator== ( DimValue  a,
Dim  b 
)
inline

◆ operator==() [2/2]

template<class TLeft , class TRight , class TOp >
bool open3d::ml::op_util::operator== ( DimValue  a,
DimX< TLeft, TRight, TOp > &&  b 
)
inline

◆ UnknownValue()

DimValue open3d::ml::op_util::UnknownValue ( )
inline