| 297 | } |
| 298 | |
| 299 | Tensor<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 |