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#include "tensor_dimension.hpp"
10
11#include <cstdint>
12#include <memory>
13
14namespace arrow {
15 class Array;
16 class DataType;
17 class StructBuilder;
18} // namespace arrow
19
20namespace rerun::datatypes {
21 /// **Datatype**: An N-dimensional array of numbers.
22 ///
23 /// The number of dimensions and their respective lengths is specified by the `shape` field.
24 /// The dimensions are ordered from outermost to innermost. For example, in the common case of
25 /// a 2D RGB Image, the shape would be `[height, width, channel]`.
26 ///
27 /// These dimensions are combined with an index to look up values from the `buffer` field,
28 /// which stores a contiguous array of typed values.
29 struct TensorData {
30 /// The shape of the tensor, including optional names for each dimension.
32
33 /// The content/data.
35
36 public: // START of extensions from tensor_data_ext.cpp:
37 /// New tensor data from shape and tensor buffer.
38 ///
39 /// \param shape_ Shape of the tensor.
40 /// \param buffer_ The tensor buffer containing the tensor's data.
43 )
44 : shape(std::move(shape_)), buffer(std::move(buffer_)) {}
45
46 /// New tensor data from dimensions and pointer to tensor data.
47 ///
48 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
49 /// \param shape_ Shape of the tensor. Determines the number of elements expected to be in `data`.
50 /// \param data Target of the pointer must outlive the archetype.
51 template <typename TElement>
52 explicit TensorData(Collection<datatypes::TensorDimension> shape_, const TElement* data)
53 : shape(std::move(shape_)) {
54 size_t num_elements = shape.empty() ? 0 : 1;
55 for (const auto& dim : shape) {
56 num_elements *= dim.size;
57 }
58 buffer = rerun::Collection<TElement>::borrow(data, num_elements);
59 }
60
61 // END of extensions from tensor_data_ext.cpp, start of generated code:
62
63 public:
64 TensorData() = default;
65 };
66} // namespace rerun::datatypes
67
68namespace rerun {
69 template <typename T>
70 struct Loggable;
71
72 /// \private
73 template <>
74 struct Loggable<datatypes::TensorData> {
75 static constexpr const char Name[] = "rerun.datatypes.TensorData";
76
77 /// Returns the arrow data type this type corresponds to.
78 static const std::shared_ptr<arrow::DataType>& arrow_datatype();
79
80 /// Serializes an array of `rerun::datatypes::TensorData` into an arrow array.
81 static Result<std::shared_ptr<arrow::Array>> to_arrow(
82 const datatypes::TensorData* instances, size_t num_instances
83 );
84
85 /// Fills an arrow array builder with an array of this type.
86 static rerun::Error fill_arrow_array_builder(
87 arrow::StructBuilder* builder, const datatypes::TensorData* elements,
88 size_t num_elements
89 );
90 };
91} // 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:151
bool empty() const
Returns true if the collection is empty.
Definition collection.hpp:286
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:91
All built-in datatypes. See Types in the Rerun manual.
Definition rerun.hpp:78
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:98
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:29
TensorData(Collection< rerun::datatypes::TensorDimension > shape_, datatypes::TensorBuffer buffer_)
New tensor data from shape and tensor buffer.
Definition tensor_data.hpp:41
rerun::datatypes::TensorBuffer buffer
The content/data.
Definition tensor_data.hpp:34
TensorData(Collection< datatypes::TensorDimension > shape_, const TElement *data)
New tensor data from dimensions and pointer to tensor data.
Definition tensor_data.hpp:52
rerun::Collection< rerun::datatypes::TensorDimension > shape
The shape of the tensor, including optional names for each dimension.
Definition tensor_data.hpp:31