| 125 | } |
| 126 | |
| 127 | std::vector<size_t> parseShape(String shape_string) |
| 128 | { |
| 129 | if (!shape_string.starts_with('(') || !shape_string.ends_with(')')) |
| 130 | throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect shape format: {}", shape_string); |
| 131 | std::vector<std::string> result_str; |
| 132 | boost::split(result_str, std::string_view(shape_string.data() + 1, shape_string.size() - 2), boost::is_any_of(",")); |
| 133 | |
| 134 | std::vector<size_t> shape; |
| 135 | if (result_str[result_str.size()-1].empty()) |
| 136 | result_str.pop_back(); |
| 137 | if (result_str.empty()) |
| 138 | throw Exception(ErrorCodes::INCORRECT_DATA, "Npy shape must have at least one dimension, got: {}", shape_string); |
| 139 | |
| 140 | shape.reserve(result_str.size()); |
| 141 | for (const String & item : result_str) |
| 142 | { |
| 143 | ReadBufferFromString buf(item); |
| 144 | skipWhitespaceIfAny(buf); |
| 145 | /// Reject negative values before parsing as unsigned. |
| 146 | if (!buf.eof() && *buf.position() == '-') |
| 147 | throw Exception(ErrorCodes::INCORRECT_DATA, "Negative shape dimension in shape {}", shape_string); |
| 148 | size_t value = 0; |
| 149 | if (!tryReadIntText(value, buf)) |
| 150 | throw Exception(ErrorCodes::INCORRECT_DATA, "Invalid shape format: {}", shape_string); |
| 151 | shape.push_back(value); |
| 152 | } |
| 153 | return shape; |
| 154 | } |
| 155 | |
| 156 | NumpyHeader parseHeader(ReadBuffer &buf) |
| 157 | { |
no test coverage detected