6#include "../collection.hpp"
8#include "../result.hpp"
9#include "../type_traits.hpp"
20 class DenseUnionBuilder;
26 enum class TensorBufferTag : uint8_t {
45 union TensorBufferData {
73 std::memset(
reinterpret_cast<void*
>(
this), 0,
sizeof(TensorBufferData));
76 ~TensorBufferData() {}
78 void swap(TensorBufferData& other)
noexcept {
80 char temp[
sizeof(TensorBufferData)];
81 void* otherbytes =
reinterpret_cast<void*
>(&other);
82 void* thisbytes =
reinterpret_cast<void*
>(
this);
83 std::memcpy(temp, thisbytes,
sizeof(TensorBufferData));
84 std::memcpy(thisbytes, otherbytes,
sizeof(TensorBufferData));
85 std::memcpy(otherbytes, temp,
sizeof(TensorBufferData));
99 case detail::TensorBufferTag::U8: {
101 new (&_data.u8) TypeAlias(other._data.u8);
103 case detail::TensorBufferTag::U16: {
105 new (&_data.u16) TypeAlias(other._data.u16);
107 case detail::TensorBufferTag::U32: {
109 new (&_data.u32) TypeAlias(other._data.u32);
111 case detail::TensorBufferTag::U64: {
113 new (&_data.u64) TypeAlias(other._data.u64);
115 case detail::TensorBufferTag::I8: {
117 new (&_data.i8) TypeAlias(other._data.i8);
119 case detail::TensorBufferTag::I16: {
121 new (&_data.i16) TypeAlias(other._data.i16);
123 case detail::TensorBufferTag::I32: {
125 new (&_data.i32) TypeAlias(other._data.i32);
127 case detail::TensorBufferTag::I64: {
129 new (&_data.i64) TypeAlias(other._data.i64);
131 case detail::TensorBufferTag::F16: {
133 new (&_data.f16) TypeAlias(other._data.f16);
135 case detail::TensorBufferTag::F32: {
137 new (&_data.f32) TypeAlias(other._data.f32);
139 case detail::TensorBufferTag::F64: {
141 new (&_data.f64) TypeAlias(other._data.f64);
143 case detail::TensorBufferTag::JPEG: {
145 new (&_data.jpeg) TypeAlias(other._data.jpeg);
147 case detail::TensorBufferTag::NV12: {
149 new (&_data.nv12) TypeAlias(other._data.nv12);
151 case detail::TensorBufferTag::None: {
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();
220 case detail::TensorBufferTag::JPEG: {
222 _data.jpeg.~TypeAlias();
224 case detail::TensorBufferTag::NV12: {
226 _data.nv12.~TypeAlias();
274 template <
typename TContainer,
typename value_type = traits::value_type_of_t<TContainer>>
284 std::swap(this->_tag, other._tag);
285 this->_data.swap(other._data);
290 self._tag = detail::TensorBufferTag::U8;
297 self._tag = detail::TensorBufferTag::U16;
304 self._tag = detail::TensorBufferTag::U32;
311 self._tag = detail::TensorBufferTag::U64;
318 self._tag = detail::TensorBufferTag::I8;
325 self._tag = detail::TensorBufferTag::I16;
332 self._tag = detail::TensorBufferTag::I32;
339 self._tag = detail::TensorBufferTag::I64;
346 self._tag = detail::TensorBufferTag::F16;
353 self._tag = detail::TensorBufferTag::F32;
360 self._tag = detail::TensorBufferTag::F64;
367 self._tag = detail::TensorBufferTag::JPEG;
374 self._tag = detail::TensorBufferTag::NV12;
381 if (_tag == detail::TensorBufferTag::U8) {
390 if (_tag == detail::TensorBufferTag::U16) {
399 if (_tag == detail::TensorBufferTag::U32) {
408 if (_tag == detail::TensorBufferTag::U64) {
417 if (_tag == detail::TensorBufferTag::I8) {
426 if (_tag == detail::TensorBufferTag::I16) {
435 if (_tag == detail::TensorBufferTag::I32) {
444 if (_tag == detail::TensorBufferTag::I64) {
453 if (_tag == detail::TensorBufferTag::F16) {
462 if (_tag == detail::TensorBufferTag::F32) {
471 if (_tag == detail::TensorBufferTag::F64) {
480 if (_tag == detail::TensorBufferTag::JPEG) {
489 if (_tag == detail::TensorBufferTag::NV12) {
497 const detail::TensorBufferData& get_union_data()
const {
502 detail::TensorBufferTag get_union_tag()
const {
507 detail::TensorBufferTag _tag;
508 detail::TensorBufferData _data;
513 template <
typename T>
518 struct Loggable<datatypes::TensorBuffer> {
519 static constexpr const char Name[] =
"rerun.datatypes.TensorBuffer";
522 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
526 arrow::DenseUnionBuilder* builder,
const datatypes::TensorBuffer* elements,
531 static Result<std::shared_ptr<arrow::Array>> to_arrow(
532 const datatypes::TensorBuffer* instances,
size_t num_instances
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:47
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:87
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:72
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Datatype: The underlying storage for a Tensor.
Definition tensor_buffer.hpp:93
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:389
TensorBuffer(const TensorBuffer &other)
Copy constructor.
Definition tensor_buffer.hpp:97
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:407
TensorBuffer(Collection< int32_t > i32)
Construct a TensorBuffer from a Collection<int32_t>.
Definition tensor_buffer.hpp:253
size_t num_elems() const
Number of elements in the buffer.
TensorBuffer(Collection< uint16_t > u16)
Construct a TensorBuffer from a Collection<uint16_t>.
Definition tensor_buffer.hpp:238
TensorBuffer(Collection< float > f32)
Construct a TensorBuffer from a Collection<float>.
Definition tensor_buffer.hpp:263
TensorBuffer(Collection< rerun::half > f16)
Construct a TensorBuffer from a Collection<half>.
Definition tensor_buffer.hpp:259
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:398
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:452
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:380
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:470
const rerun::Collection< uint8_t > * get_nv12() const
Return a pointer to nv12 if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:488
TensorBuffer(Collection< uint8_t > u8)
Construct a TensorBuffer from a Collection<uint8_t>.
Definition tensor_buffer.hpp:235
const rerun::Collection< uint8_t > * get_jpeg() const
Return a pointer to jpeg if the union is in that state, otherwise nullptr.
Definition tensor_buffer.hpp:479
TensorBuffer(Collection< int16_t > i16)
Construct a TensorBuffer from a Collection<int16_t>.
Definition tensor_buffer.hpp:250
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:425
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:461
TensorBuffer(Collection< int64_t > i64)
Construct a TensorBuffer from a Collection<int64_t>.
Definition tensor_buffer.hpp:256
TensorBuffer(Collection< uint32_t > u32)
Construct a TensorBuffer from a Collection<uint32_t>.
Definition tensor_buffer.hpp:241
TensorBuffer(Collection< uint64_t > u64)
Construct a TensorBuffer from a Collection<uint64_t>.
Definition tensor_buffer.hpp:244
TensorBuffer(Collection< int8_t > i8)
Construct a TensorBuffer from a Collection<int8_t>.
Definition tensor_buffer.hpp:247
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:416
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:275
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:443
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:434
TensorBuffer(Collection< double > f64)
Construct a TensorBuffer from a Collection<double>.
Definition tensor_buffer.hpp:266