| 450 | } |
| 451 | |
| 452 | void write_tensor_f32(const TensorValue & tensor, const float * values, size_t count) { |
| 453 | if (tensor.type != GGML_TYPE_F32) { |
| 454 | throw std::runtime_error("write_tensor_f32 requires GGML_TYPE_F32 tensor"); |
| 455 | } |
| 456 | if (tensor.shape.num_elements() != static_cast<int64_t>(count)) { |
| 457 | throw std::runtime_error( |
| 458 | "write_tensor_f32 value count does not match tensor shape for tensor '" + |
| 459 | std::string(tensor.tensor != nullptr ? tensor.tensor->name : "<null>") + |
| 460 | "': expected " + std::to_string(tensor.shape.num_elements()) + |
| 461 | ", got " + std::to_string(count)); |
| 462 | } |
| 463 | ggml_backend_tensor_set(tensor.tensor, values, 0, count * sizeof(float)); |
| 464 | } |
| 465 | |
| 466 | void write_tensor_f32_slice(const TensorValue & tensor, size_t element_offset, const float * values, size_t count) { |
| 467 | if (tensor.type != GGML_TYPE_F32) { |
| 468 | throw std::runtime_error("write_tensor_f32_slice requires GGML_TYPE_F32 tensor"); |
| 469 | } |
no test coverage detected