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

Function ReadTensor

dali/util/numpy.cc:299–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297}
298
299Tensor<CPUBackend> ReadTensor(InputStream *src, bool pinned) {
300 numpy::HeaderData header;
301 numpy::ParseHeader(header, src);
302 src->SeekRead(header.data_offset, SEEK_SET);
303
304 Tensor<CPUBackend> data;
305 data.set_pinned(pinned);
306 data.Resize(header.shape, header.type());
307 auto ret = src->Read(static_cast<uint8_t*>(data.raw_mutable_data()), header.nbytes());
308 DALI_ENFORCE(ret == header.nbytes(), "Failed to read numpy file");
309
310 if (header.fortran_order) {
311 Tensor<CPUBackend> transposed;
312 transposed.Resize(data.shape(), data.type());
313 SampleView<CPUBackend> input(data.raw_mutable_data(), data.shape(), data.type());
314 SampleView<CPUBackend> output(transposed.raw_mutable_data(), transposed.shape(),
315 transposed.type());
316 numpy::FromFortranOrder(output, input);
317 return transposed;
318 }
319 return data;
320}
321
322} // namespace numpy
323} // namespace dali

Callers 1

ReadReferenceFunction · 0.85

Calls 10

FromFortranOrderFunction · 0.85
set_pinnedMethod · 0.80
ParseHeaderFunction · 0.70
SeekReadMethod · 0.45
ResizeMethod · 0.45
typeMethod · 0.45
ReadMethod · 0.45
raw_mutable_dataMethod · 0.45
nbytesMethod · 0.45
shapeMethod · 0.45

Tested by 1

ReadReferenceFunction · 0.68