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

Function TensorFromJSON

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

Source from the content-addressed store, hash-verified

436}
437
438std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
439 std::string_view data, std::string_view shape,
440 std::string_view strides,
441 std::string_view dim_names) {
442 std::shared_ptr<Array> array = arrow::ArrayFromJSON(type, data);
443
444 simdjson::dom::parser parser;
445
446 auto json_shape =
447 internal::ResolveSimdjsonResult(parser.parse(shape), "Failed to parse shape")
448 .ValueOrDie();
449 auto shape_vector = internal::GetJsonIntArray(json_shape, "shape").ValueOrDie();
450
451 auto json_strides =
452 internal::ResolveSimdjsonResult(parser.parse(strides), "Failed to parse strides")
453 .ValueOrDie();
454 auto strides_vector = internal::GetJsonIntArray(json_strides, "strides").ValueOrDie();
455
456 auto json_dim_names = internal::ResolveSimdjsonResult(parser.parse(dim_names),
457 "Failed to parse dimension names")
458 .ValueOrDie();
459 auto dim_names_vector =
460 internal::GetJsonStringArray(json_dim_names, "dimension names").ValueOrDie();
461
462 return *Tensor::Make(type, array->data()->buffers[1], shape_vector, strides_vector,
463 dim_names_vector);
464}
465
466std::shared_ptr<Tensor> TensorFromJSON(const std::shared_ptr<DataType>& type,
467 std::string_view data,

Callers 8

TEST_FFunction · 0.85
TYPED_TEST_PFunction · 0.85
TEST_FFunction · 0.85
TYPED_TEST_PFunction · 0.85
TYPED_TESTFunction · 0.85
TESTFunction · 0.85
TEST_FFunction · 0.85
TEST_FFunction · 0.85

Calls 7

ArrayFromJSONFunction · 0.85
ResolveSimdjsonResultFunction · 0.85
GetJsonIntArrayFunction · 0.85
ValueOrDieMethod · 0.80
MakeFunction · 0.50
parseMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected