| 417 | } |
| 418 | |
| 419 | void write_tensor_f32(const TensorValue & tensor, const float * values, size_t count) { |
| 420 | if (tensor.type != GGML_TYPE_F32) { |
| 421 | throw std::runtime_error("write_tensor_f32 requires GGML_TYPE_F32 tensor"); |
| 422 | } |
| 423 | if (tensor.shape.num_elements() != static_cast<int64_t>(count)) { |
| 424 | throw std::runtime_error( |
| 425 | "write_tensor_f32 value count does not match tensor shape for tensor '" + |
| 426 | std::string(tensor.tensor != nullptr ? tensor.tensor->name : "<null>") + |
| 427 | "': expected " + std::to_string(tensor.shape.num_elements()) + |
| 428 | ", got " + std::to_string(count)); |
| 429 | } |
| 430 | ggml_backend_tensor_set(tensor.tensor, values, 0, count * sizeof(float)); |
| 431 | } |
| 432 | |
| 433 | void write_tensor_f32_slice(const TensorValue & tensor, size_t element_offset, const float * values, size_t count) { |
| 434 | if (tensor.type != GGML_TYPE_F32) { |
no test coverage detected