6#include "../collection.hpp"
7#include "../component_descriptor.hpp"
9#include "../result.hpp"
10#include "../type_traits.hpp"
21 class DenseUnionBuilder;
27 enum class TensorBufferTag : uint8_t {
44 union TensorBufferData {
79 std::memset(
reinterpret_cast<void*
>(
this), 0,
sizeof(TensorBufferData));
82 ~TensorBufferData() {}
84 void swap(TensorBufferData& other)
noexcept {
86 char temp[
sizeof(TensorBufferData)];
87 void* otherbytes =
reinterpret_cast<void*
>(&other);
88 void* thisbytes =
reinterpret_cast<void*
>(
this);
89 std::memcpy(temp, thisbytes,
sizeof(TensorBufferData));
90 std::memcpy(thisbytes, otherbytes,
sizeof(TensorBufferData));
91 std::memcpy(otherbytes, temp,
sizeof(TensorBufferData));
104 switch (other._tag) {
105 case detail::TensorBufferTag::U8: {
107 new (&_data.u8) TypeAlias(other._data.u8);
109 case detail::TensorBufferTag::U16: {
111 new (&_data.u16) TypeAlias(other._data.u16);
113 case detail::TensorBufferTag::U32: {
115 new (&_data.u32) TypeAlias(other._data.u32);
117 case detail::TensorBufferTag::U64: {
119 new (&_data.u64) TypeAlias(other._data.u64);
121 case detail::TensorBufferTag::I8: {
123 new (&_data.i8) TypeAlias(other._data.i8);
125 case detail::TensorBufferTag::I16: {
127 new (&_data.i16) TypeAlias(other._data.i16);
129 case detail::TensorBufferTag::I32: {
131 new (&_data.i32) TypeAlias(other._data.i32);
133 case detail::TensorBufferTag::I64: {
135 new (&_data.i64) TypeAlias(other._data.i64);
137 case detail::TensorBufferTag::F16: {
139 new (&_data.f16) TypeAlias(other._data.f16);
141 case detail::TensorBufferTag::F32: {
143 new (&_data.f32) TypeAlias(other._data.f32);
145 case detail::TensorBufferTag::F64: {
147 new (&_data.f64) TypeAlias(other._data.f64);
149 case detail::TensorBufferTag::None: {
152 assert(
false &&
"unreachable");
166 TensorBuffer& operator=(TensorBuffer&& other)
noexcept {
172 switch (this->_tag) {
173 case detail::TensorBufferTag::None: {
176 case detail::TensorBufferTag::U8: {
178 _data.u8.~TypeAlias();
180 case detail::TensorBufferTag::U16: {
182 _data.u16.~TypeAlias();
184 case detail::TensorBufferTag::U32: {
186 _data.u32.~TypeAlias();
188 case detail::TensorBufferTag::U64: {
190 _data.u64.~TypeAlias();
192 case detail::TensorBufferTag::I8: {
194 _data.i8.~TypeAlias();
196 case detail::TensorBufferTag::I16: {
198 _data.i16.~TypeAlias();
200 case detail::TensorBufferTag::I32: {
202 _data.i32.~TypeAlias();
204 case detail::TensorBufferTag::I64: {
206 _data.i64.~TypeAlias();
208 case detail::TensorBufferTag::F16: {
210 _data.f16.~TypeAlias();
212 case detail::TensorBufferTag::F32: {
214 _data.f32.~TypeAlias();
216 case detail::TensorBufferTag::F64: {
218 _data.f64.~TypeAlias();
221 assert(
false &&
"unreachable");
232 template <
typename TContainer,
typename value_type = traits::value_type_of_t<TContainer>>
244 std::swap(this->_tag, other._tag);
245 this->_data.swap(other._data);
306 self._tag = detail::TensorBufferTag::U8;
314 self._tag = detail::TensorBufferTag::U16;
322 self._tag = detail::TensorBufferTag::U32;
330 self._tag = detail::TensorBufferTag::U64;
338 self._tag = detail::TensorBufferTag::I8;
346 self._tag = detail::TensorBufferTag::I16;
354 self._tag = detail::TensorBufferTag::I32;
362 self._tag = detail::TensorBufferTag::I64;
370 self._tag = detail::TensorBufferTag::F16;
378 self._tag = detail::TensorBufferTag::F32;
386 self._tag = detail::TensorBufferTag::F64;
393 if (_tag == detail::TensorBufferTag::U8) {
402 if (_tag == detail::TensorBufferTag::U16) {
411 if (_tag == detail::TensorBufferTag::U32) {
420 if (_tag == detail::TensorBufferTag::U64) {
429 if (_tag == detail::TensorBufferTag::I8) {
438 if (_tag == detail::TensorBufferTag::I16) {
447 if (_tag == detail::TensorBufferTag::I32) {
456 if (_tag == detail::TensorBufferTag::I64) {
465 if (_tag == detail::TensorBufferTag::F16) {
474 if (_tag == detail::TensorBufferTag::F32) {
483 if (_tag == detail::TensorBufferTag::F64) {
491 const detail::TensorBufferData& get_union_data()
const {
496 detail::TensorBufferTag get_union_tag()
const {
501 detail::TensorBufferTag _tag;
502 detail::TensorBufferData _data;
507 template <
typename T>
512 struct Loggable<datatypes::TensorBuffer> {
513 static constexpr ComponentDescriptor Descriptor =
"rerun.datatypes.TensorBuffer";
516 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
519 static Result<std::shared_ptr<arrow::Array>> to_arrow(
520 const datatypes::TensorBuffer* instances,
size_t num_instances
525 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:83
@ 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:23
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:99
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:401
TensorBuffer(const TensorBuffer &other)
Copy constructor.
Definition tensor_buffer.hpp:103
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:419
size_t num_elems() const
Number of elements in the buffer.
TensorBuffer(rerun::Collection< int32_t > i32)
32bit signed integer.
Definition tensor_buffer.hpp:279
static TensorBuffer f32(rerun::Collection< float > f32)
32bit IEEE-754 floating point, also known as float or single.
Definition tensor_buffer.hpp:376
TensorBuffer(rerun::Collection< uint32_t > u32)
32bit unsigned integer.
Definition tensor_buffer.hpp:259
static TensorBuffer u64(rerun::Collection< uint64_t > u64)
64bit unsigned integer.
Definition tensor_buffer.hpp:328
TensorBuffer(rerun::Collection< int16_t > i16)
16bit signed integer.
Definition tensor_buffer.hpp:274
TensorBuffer(rerun::Collection< double > f64)
64bit IEEE-754 floating point, also known as double.
Definition tensor_buffer.hpp:299
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:410
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:464
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:392
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:482
static TensorBuffer i32(rerun::Collection< int32_t > i32)
32bit signed integer.
Definition tensor_buffer.hpp:352
static TensorBuffer i64(rerun::Collection< int64_t > i64)
64bit signed integer.
Definition tensor_buffer.hpp:360
static TensorBuffer f16(rerun::Collection< rerun::half > f16)
16bit IEEE-754 floating point, also known as half.
Definition tensor_buffer.hpp:368
TensorBuffer(rerun::Collection< int64_t > i64)
64bit signed integer.
Definition tensor_buffer.hpp:284
TensorBuffer(rerun::Collection< uint16_t > u16)
16bit unsigned integer.
Definition tensor_buffer.hpp:254
static TensorBuffer u16(rerun::Collection< uint16_t > u16)
16bit unsigned integer.
Definition tensor_buffer.hpp:312
TensorBuffer(rerun::Collection< int8_t > i8)
8bit signed integer.
Definition tensor_buffer.hpp:269
static TensorBuffer i8(rerun::Collection< int8_t > i8)
8bit signed integer.
Definition tensor_buffer.hpp:336
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:437
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:473
static TensorBuffer u8(rerun::Collection< uint8_t > u8)
8bit unsigned integer.
Definition tensor_buffer.hpp:304
static TensorBuffer i16(rerun::Collection< int16_t > i16)
16bit signed integer.
Definition tensor_buffer.hpp:344
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:428
TensorBuffer(rerun::Collection< uint8_t > u8)
8bit unsigned integer.
Definition tensor_buffer.hpp:249
static TensorBuffer u32(rerun::Collection< uint32_t > u32)
32bit unsigned integer.
Definition tensor_buffer.hpp:320
TensorBuffer(rerun::Collection< uint64_t > u64)
64bit unsigned integer.
Definition tensor_buffer.hpp:264
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:233
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:455
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:446
static TensorBuffer f64(rerun::Collection< double > f64)
64bit IEEE-754 floating point, also known as double.
Definition tensor_buffer.hpp:384
TensorBuffer(rerun::Collection< float > f32)
32bit IEEE-754 floating point, also known as float or single.
Definition tensor_buffer.hpp:294
TensorBuffer(rerun::Collection< rerun::half > f16)
16bit IEEE-754 floating point, also known as half.
Definition tensor_buffer.hpp:289