| 1026 | |
| 1027 | template <typename T> |
| 1028 | void AssetsLibrary::fill_layer_data(T &&tensor, std::string name) const |
| 1029 | { |
| 1030 | #ifdef _WIN32 |
| 1031 | const std::string path_separator("\\"); |
| 1032 | #else /* _WIN32 */ |
| 1033 | const std::string path_separator("/"); |
| 1034 | #endif /* _WIN32 */ |
| 1035 | const std::string path = _library_path + path_separator + name; |
| 1036 | |
| 1037 | // Open file |
| 1038 | std::ifstream stream(path, std::ios::in | std::ios::binary); |
| 1039 | if (!stream.good()) |
| 1040 | { |
| 1041 | throw framework::FileNotFound("Could not load npy file: " + path); |
| 1042 | } |
| 1043 | |
| 1044 | validate_npy_header(stream, tensor.data_type(), tensor.shape()); |
| 1045 | |
| 1046 | // Read data |
| 1047 | if (tensor.padding().empty()) |
| 1048 | { |
| 1049 | // If tensor has no padding read directly from stream. |
| 1050 | stream.read(reinterpret_cast<char *>(tensor.data()), tensor.size()); |
| 1051 | } |
| 1052 | else |
| 1053 | { |
| 1054 | // If tensor has padding accessing tensor elements through execution window. |
| 1055 | Window window; |
| 1056 | window.use_tensor_dimensions(tensor.shape()); |
| 1057 | |
| 1058 | execute_window_loop(window, [&](const Coordinates &id) |
| 1059 | { stream.read(reinterpret_cast<char *>(tensor(id)), tensor.element_size()); }); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | template <typename T, typename D> |
| 1064 | void AssetsLibrary::fill_tensor_value(T &&tensor, D value) const |
nothing calls this directly
no test coverage detected