目录

DataFormatToFormat

Function Description

Converts a data character 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"

Function Prototype

static Format DataFormatToFormat(const AscendString &str);
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 ABIs 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.

Return Value

If the input is valid, the converted format enum value is returned. For details about the enum 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:

Calling Example

// (Recommended) If an API with the AscendString input parameter is used, run the following:
ge::AscendString format_str = "NHWC";
auto format = 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 = DataFormatToFormat(format_str); // 1