sparrow
0.3.0
Loading...
Searching...
No Matches
typed_array_low_level.cpp
Go to the documentation of this file.
1
6
7
// #include <sparrow/array/array_data.hpp>
8
9
int
main
()
10
{
12
// create array_data with 5 float32 elements
13
// where the value at index 2 is missing
15
/*using value_type = float;
16
static const float no_value = NAN;
17
auto n = 5;
18
19
// create the array_data object
20
sparrow::array_data data;
21
data.type = sparrow::data_descriptor(sparrow::arrow_traits<value_type>::type_id);
22
23
// create a bitmap with all bits set to true except for
24
// the missing value at index 2
25
data.bitmap = sparrow::dynamic_bitset<uint8_t>(n, true);
26
data.bitmap.set(2, false);
27
28
29
// the buffer holding the actual data
30
const size_t buffer_size = (n * sizeof(value_type)) / sizeof(uint8_t);
31
sparrow::buffer<uint8_t> buffer(buffer_size);
32
33
buffer.data<value_type>()[0] = 1.0;
34
buffer.data<value_type>()[1] = 2.0;
35
buffer.data<value_type>()[2] = no_value; // missing value, will lead to errors if used
36
buffer.data<value_type>()[3] = 4.0;
37
buffer.data<value_type>()[4] = 5.0;
38
39
// add the buffer to the array_data
40
data.buffers.push_back(buffer);
41
data.length = static_cast<std::int64_t>(n);
42
data.offset = static_cast<std::int64_t>(0);
43
data.child_data.emplace_back();
44
45
// create a typed_array object from the array_data
46
auto array = sparrow::typed_array<value_type>(data);
47
48
// access the data
49
for (auto i = 0; i < n; ++i) {
50
if (array.bitmap()[i]) {
51
std::cout << array[i].value() << std::endl;
52
} else {
53
std::cout << "missing value" << std::endl;
54
}
55
}*/
56
57
return
0;
58
}
main
int main()
Definition
builder_example.cpp:207
examples
typed_array_low_level.cpp
Generated by
1.13.2