| 113 | } |
| 114 | |
| 115 | inline version_t read_magic(std::istream &istream) { |
| 116 | char buf[magic_string_length + 2]; |
| 117 | istream.read(buf, magic_string_length + 2); |
| 118 | |
| 119 | if (!istream) { |
| 120 | throw std::runtime_error("io error: failed reading file"); |
| 121 | } |
| 122 | |
| 123 | if (0 != std::memcmp(buf, magic_string, magic_string_length)) |
| 124 | throw std::runtime_error("this file does not have a valid npy format."); |
| 125 | |
| 126 | version_t version; |
| 127 | version.first = buf[magic_string_length]; |
| 128 | version.second = buf[magic_string_length + 1]; |
| 129 | |
| 130 | return version; |
| 131 | } |
| 132 | |
| 133 | const std::unordered_map<std::type_index, dtype_t> dtype_map = { |
| 134 | {std::type_index(typeid(float)), {host_endian_char, 'f', sizeof(float)}}, |