| 34 | } |
| 35 | |
| 36 | numpy::HeaderData ParseHeader(const std::string_view data) { |
| 37 | const auto numpy_magic = "\x93NUMPY"; |
| 38 | if (data.size() < 10 || data.substr(0, 6) != numpy_magic) { |
| 39 | DALI_FAIL("Got bad magic string for numpy header ", |
| 40 | to_hex_string(data.substr(0, std::min(6UL, data.size()))), ", expected ", |
| 41 | to_hex_string(numpy_magic)); |
| 42 | } else if (data[6] != 1) { |
| 43 | DALI_FAIL("Unsupported numpy file version. Only major version 1 is supported."); |
| 44 | } |
| 45 | |
| 46 | uint16_t header_len = 0; |
| 47 | std::memcpy(&header_len, &data[8], 2); |
| 48 | if (header_len + 10UL > data.size()) { |
| 49 | DALI_FAIL("Header length exceeds input size."); |
| 50 | } |
| 51 | |
| 52 | numpy::HeaderData header; |
| 53 | numpy::ParseHeaderContents(header, data.substr(10, header_len)); |
| 54 | header.data_offset = 10 + header_len; |
| 55 | |
| 56 | const auto expected_size = header.data_offset + header.nbytes(); |
| 57 | if (expected_size != data.size()) { |
| 58 | DALI_FAIL("Expected data numpy size ", expected_size, " bytes does not match the actual size ", |
| 59 | data.size(), " bytes."); |
| 60 | } |
| 61 | |
| 62 | return header; |
| 63 | } |
| 64 | |
| 65 | bool NumpyDecoder::SetupImpl(std::vector<OutputDesc> &output_desc, const Workspace &ws) { |
| 66 | const auto &input = ws.Input<CPUBackend>(0); |
no test coverage detected