ToString
Description
Serializes a group of data types into a string. An empty list returns "[]". For a non-empty initializer_list, a string in the format of "[DT_FLOAT,DT_INT8,]" is returned, with each element followed by a comma (including the trailing comma). For a non-empty array or vector, a string in the format of "[DT_FLOAT,DT_INT8]" is returned, with elements separated by commas and no trailing comma.
Prototype
ge::AscendString ToString(const std::initializer_list<DataType>& dataTypes) template <size_t N> ge::AscendString ToString(const std::array<DataType, N>& dataTypes) ge::AscendString ToString(const std::vector<DataType>& dataTypes)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
dataTypes |
Input |
List of data types to serialize. The type is std::initializer_list<DataType>, std::array<DataType, N>, or std::vector<DataType>. |
Return Value
Returns the serialized string of ge::AscendString type. An empty list returns "[]". The output formats of non-empty lists vary in different versions:
- initializer_list: "[DT_FLOAT,DT_INT8,]" is returned, with each element followed by a comma (including the trailing comma).
- array and vector: "[DT_FLOAT,DT_INT8]" is returned. Elements are separated by commas (,) without a trailing comma.
The output format of the array/vector type is different from that of the initializer_list type, which is a design decision. The new overload corrects the trailing comma, and the initializer_list type retains the original format to avoid damaging existing logs.
Constraints
None
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Serialize a group of data types into a string and print the string. void Func() { ge::AscendString typeStr = ToString({DT_FLOAT, DT_INT8}); // typeStr: "[DT_FLOAT,DT_INT8,]" } // Use std::array or std::vector for serialization (no trailing comma). void FuncContainer() { ge::AscendString arrStr = ToString(std::array<ge::DataType, 2>{DT_FLOAT, DT_INT8}); // arrStr: "[DT_FLOAT,DT_INT8]" ge::AscendString vecStr = ToString(std::vector<ge::DataType>{DT_FLOAT, DT_INT8}); // vecStr: "[DT_FLOAT,DT_INT8]" } |