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

Function TensorFromJSON

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

Source from the content-addressed store, hash-verified

440}
441
442std::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
470std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
471 std::string_view data,

Callers 7

TEST_FFunction · 0.85
TYPED_TEST_PFunction · 0.85
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