DataFormatToFormat
Description
Converts a data string into a value of the Format type.
To use this API, the type_utils.h header file must be included.
#include "graph/utils/type_utils.h"
Prototype
static Format DataFormatToFormat(const AscendString &str)
static Format DataFormatToFormat(const std::string &str)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
str |
Input |
Format string to be converted. In GCC 5.1 and later versions, libstdc++ changes some APIs of std::string and std::list to better implement C++11 specifications. As a result, the ABI of the old and new versions are incompatible. Therefore, it is recommended that APIs whose input parameter is of the AscendString type should be used. |
Returns
If the input is valid, the Format enum value after conversion is returned. For details about the enumeration definition, see Format. Only some formats are supported. For details, see Restrictions. If the input is invalid, FORMAT_RESERVED is returned and an error message is printed.
Restrictions
Only the following formats are supported:
"NCHW": FORMAT_NCHW
"NHWC": FORMAT_NHWC
"NDHWC": FORMAT_NDHWC
"NCDHW": FORMAT_NCDHW
"ND": FORMAT_ND
Example
// (Recommended) If an API with the AscendString input parameter is used, run the following: ge::AscendString format_str = "NHWC"; auto format = ge::TypeUtils::DataFormatToFormat(format_str); // 1 // (Not recommended) If an API with the std:string input parameters is used, run the following: std::string format_str = "NHWC"; auto format = ge::TypeUtils::DataFormatToFormat(format_str); // 1