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
11#include <cstdint>
12#include <memory>
13#include <optional>
14#include <string>
15
16namespace arrow {
17 class Array;
18 class DataType;
19 class StructBuilder;
20} // namespace arrow
21
22namespace rerun::datatypes {
23 /// **Datatype**: An N-dimensional array of numbers.
24 ///
25 /// The number of dimensions and their respective lengths is specified by the `shape` field.
26 /// The dimensions are ordered from outermost to innermost. For example, in the common case of
27 /// a 2D RGB Image, the shape would be `[height, width, channel]`.
28 ///
29 /// These dimensions are combined with an index to look up values from the `buffer` field,
30 /// which stores a contiguous array of typed values.
31 struct TensorData {
32 /// The shape of the tensor, i.e. the length of each dimension.
34
35 /// The names of the dimensions of the tensor (optional).
36 ///
37 /// If set, should be the same length as `datatypes::TensorData::shape`.
38 /// If it has a different length your names may show up improperly,
39 /// and some constructors may produce a warning or even an error.
40 ///
41 /// Example: `["height", "width", "channel", "batch"]`.
42 std::optional<rerun::Collection<std::string>> names;
43
44 /// The content/data.
46
47 public: // START of extensions from tensor_data_ext.cpp:
48 /// New tensor data from shape and tensor buffer.
49 ///
50 /// \param shape_ Shape of the tensor.
51 /// \param buffer_ The tensor buffer containing the tensor's data.
53 : shape(std::move(shape_)), buffer(std::move(buffer_)) {}
54
55 /// New tensor data from dimensions and pointer to tensor data.
56 ///
57 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
58 /// \param shape_ Shape of the tensor. Determines the number of elements expected to be in `data`.
59 /// \param data Target of the pointer must outlive the archetype.
60 template <typename TElement>
61 explicit TensorData(Collection<uint64_t> shape_, const TElement* data)
62 : shape(std::move(shape_)) {
63 size_t num_elements = shape.empty() ? 0 : 1;
64 for (const auto& dim : shape) {
65 num_elements *= dim;
66 }
67 buffer = rerun::Collection<TElement>::borrow(data, num_elements);
68 }
69
70 // END of extensions from tensor_data_ext.cpp, start of generated code:
71
72 public:
73 TensorData() = default;
74 };
75} // namespace rerun::datatypes
76
77namespace rerun {
78 template <typename T>
79 struct Loggable;
80
81 /// \private
82 template <>
83 struct Loggable<datatypes::TensorData> {
84 static constexpr ComponentDescriptor Descriptor = "rerun.datatypes.TensorData";
85
86 /// Returns the arrow data type this type corresponds to.
87 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
88
89 /// Serializes an array of `rerun::datatypes::TensorData` into an arrow array.
90 static Result<std::shared_ptr<arrow::Array>> to_arrow(
91 const datatypes::TensorData* instances, size_t num_instances
92 );
93
94 /// Fills an arrow array builder with an array of this type.
95 static rerun::Error fill_arrow_array_builder(
96 arrow::StructBuilder* builder, const datatypes::TensorData* elements,
97 size_t num_elements
98 );
99 };
100} // 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:99
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:31
rerun::datatypes::TensorBuffer buffer
The content/data.
Definition tensor_data.hpp:45
rerun::Collection< uint64_t > shape
The shape of the tensor, i.e. the length of each dimension.
Definition tensor_data.hpp:33
std::optional< rerun::Collection< std::string > > names
The names of the dimensions of the tensor (optional).
Definition tensor_data.hpp:42
TensorData(Collection< uint64_t > shape_, const TElement *data)
New tensor data from dimensions and pointer to tensor data.
Definition tensor_data.hpp:61
TensorData(Collection< uint64_t > shape_, datatypes::TensorBuffer buffer_)
New tensor data from shape and tensor buffer.
Definition tensor_data.hpp:52