| 142 | return static_cast<int>(rank) - 1 - logical_axis; |
| 143 | } |
| 144 | |
| 145 | TensorValue wrap_tensor(ggml_tensor * tensor, const TensorShape & shape, ggml_type type) { |
| 146 | if (tensor == nullptr) { |
| 147 | throw std::runtime_error("Cannot wrap null ggml tensor"); |
| 148 | } |
| 149 | |
| 150 | ensure_positive_dims(shape); |
| 151 | const auto ggml_dims = to_ggml_dims(shape); |
| 152 | for (size_t i = 0; i < shape.rank; ++i) { |
| 153 | if (tensor->ne[i] != ggml_dims[i]) { |
| 154 | throw std::runtime_error("Wrapped ggml tensor shape does not match logical shape " + shape.to_string()); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return TensorValue{tensor, shape, type}; |
| 159 | } |
| 160 | |
| 161 | TensorValue reshape_tensor(ModuleBuildContext & ctx, const TensorValue & value, const TensorShape & new_shape) { |