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 "../result.hpp"
8#include "tensor_buffer.hpp"
9
10#include <cstdint>
11#include <memory>
12#include <optional>
13#include <string>
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, i.e. the length of each dimension.
33
34 /// The names of the dimensions of the tensor (optional).
35 ///
36 /// If set, should be the same length as `datatypes::TensorData::shape`.
37 /// If it has a different length your names may show up improperly,
38 /// and some constructors may produce a warning or even an error.
39 ///
40 /// Example: `["height", "width", "channel", "batch"]`.
41 std::optional<rerun::Collection<std::string>> names;
42
43 /// The content/data.
45
46 public: // START of extensions from tensor_data_ext.cpp:
47 /// New tensor data from shape and tensor buffer.
48 ///
49 /// \param shape_ Shape of the tensor.
50 /// \param buffer_ The tensor buffer containing the tensor's data.
52 : shape(std::move(shape_)), buffer(std::move(buffer_)) {}
53
54 /// New tensor data from dimensions and pointer to tensor data.
55 ///
56 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
57 /// \param shape_ Shape of the tensor. Determines the number of elements expected to be in `data`.
58 /// \param data Target of the pointer must outlive the archetype.
59 template <typename TElement>
60 explicit TensorData(Collection<uint64_t> shape_, const TElement* data)
61 : shape(std::move(shape_)) {
62 size_t num_elements = shape.empty() ? 0 : 1;
63 for (const auto& dim : shape) {
64 num_elements *= dim;
65 }
66 buffer = rerun::Collection<TElement>::borrow(data, num_elements);
67 }
68
69 // END of extensions from tensor_data_ext.cpp, start of generated code:
70
71 public:
72 TensorData() = default;
73 };
74} // namespace rerun::datatypes
75
76namespace rerun {
77 template <typename T>
78 struct Loggable;
79
80 /// \private
81 template <>
82 struct Loggable<datatypes::TensorData> {
83 static constexpr std::string_view ComponentType = "rerun.datatypes.TensorData";
84
85 /// Returns the arrow data type this type corresponds to.
86 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
87
88 /// Serializes an array of `rerun::datatypes::TensorData` into an arrow array.
89 static Result<std::shared_ptr<arrow::Array>> to_arrow(
90 const datatypes::TensorData* instances, size_t num_instances
91 );
92
93 /// Fills an arrow array builder with an array of this type.
94 static rerun::Error fill_arrow_array_builder(
95 arrow::StructBuilder* builder, const datatypes::TensorData* elements,
96 size_t num_elements
97 );
98 };
99} // 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:99
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:82
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
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:30
rerun::datatypes::TensorBuffer buffer
The content/data.
Definition tensor_data.hpp:44
rerun::Collection< uint64_t > shape
The shape of the tensor, i.e. the length of each dimension.
Definition tensor_data.hpp:32
std::optional< rerun::Collection< std::string > > names
The names of the dimensions of the tensor (optional).
Definition tensor_data.hpp:41
TensorData(Collection< uint64_t > shape_, const TElement *data)
New tensor data from dimensions and pointer to tensor data.
Definition tensor_data.hpp:60
TensorData(Collection< uint64_t > shape_, datatypes::TensorBuffer buffer_)
New tensor data from shape and tensor buffer.
Definition tensor_data.hpp:51