| 440 | } |
| 441 | |
| 442 | std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type, |
| 443 | std::string_view data, std::string_view shape, |
| 444 | std::string_view strides, |
| 445 | std::string_view dim_names) { |
| 446 | std::shared_ptr<Array> array = arrow::ArrayFromJSON(type, data); |
| 447 | |
| 448 | rj::Document json_shape; |
| 449 | json_shape.Parse(shape.data(), shape.length()); |
| 450 | std::vector<int64_t> shape_vector; |
| 451 | for (auto& x : json_shape.GetArray()) { |
| 452 | shape_vector.emplace_back(x.GetInt64()); |
| 453 | } |
| 454 | rj::Document json_strides; |
| 455 | json_strides.Parse(strides.data(), strides.length()); |
| 456 | std::vector<int64_t> strides_vector; |
| 457 | for (auto& x : json_strides.GetArray()) { |
| 458 | strides_vector.emplace_back(x.GetInt64()); |
| 459 | } |
| 460 | rj::Document json_dim_names; |
| 461 | json_dim_names.Parse(dim_names.data(), dim_names.length()); |
| 462 | std::vector<std::string> dim_names_vector; |
| 463 | for (auto& x : json_dim_names.GetArray()) { |
| 464 | dim_names_vector.emplace_back(x.GetString()); |
| 465 | } |
| 466 | return *Tensor::Make(type, array->data()->buffers[1], shape_vector, strides_vector, |
| 467 | dim_names_vector); |
| 468 | } |
| 469 | |
| 470 | std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type, |
| 471 | std::string_view data, |
no test coverage detected