6#include "../collection.hpp"
8#include "../result.hpp"
9#include "../type_traits.hpp"
20 class DenseUnionBuilder;
26 enum class TensorBufferTag : uint8_t {
43 union TensorBufferData {
78 std::memset(
reinterpret_cast<void*
>(
this), 0,
sizeof(TensorBufferData));
81 ~TensorBufferData() {}
83 void swap(TensorBufferData& other)
noexcept {
85 char temp[
sizeof(TensorBufferData)];
86 void* otherbytes =
reinterpret_cast<void*
>(&other);
87 void* thisbytes =
reinterpret_cast<void*
>(
this);
88 std::memcpy(temp, thisbytes,
sizeof(TensorBufferData));
89 std::memcpy(thisbytes, otherbytes,
sizeof(TensorBufferData));
90 std::memcpy(otherbytes, temp,
sizeof(TensorBufferData));
103 switch (other._tag) {
104 case detail::TensorBufferTag::U8: {
106 new (&_data.u8) TypeAlias(other._data.u8);
108 case detail::TensorBufferTag::U16: {
110 new (&_data.u16) TypeAlias(other._data.u16);
112 case detail::TensorBufferTag::U32: {
114 new (&_data.u32) TypeAlias(other._data.u32);
116 case detail::TensorBufferTag::U64: {
118 new (&_data.u64) TypeAlias(other._data.u64);
120 case detail::TensorBufferTag::I8: {
122 new (&_data.i8) TypeAlias(other._data.i8);
124 case detail::TensorBufferTag::I16: {
126 new (&_data.i16) TypeAlias(other._data.i16);
128 case detail::TensorBufferTag::I32: {
130 new (&_data.i32) TypeAlias(other._data.i32);
132 case detail::TensorBufferTag::I64: {
134 new (&_data.i64) TypeAlias(other._data.i64);
136 case detail::TensorBufferTag::F16: {
138 new (&_data.f16) TypeAlias(other._data.f16);
140 case detail::TensorBufferTag::F32: {
142 new (&_data.f32) TypeAlias(other._data.f32);
144 case detail::TensorBufferTag::F64: {
146 new (&_data.f64) TypeAlias(other._data.f64);
148 case detail::TensorBufferTag::None: {
151 assert(
false &&
"unreachable");
165 TensorBuffer& operator=(TensorBuffer&& other)
noexcept {
171 switch (this->_tag) {
172 case detail::TensorBufferTag::None: {
175 case detail::TensorBufferTag::U8: {
177 _data.u8.~TypeAlias();
179 case detail::TensorBufferTag::U16: {
181 _data.u16.~TypeAlias();
183 case detail::TensorBufferTag::U32: {
185 _data.u32.~TypeAlias();
187 case detail::TensorBufferTag::U64: {
189 _data.u64.~TypeAlias();
191 case detail::TensorBufferTag::I8: {
193 _data.i8.~TypeAlias();
195 case detail::TensorBufferTag::I16: {
197 _data.i16.~TypeAlias();
199 case detail::TensorBufferTag::I32: {
201 _data.i32.~TypeAlias();
203 case detail::TensorBufferTag::I64: {
205 _data.i64.~TypeAlias();
207 case detail::TensorBufferTag::F16: {
209 _data.f16.~TypeAlias();
211 case detail::TensorBufferTag::F32: {
213 _data.f32.~TypeAlias();
215 case detail::TensorBufferTag::F64: {
217 _data.f64.~TypeAlias();
220 assert(
false &&
"unreachable");
231 template <
typename TContainer,
typename value_type = traits::value_type_of_t<TContainer>>
243 std::swap(this->_tag, other._tag);
244 this->_data.swap(other._data);
305 self._tag = detail::TensorBufferTag::U8;
313 self._tag = detail::TensorBufferTag::U16;
321 self._tag = detail::TensorBufferTag::U32;
329 self._tag = detail::TensorBufferTag::U64;
337 self._tag = detail::TensorBufferTag::I8;
345 self._tag = detail::TensorBufferTag::I16;
353 self._tag = detail::TensorBufferTag::I32;
361 self._tag = detail::TensorBufferTag::I64;
369 self._tag = detail::TensorBufferTag::F16;
377 self._tag = detail::TensorBufferTag::F32;
385 self._tag = detail::TensorBufferTag::F64;
392 if (_tag == detail::TensorBufferTag::U8) {
401 if (_tag == detail::TensorBufferTag::U16) {
410 if (_tag == detail::TensorBufferTag::U32) {
419 if (_tag == detail::TensorBufferTag::U64) {
428 if (_tag == detail::TensorBufferTag::I8) {
437 if (_tag == detail::TensorBufferTag::I16) {
446 if (_tag == detail::TensorBufferTag::I32) {
455 if (_tag == detail::TensorBufferTag::I64) {
464 if (_tag == detail::TensorBufferTag::F16) {
473 if (_tag == detail::TensorBufferTag::F32) {
482 if (_tag == detail::TensorBufferTag::F64) {
490 const detail::TensorBufferData& get_union_data()
const {
495 detail::TensorBufferTag get_union_tag()
const {
500 detail::TensorBufferTag _tag;
501 detail::TensorBufferData _data;
506 template <
typename T>
511 struct Loggable<datatypes::TensorBuffer> {
512 static constexpr const char Name[] =
"rerun.datatypes.TensorBuffer";
515 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
518 static Result<std::shared_ptr<arrow::Array>> to_arrow(
519 const datatypes::TensorBuffer* instances,
size_t num_instances
524 arrow::DenseUnionBuilder* builder,
const datatypes::TensorBuffer* elements,
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:95
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:82
@ F64
64-bit IEEE-754 floating point, also known as double.
@ U64
64-bit unsigned integer.
@ F32
32-bit IEEE-754 floating point, also known as float or single.
@ F16
16-bit IEEE-754 floating point, also known as half.
@ I8
8-bit signed integer.
@ U8
8-bit unsigned integer.
@ I16
16-bit signed integer.
@ U32
32-bit unsigned integer.
@ I32
32-bit signed integer.
@ I64
64-bit signed integer.
@ U16
16-bit unsigned integer.
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:98
const rerun::Collection< uint16_t > * get_u16() const
Return a pointer to u16 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:400
TensorBuffer(const TensorBuffer &other)
Copy constructor.
Definition tensor_buffer.hpp:102
const rerun::Collection< uint64_t > * get_u64() const
Return a pointer to u64 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:418
size_t num_elems() const
Number of elements in the buffer.
TensorBuffer(rerun::Collection< int32_t > i32)
32bit signed integer.
Definition tensor_buffer.hpp:278
static TensorBuffer f32(rerun::Collection< float > f32)
32bit IEEE-754 floating point, also known as float or single.
Definition tensor_buffer.hpp:375
TensorBuffer(rerun::Collection< uint32_t > u32)
32bit unsigned integer.
Definition tensor_buffer.hpp:258
static TensorBuffer u64(rerun::Collection< uint64_t > u64)
64bit unsigned integer.
Definition tensor_buffer.hpp:327
TensorBuffer(rerun::Collection< int16_t > i16)
16bit signed integer.
Definition tensor_buffer.hpp:273
TensorBuffer(rerun::Collection< double > f64)
64bit IEEE-754 floating point, also known as double.
Definition tensor_buffer.hpp:298
const rerun::Collection< uint32_t > * get_u32() const
Return a pointer to u32 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:409
const rerun::Collection< rerun::half > * get_f16() const
Return a pointer to f16 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:463
const rerun::Collection< uint8_t > * get_u8() const
Return a pointer to u8 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:391
const rerun::Collection< double > * get_f64() const
Return a pointer to f64 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:481
static TensorBuffer i32(rerun::Collection< int32_t > i32)
32bit signed integer.
Definition tensor_buffer.hpp:351
static TensorBuffer i64(rerun::Collection< int64_t > i64)
64bit signed integer.
Definition tensor_buffer.hpp:359
static TensorBuffer f16(rerun::Collection< rerun::half > f16)
16bit IEEE-754 floating point, also known as half.
Definition tensor_buffer.hpp:367
TensorBuffer(rerun::Collection< int64_t > i64)
64bit signed integer.
Definition tensor_buffer.hpp:283
TensorBuffer(rerun::Collection< uint16_t > u16)
16bit unsigned integer.
Definition tensor_buffer.hpp:253
static TensorBuffer u16(rerun::Collection< uint16_t > u16)
16bit unsigned integer.
Definition tensor_buffer.hpp:311
TensorBuffer(rerun::Collection< int8_t > i8)
8bit signed integer.
Definition tensor_buffer.hpp:268
static TensorBuffer i8(rerun::Collection< int8_t > i8)
8bit signed integer.
Definition tensor_buffer.hpp:335
const rerun::Collection< int16_t > * get_i16() const
Return a pointer to i16 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:436
const rerun::Collection< float > * get_f32() const
Return a pointer to f32 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:472
static TensorBuffer u8(rerun::Collection< uint8_t > u8)
8bit unsigned integer.
Definition tensor_buffer.hpp:303
static TensorBuffer i16(rerun::Collection< int16_t > i16)
16bit signed integer.
Definition tensor_buffer.hpp:343
const rerun::Collection< int8_t > * get_i8() const
Return a pointer to i8 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:427
TensorBuffer(rerun::Collection< uint8_t > u8)
8bit unsigned integer.
Definition tensor_buffer.hpp:248
static TensorBuffer u32(rerun::Collection< uint32_t > u32)
32bit unsigned integer.
Definition tensor_buffer.hpp:319
TensorBuffer(rerun::Collection< uint64_t > u64)
64bit unsigned integer.
Definition tensor_buffer.hpp:263
TensorBuffer(TContainer &&container)
Construct a TensorBuffer from any container type that has a value_type member and for which a rerun::...
Definition tensor_buffer.hpp:232
const rerun::Collection< int64_t > * get_i64() const
Return a pointer to i64 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:454
const rerun::Collection< int32_t > * get_i32() const
Return a pointer to i32 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:445
static TensorBuffer f64(rerun::Collection< double > f64)
64bit IEEE-754 floating point, also known as double.
Definition tensor_buffer.hpp:383
TensorBuffer(rerun::Collection< float > f32)
32bit IEEE-754 floating point, also known as float or single.
Definition tensor_buffer.hpp:293
TensorBuffer(rerun::Collection< rerun::half > f16)
16bit IEEE-754 floating point, also known as half.
Definition tensor_buffer.hpp:288