MCPcopy Create free account
hub / github.com/apache/arrow / TensorFromJSON

Function TensorFromJSON

cpp/src/arrow/testing/gtest_util.cc:434–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432}
433
434std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
435 std::string_view data, std::string_view shape,
436 std::string_view strides,
437 std::string_view dim_names) {
438 std::shared_ptr<Array> array = arrow::ArrayFromJSON(type, data);
439
440 rj::Document json_shape;
441 json_shape.Parse(shape.data(), shape.length());
442 std::vector<int64_t> shape_vector;
443 for (auto& x : json_shape.GetArray()) {
444 shape_vector.emplace_back(x.GetInt64());
445 }
446 rj::Document json_strides;
447 json_strides.Parse(strides.data(), strides.length());
448 std::vector<int64_t> strides_vector;
449 for (auto& x : json_strides.GetArray()) {
450 strides_vector.emplace_back(x.GetInt64());
451 }
452 rj::Document json_dim_names;
453 json_dim_names.Parse(dim_names.data(), dim_names.length());
454 std::vector<std::string> dim_names_vector;
455 for (auto& x : json_dim_names.GetArray()) {
456 dim_names_vector.emplace_back(x.GetString());
457 }
458 return *Tensor::Make(type, array->data()->buffers[1], shape_vector, strides_vector,
459 dim_names_vector);
460}
461
462std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
463 std::string_view data,

Callers 5

TEST_FFunction · 0.85
TYPED_TEST_PFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls 8

ArrayFromJSONFunction · 0.85
emplace_backMethod · 0.80
MakeFunction · 0.50
ParseMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
GetArrayMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected