ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::ml::op_util Namespace Reference

Classes

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 ()
 
DimX< Dim, Dim, DimXPlusoperator+ (Dim a, Dim b)
 
template<class TL , class TR , class TOp >
DimX< Dim, DimX< TL, TR, TOp >, DimXPlusoperator+ (Dim a, DimX< TL, TR, TOp > &&b)
 
template<class TL , class TR , class TOp >
DimX< DimX< TL, TR, TOp >, Dim, DimXPlusoperator+ (DimX< TL, TR, TOp > &&a, Dim b)
 
template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX< DimX< TL1, TR1, TOp1 >, DimX< TL2, TR2, TOp2 >, DimXPlusoperator+ (DimX< TL1, TR1, TOp1 > &&a, DimX< TL2, TR2, TOp2 > &&b)
 
DimX< Dim, Dim, DimXMinusoperator- (Dim a, Dim b)
 
template<class TL , class TR , class TOp >
DimX< Dim, DimX< TL, TR, TOp >, DimXMinusoperator- (Dim a, DimX< TL, TR, TOp > &&b)
 
template<class TL , class TR , class TOp >
DimX< DimX< TL, TR, TOp >, Dim, DimXMinusoperator- (DimX< TL, TR, TOp > &&a, Dim b)
 
template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX< DimX< TL1, TR1, TOp1 >, DimX< TL2, TR2, TOp2 >, DimXMinusoperator- (DimX< TL1, TR1, TOp1 > &&a, DimX< TL2, TR2, TOp2 > &&b)
 
DimX< Dim, Dim, DimXMultiplyoperator* (Dim a, Dim b)
 
template<class TL , class TR , class TOp >
DimX< Dim, DimX< TL, TR, TOp >, DimXMultiplyoperator* (Dim a, DimX< TL, TR, TOp > &&b)
 
template<class TL , class TR , class TOp >
DimX< DimX< TL, TR, TOp >, Dim, DimXMultiplyoperator* (DimX< TL, TR, TOp > &&a, Dim b)
 
template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX< DimX< TL1, TR1, TOp1 >, DimX< TL2, TR2, TOp2 >, DimXMultiplyoperator* (DimX< TL1, TR1, TOp1 > &&a, DimX< TL2, TR2, TOp2 > &&b)
 
DimX< Dim, Dim, DimXDivideoperator/ (Dim a, Dim b)
 
template<class TL , class TR , class TOp >
DimX< Dim, DimX< TL, TR, TOp >, DimXDivideoperator/ (Dim a, DimX< TL, TR, TOp > &&b)
 
template<class TL , class TR , class TOp >
DimX< DimX< TL, TR, TOp >, Dim, DimXDivideoperator/ (DimX< TL, TR, TOp > &&a, Dim b)
 
template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX< DimX< TL1, TR1, TOp1 >, DimX< TL2, TR2, TOp2 >, DimXDivideoperator/ (DimX< TL1, TR1, TOp1 > &&a, DimX< TL2, TR2, TOp2 > &&b)
 
DimX< Dim, Dim, DimXOroperator|| (Dim a, Dim b)
 
template<class TL , class TR , class TOp >
DimX< Dim, DimX< TL, TR, TOp >, DimXOroperator|| (Dim a, DimX< TL, TR, TOp > &&b)
 
template<class TL , class TR , class TOp >
DimX< DimX< TL, TR, TOp >, Dim, DimXOroperator|| (DimX< TL, TR, TOp > &&a, Dim b)
 
template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX< DimX< TL1, TR1, TOp1 >, DimX< TL2, TR2, TOp2 >, DimXOroperator|| (DimX< TL1, TR1, TOp1 > &&a, DimX< TL2, TR2, TOp2 > &&b)
 
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 

Definition at line 405 of file ShapeChecking.h.

Function Documentation

◆ _CheckShape() [1/2]

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

Definition at line 414 of file ShapeChecking.h.

References CheckDim(), COMBINE_FIRST_DIMS, COMBINE_LAST_DIMS, IGNORE_FIRST_DIMS, and NONE.

◆ _CheckShape() [2/2]

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

Definition at line 446 of file ShapeChecking.h.

References CheckDim(), COMBINE_FIRST_DIMS, IGNORE_FIRST_DIMS, NONE, and offset.

◆ CheckDim() [1/2]

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

Definition at line 399 of file ShapeChecking.h.

◆ CheckDim() [2/2]

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

Definition at line 394 of file ShapeChecking.h.

Referenced by _CheckShape().

◆ CheckShape()

template<CSOpt Opt = CSOpt::NONE, class TDimX , class... TArgs>
std::tuple<bool, std::string> cloudViewer::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 cheked 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

Definition at line 574 of file ShapeChecking.h.

References COMBINE_FIRST_DIMS, COMBINE_LAST_DIMS, CreateDimXString(), GetString(), IGNORE_FIRST_DIMS, IGNORE_LAST_DIMS, NONE, and patch::to_string().

◆ CreateDimVector() [1/4]

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

Definition at line 374 of file ShapeChecking.h.

◆ CreateDimVector() [2/4]

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

Definition at line 381 of file ShapeChecking.h.

◆ CreateDimVector() [3/4]

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

Definition at line 358 of file ShapeChecking.h.

◆ CreateDimVector() [4/4]

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

Definition at line 365 of file ShapeChecking.h.

◆ CreateDimXString() [1/3]

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

Definition at line 345 of file ShapeChecking.h.

Referenced by CheckShape(), and CreateDimXString().

◆ CreateDimXString() [2/3]

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

Definition at line 348 of file ShapeChecking.h.

References GetString().

◆ CreateDimXString() [3/3]

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

Definition at line 353 of file ShapeChecking.h.

References CreateDimXString(), and GetString().

◆ GetString() [1/2]

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

Definition at line 316 of file ShapeChecking.h.

References cloudViewer::ml::op_util::Dim::ToString().

◆ GetString() [2/2]

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

◆ GetValue() [1/4]

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

Definition at line 335 of file ShapeChecking.h.

References cloudViewer::ml::op_util::Dim::value().

◆ GetValue() [2/4]

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

◆ GetValue() [3/4]

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

◆ GetValue() [4/4]

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

◆ operator*() [1/4]

DimX<Dim, Dim, DimXMultiply > cloudViewer::ml::op_util::operator* ( Dim  a,
Dim  b 
)
inline

Definition at line 276 of file ShapeChecking.h.

◆ operator*() [2/4]

template<class TL , class TR , class TOp >
DimX<Dim, DimX<TL, TR, TOp>, DimXMultiply > cloudViewer::ml::op_util::operator* ( Dim  a,
DimX< TL, TR, TOp > &&  b 
)
inline

Definition at line 276 of file ShapeChecking.h.

◆ operator*() [3/4]

template<class TL , class TR , class TOp >
DimX<DimX<TL, TR, TOp>, Dim, DimXMultiply > cloudViewer::ml::op_util::operator* ( DimX< TL, TR, TOp > &&  a,
Dim  b 
)
inline

Definition at line 276 of file ShapeChecking.h.

◆ operator*() [4/4]

template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX<DimX<TL1, TR1, TOp1>, DimX<TL2, TR2, TOp2>, DimXMultiply > cloudViewer::ml::op_util::operator* ( DimX< TL1, TR1, TOp1 > &&  a,
DimX< TL2, TR2, TOp2 > &&  b 
)
inline

Definition at line 276 of file ShapeChecking.h.

◆ operator+() [1/4]

DimX<Dim, Dim, DimXPlus > cloudViewer::ml::op_util::operator+ ( Dim  a,
Dim  b 
)
inline

Definition at line 274 of file ShapeChecking.h.

◆ operator+() [2/4]

template<class TL , class TR , class TOp >
DimX<Dim, DimX<TL, TR, TOp>, DimXPlus > cloudViewer::ml::op_util::operator+ ( Dim  a,
DimX< TL, TR, TOp > &&  b 
)
inline

Definition at line 274 of file ShapeChecking.h.

◆ operator+() [3/4]

template<class TL , class TR , class TOp >
DimX<DimX<TL, TR, TOp>, Dim, DimXPlus > cloudViewer::ml::op_util::operator+ ( DimX< TL, TR, TOp > &&  a,
Dim  b 
)
inline

Definition at line 274 of file ShapeChecking.h.

◆ operator+() [4/4]

template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX<DimX<TL1, TR1, TOp1>, DimX<TL2, TR2, TOp2>, DimXPlus > cloudViewer::ml::op_util::operator+ ( DimX< TL1, TR1, TOp1 > &&  a,
DimX< TL2, TR2, TOp2 > &&  b 
)
inline

Definition at line 274 of file ShapeChecking.h.

◆ operator-() [1/4]

DimX<Dim, Dim, DimXMinus > cloudViewer::ml::op_util::operator- ( Dim  a,
Dim  b 
)
inline

Definition at line 275 of file ShapeChecking.h.

◆ operator-() [2/4]

template<class TL , class TR , class TOp >
DimX<Dim, DimX<TL, TR, TOp>, DimXMinus > cloudViewer::ml::op_util::operator- ( Dim  a,
DimX< TL, TR, TOp > &&  b 
)
inline

Definition at line 275 of file ShapeChecking.h.

◆ operator-() [3/4]

template<class TL , class TR , class TOp >
DimX<DimX<TL, TR, TOp>, Dim, DimXMinus > cloudViewer::ml::op_util::operator- ( DimX< TL, TR, TOp > &&  a,
Dim  b 
)
inline

Definition at line 275 of file ShapeChecking.h.

◆ operator-() [4/4]

template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX<DimX<TL1, TR1, TOp1>, DimX<TL2, TR2, TOp2>, DimXMinus > cloudViewer::ml::op_util::operator- ( DimX< TL1, TR1, TOp1 > &&  a,
DimX< TL2, TR2, TOp2 > &&  b 
)
inline

Definition at line 275 of file ShapeChecking.h.

◆ operator/() [1/4]

DimX<Dim, Dim, DimXDivide > cloudViewer::ml::op_util::operator/ ( Dim  a,
Dim  b 
)
inline

Definition at line 277 of file ShapeChecking.h.

◆ operator/() [2/4]

template<class TL , class TR , class TOp >
DimX<Dim, DimX<TL, TR, TOp>, DimXDivide > cloudViewer::ml::op_util::operator/ ( Dim  a,
DimX< TL, TR, TOp > &&  b 
)
inline

Definition at line 277 of file ShapeChecking.h.

◆ operator/() [3/4]

template<class TL , class TR , class TOp >
DimX<DimX<TL, TR, TOp>, Dim, DimXDivide > cloudViewer::ml::op_util::operator/ ( DimX< TL, TR, TOp > &&  a,
Dim  b 
)
inline

Definition at line 277 of file ShapeChecking.h.

◆ operator/() [4/4]

template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX<DimX<TL1, TR1, TOp1>, DimX<TL2, TR2, TOp2>, DimXDivide > cloudViewer::ml::op_util::operator/ ( DimX< TL1, TR1, TOp1 > &&  a,
DimX< TL2, TR2, TOp2 > &&  b 
)
inline

Definition at line 277 of file ShapeChecking.h.

◆ operator==() [1/2]

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

◆ operator==() [2/2]

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

◆ operator||() [1/4]

DimX<Dim, Dim, DimXOr > cloudViewer::ml::op_util::operator|| ( Dim  a,
Dim  b 
)
inline

Definition at line 278 of file ShapeChecking.h.

◆ operator||() [2/4]

template<class TL , class TR , class TOp >
DimX<Dim, DimX<TL, TR, TOp>, DimXOr > cloudViewer::ml::op_util::operator|| ( Dim  a,
DimX< TL, TR, TOp > &&  b 
)
inline

Definition at line 278 of file ShapeChecking.h.

◆ operator||() [3/4]

template<class TL , class TR , class TOp >
DimX<DimX<TL, TR, TOp>, Dim, DimXOr > cloudViewer::ml::op_util::operator|| ( DimX< TL, TR, TOp > &&  a,
Dim  b 
)
inline

Definition at line 278 of file ShapeChecking.h.

◆ operator||() [4/4]

template<class TL1 , class TR1 , class TOp1 , class TL2 , class TR2 , class TOp2 >
DimX<DimX<TL1, TR1, TOp1>, DimX<TL2, TR2, TOp2>, DimXOr > cloudViewer::ml::op_util::operator|| ( DimX< TL1, TR1, TOp1 > &&  a,
DimX< TL2, TR2, TOp2 > &&  b 
)
inline

Definition at line 278 of file ShapeChecking.h.

◆ UnknownValue()

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

Definition at line 47 of file ShapeChecking.h.