MCPcopy Create free account
hub / github.com/NVIDIA/DALI / ParseHeader

Function ParseHeader

dali/util/numpy.cc:250–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250void ParseHeader(HeaderData &parsed_header, InputStream *src) {
251 // check if the file is actually a numpy file
252 SmallVector<char, 128> token;
253 int64_t nread = src->Read(token.data(), 10);
254 DALI_ENFORCE(nread == 10, "Can not read header.");
255 token[nread] = '\0';
256
257 CheckNpyVersion(token.data());
258 auto header_len = GetHeaderLen(token.data());
259
260 // read header: the offset is a magic number
261 int64_t offset = 6 + 1 + 1 + 2;
262 // The header_len can have up to 2**16 - 1 bytes. We do not support V2 headers
263 // (with up to 4GB - 4 byte header len), as those are used by numpy to save structured
264 // arrays (where dtype can be different for each column and the columns have arbitrary names).
265 // Parsing such a dtype in the header will fail.
266 // https://numpy.org/neps/nep-0001-npy-format.html
267 token.resize(header_len+1);
268 src->SeekRead(offset);
269 nread = src->Read(token.data(), header_len);
270 DALI_ENFORCE(nread == static_cast<Index>(header_len), "Can not read header.");
271 token[header_len] = '\0';
272
273 ParseHeaderItself(parsed_header, token.data(), header_len);
274}
275
276void FromFortranOrder(SampleView<CPUBackend> output, ConstSampleView<CPUBackend> input) {
277 int n_dims = input.shape().sample_dim();

Callers 1

ReadTensorFunction · 0.70

Calls 7

CheckNpyVersionFunction · 0.85
GetHeaderLenFunction · 0.85
ParseHeaderItselfFunction · 0.85
ReadMethod · 0.45
dataMethod · 0.45
resizeMethod · 0.45
SeekReadMethod · 0.45

Tested by

no test coverage detected