MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / splitNameAndValue

Function splitNameAndValue

samples/common/sampleOptions.cpp:166–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164
165template <typename T>
166std::pair<std::string, T> splitNameAndValue(const std::string& s)
167{
168 std::string tensorName;
169 std::string valueString;
170
171 // Support 'inputName':Path format for --loadInputs flag when dealing with Windows paths.
172 // i.e. 'inputName':c:\inputData
173 std::vector<std::string> quoteNameRange{ splitToStringVec(s, '\'') };
174 // splitToStringVec returns the entire string when delimiter is not found, so it's size is always at least 1
175 if (quoteNameRange.size() != 1)
176 {
177 if (quoteNameRange.size() != 3)
178 {
179 throw std::invalid_argument(std::string("Found invalid number of \'s when parsing ") + s +
180 std::string(". Expected: 2, received: ") + std::to_string(quoteNameRange.size() -1));
181 }
182 // Everything before the second "'" is the name.
183 tensorName = quoteNameRange[0] + quoteNameRange[1];
184 // Path is the last string - ignoring leading ":" so slice it with [1:]
185 valueString = quoteNameRange[2].substr(1);
186 return std::pair<std::string, T>(tensorName, stringToValue<T>(valueString));
187 }
188
189 // Split on the last :
190 std::vector<std::string> nameRange{splitToStringVec(s, ':')};
191 // Everything before the last : is the name
192 tensorName = nameRange[0];
193 for (size_t i = 1; i < nameRange.size() - 1; i++)
194 {
195 tensorName += ":" + nameRange[i];
196 }
197 // Value is the string element after the last :
198 valueString = nameRange[nameRange.size() - 1];
199 return std::pair<std::string, T>(tensorName, stringToValue<T>(valueString));
200}
201
202template <typename T>
203void splitInsertKeyValue(const std::vector<std::string>& kvList, T& map)

Callers

nothing calls this directly

Calls 2

splitToStringVecFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected