Rerun C++ SDK
Loading...
Searching...
No Matches
tensor_data.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_types/definitions/rerun/datatypes/tensor_data.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_descriptor.hpp"
8#include "../result.hpp"
9#include "tensor_buffer.hpp"
10#include "tensor_dimension.hpp"
11
12#include <cstdint>
13#include <memory>
14
15namespace arrow {
16 class Array;
17 class DataType;
18 class StructBuilder;
19} // namespace arrow
20
21namespace rerun::datatypes {
22 /// **Datatype**: An N-dimensional array of numbers.
23 ///
24 /// The number of dimensions and their respective lengths is specified by the `shape` field.
25 /// The dimensions are ordered from outermost to innermost. For example, in the common case of
26 /// a 2D RGB Image, the shape would be `[height, width, channel]`.
27 ///
28 /// These dimensions are combined with an index to look up values from the `buffer` field,
29 /// which stores a contiguous array of typed values.
30 struct TensorData {
31 /// The shape of the tensor, including optional names for each dimension.
33
34 /// The content/data.
36
37 public: // START of extensions from tensor_data_ext.cpp:
38 /// New tensor data from shape and tensor buffer.
39 ///
40 /// \param shape_ Shape of the tensor.
41 /// \param buffer_ The tensor buffer containing the tensor's data.
44 )
45 : shape(std::move(shape_)), buffer(std::move(buffer_)) {}
46
47 /// New tensor data from dimensions and pointer to tensor data.
48 ///
49 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
50 /// \param shape_ Shape of the tensor. Determines the number of elements expected to be in `data`.
51 /// \param data Target of the pointer must outlive the archetype.
52 template <typename TElement>
53 explicit TensorData(Collection<datatypes::TensorDimension> shape_, const TElement* data)
54 : shape(std::move(shape_)) {
55 size_t num_elements = shape.empty() ? 0 : 1;
56 for (const auto& dim : shape) {
57 num_elements *= dim.size;
58 }
59 buffer = rerun::Collection<TElement>::borrow(data, num_elements);
60 }
61
62 // END of extensions from tensor_data_ext.cpp, start of generated code:
63
64 public:
65 TensorData() = default;
66 };
67} // namespace rerun::datatypes
68
69namespace rerun {
70 template <typename T>
71 struct Loggable;
72
73 /// \private
74 template <>
75 struct Loggable<datatypes::TensorData> {
76 static constexpr ComponentDescriptor Descriptor = "rerun.datatypes.TensorData";
77
78 /// Returns the arrow data type this type corresponds to.
79 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
80
81 /// Serializes an array of `rerun::datatypes::TensorData` into an arrow array.
82 static Result<std::shared_ptr<arrow::Array>> to_arrow(
83 const datatypes::TensorData* instances, size_t num_instances
84 );
85
86 /// Fills an arrow array builder with an array of this type.
87 static rerun::Error fill_arrow_array_builder(
88 arrow::StructBuilder* builder, const datatypes::TensorData* elements,
89 size_t num_elements
90 );
91 };
92} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
static Collection< TElement > borrow(const T *data, size_t num_instances=1)
Borrows binary compatible data into the collection from a typed pointer.
Definition collection.hpp:154
bool empty() const
Returns true if the collection is empty.
Definition collection.hpp:306
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
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
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:30
TensorData(Collection< rerun::datatypes::TensorDimension > shape_, datatypes::TensorBuffer buffer_)
New tensor data from shape and tensor buffer.
Definition tensor_data.hpp:42
rerun::datatypes::TensorBuffer buffer
The content/data.
Definition tensor_data.hpp:35
TensorData(Collection< datatypes::TensorDimension > shape_, const TElement *data)
New tensor data from dimensions and pointer to tensor data.
Definition tensor_data.hpp:53
rerun::Collection< rerun::datatypes::TensorDimension > shape
The shape of the tensor, including optional names for each dimension.
Definition tensor_data.hpp:32