CanCast

Description

Checks whether a source type can be cast to a destination type.

Prototype

bool CanCast(const ge::DataType from, const ge::DataType to)

Parameters

Parameter

Input/Output

Description

from

Input

Source type.

to

Input

Destination type.

Return Value

true: cast successfully; false: otherwise.

Constraints

None

Example

1
2
3
4
5
6
// If dtype cannot be cast to int8 type, a return statement is executed.
void Func(const DataType dtype) {
    if (!CanCast(dtype, DT_INT8)) {
        return;
    }
}