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

Function TableToTensorSimple

cpp/src/arrow/tensor_benchmark.cc:56–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54
55template <typename ValueType, bool row_major>
56static void TableToTensorSimple(benchmark::State& state) {
57 using CType = typename ValueType::c_type;
58 std::shared_ptr<DataType> ty = TypeTraits<ValueType>::type_singleton();
59
60 const int64_t num_cols = state.range(1);
61 const int64_t num_rows = state.range(0) / num_cols / sizeof(CType);
62 arrow::random::RandomArrayGenerator gen_{42};
63
64 std::vector<std::shared_ptr<Field>> fields = {};
65 std::vector<std::shared_ptr<ChunkedArray>> columns = {};
66
67 for (int64_t i = 0; i < num_cols; ++i) {
68 fields.push_back(field("f" + std::to_string(i), ty));
69 const int64_t chunk1_len = num_rows / 2;
70 const int64_t chunk2_len = num_rows - chunk1_len;
71 ArrayVector arrays = {gen_.ArrayOf(ty, chunk1_len), gen_.ArrayOf(ty, chunk2_len)};
72 auto chunks = std::make_shared<ChunkedArray>(arrays, ty);
73 columns.push_back(chunks);
74 }
75 auto schema = std::make_shared<Schema>(std::move(fields));
76 auto table = Table::Make(schema, columns);
77
78 for (auto _ : state) {
79 ASSERT_OK_AND_ASSIGN(auto tensor,
80 table->ToTensor(/*null_to_nan=*/false, /*row_major=*/row_major));
81 }
82 state.SetItemsProcessed(state.iterations() * num_rows * num_cols);
83 state.SetBytesProcessed(state.iterations() * ty->byte_width() * num_rows * num_cols);
84}
85
86void SetArgs(benchmark::internal::Benchmark* bench) {
87 for (int64_t size : {kL1Size, kL2Size}) {

Callers

nothing calls this directly

Calls 7

to_stringFunction · 0.85
push_backMethod · 0.80
type_singletonFunction · 0.70
fieldFunction · 0.70
MakeFunction · 0.70
ArrayOfMethod · 0.45
byte_widthMethod · 0.45

Tested by

no test coverage detected