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>>
245 std::swap(this->_tag, other._tag);
246 this->_data.swap(other._data);
307 self._tag = detail::TensorBufferTag::U8;
315 self._tag = detail::TensorBufferTag::U16;
323 self._tag = detail::TensorBufferTag::U32;
331 self._tag = detail::TensorBufferTag::U64;
339 self._tag = detail::TensorBufferTag::I8;
347 self._tag = detail::TensorBufferTag::I16;
355 self._tag = detail::TensorBufferTag::I32;
363 self._tag = detail::TensorBufferTag::I64;
371 self._tag = detail::TensorBufferTag::F16;
379 self._tag = detail::TensorBufferTag::F32;
387 self._tag = detail::TensorBufferTag::F64;
394 if (_tag == detail::TensorBufferTag::U8) {
403 if (_tag == detail::TensorBufferTag::U16) {
412 if (_tag == detail::TensorBufferTag::U32) {
421 if (_tag == detail::TensorBufferTag::U64) {
430 if (_tag == detail::TensorBufferTag::I8) {
439 if (_tag == detail::TensorBufferTag::I16) {
448 if (_tag == detail::TensorBufferTag::I32) {
457 if (_tag == detail::TensorBufferTag::I64) {
466 if (_tag == detail::TensorBufferTag::F16) {
475 if (_tag == detail::TensorBufferTag::F32) {
484 if (_tag == detail::TensorBufferTag::F64) {
492 const detail::TensorBufferData& get_union_data()
const {
497 detail::TensorBufferTag get_union_tag()
const {
502 detail::TensorBufferTag _tag;
503 detail::TensorBufferData _data;
508 template <
typename T>
513 struct Loggable<datatypes::TensorBuffer> {
514 static constexpr std::string_view ComponentType =
"rerun.datatypes.TensorBuffer";
517 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
520 static Result<std::shared_ptr<arrow::Array>> to_arrow(
521 const datatypes::TensorBuffer* instances,
size_t num_instances
526 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:103
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:93
@ 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: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:402
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:420
size_t num_elems() const
Number of elements in the buffer.
TensorBuffer(rerun::Collection< int32_t > i32)
32bit signed integer.
Definition tensor_buffer.hpp:280
static TensorBuffer f32(rerun::Collection< float > f32)
32bit IEEE-754 floating point, also known as float or single.
Definition tensor_buffer.hpp:377
TensorBuffer(rerun::Collection< uint32_t > u32)
32bit unsigned integer.
Definition tensor_buffer.hpp:260
static TensorBuffer u64(rerun::Collection< uint64_t > u64)
64bit unsigned integer.
Definition tensor_buffer.hpp:329
TensorBuffer(rerun::Collection< int16_t > i16)
16bit signed integer.
Definition tensor_buffer.hpp:275
TensorBuffer(rerun::Collection< double > f64)
64bit IEEE-754 floating point, also known as double.
Definition tensor_buffer.hpp:300
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:411
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:465
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:393
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:483
static TensorBuffer i32(rerun::Collection< int32_t > i32)
32bit signed integer.
Definition tensor_buffer.hpp:353
static TensorBuffer i64(rerun::Collection< int64_t > i64)
64bit signed integer.
Definition tensor_buffer.hpp:361
static TensorBuffer f16(rerun::Collection< rerun::half > f16)
16bit IEEE-754 floating point, also known as half.
Definition tensor_buffer.hpp:369
TensorBuffer(rerun::Collection< int64_t > i64)
64bit signed integer.
Definition tensor_buffer.hpp:285
TensorBuffer(rerun::Collection< uint16_t > u16)
16bit unsigned integer.
Definition tensor_buffer.hpp:255
static TensorBuffer u16(rerun::Collection< uint16_t > u16)
16bit unsigned integer.
Definition tensor_buffer.hpp:313
TensorBuffer(rerun::Collection< int8_t > i8)
8bit signed integer.
Definition tensor_buffer.hpp:270
static TensorBuffer i8(rerun::Collection< int8_t > i8)
8bit signed integer.
Definition tensor_buffer.hpp:337
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:438
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:474
static TensorBuffer u8(rerun::Collection< uint8_t > u8)
8bit unsigned integer.
Definition tensor_buffer.hpp:305
static TensorBuffer i16(rerun::Collection< int16_t > i16)
16bit signed integer.
Definition tensor_buffer.hpp:345
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:429
TensorBuffer(rerun::Collection< uint8_t > u8)
8bit unsigned integer.
Definition tensor_buffer.hpp:250
static TensorBuffer u32(rerun::Collection< uint32_t > u32)
32bit unsigned integer.
Definition tensor_buffer.hpp:321
TensorBuffer(rerun::Collection< uint64_t > u64)
64bit unsigned integer.
Definition tensor_buffer.hpp:265
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:234
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:456
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:447
static TensorBuffer f64(rerun::Collection< double > f64)
64bit IEEE-754 floating point, also known as double.
Definition tensor_buffer.hpp:385
TensorBuffer(rerun::Collection< float > f32)
32bit IEEE-754 floating point, also known as float or single.
Definition tensor_buffer.hpp:295
TensorBuffer(rerun::Collection< rerun::half > f16)
16bit IEEE-754 floating point, also known as half.
Definition tensor_buffer.hpp:290