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/components/tensor_data.fbs".
3
4#pragma once
5
6#include "../component_descriptor.hpp"
7#include "../datatypes/tensor_data.hpp"
8#include "../result.hpp"
9
10#include <cstdint>
11#include <memory>
12#include <utility>
13
14namespace rerun::components {
15 /// **Component**: An N-dimensional array of numbers.
16 ///
17 /// The number of dimensions and their respective lengths is specified by the `shape` field.
18 /// The dimensions are ordered from outermost to innermost. For example, in the common case of
19 /// a 2D RGB Image, the shape would be `[height, width, channel]`.
20 ///
21 /// These dimensions are combined with an index to look up values from the `buffer` field,
22 /// which stores a contiguous array of typed values.
23 struct TensorData {
25
26 public: // START of extensions from tensor_data_ext.cpp:
27 /// New tensor data from shape and tensor buffer.
28 ///
29 /// \param shape Shape of the tensor.
30 /// \param buffer The tensor buffer containing the tensor's data.
34 )
35 : data(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {}
36
37 /// New tensor data from dimensions and pointer to tensor data.
38 ///
39 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
40 /// \param shape Shape of the tensor. Determines the number of elements expected to be in `data_`.
41 /// \param data_ Target of the pointer must outlive the archetype.
42 template <typename TElement>
43 explicit TensorData(Collection<datatypes::TensorDimension> shape, const TElement* data_)
44 : data(rerun::datatypes::TensorData(std::move(shape), data_)) {}
45
46 // END of extensions from tensor_data_ext.cpp, start of generated code:
47
48 public:
49 TensorData() = default;
50
51 TensorData(rerun::datatypes::TensorData data_) : data(std::move(data_)) {}
52
54 data = std::move(data_);
55 return *this;
56 }
57
58 /// Cast to the underlying TensorData datatype
60 return data;
61 }
62 };
63} // namespace rerun::components
64
65namespace rerun {
66 static_assert(sizeof(rerun::datatypes::TensorData) == sizeof(components::TensorData));
67
68 /// \private
69 template <>
70 struct Loggable<components::TensorData> {
71 static constexpr ComponentDescriptor Descriptor = "rerun.components.TensorData";
72
73 /// Returns the arrow data type this type corresponds to.
74 static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
75 return Loggable<rerun::datatypes::TensorData>::arrow_datatype();
76 }
77
78 /// Serializes an array of `rerun::components::TensorData` into an arrow array.
79 static Result<std::shared_ptr<arrow::Array>> to_arrow(
80 const components::TensorData* instances, size_t num_instances
81 ) {
82 if (num_instances == 0) {
83 return Loggable<rerun::datatypes::TensorData>::to_arrow(nullptr, 0);
84 } else if (instances == nullptr) {
85 return rerun::Error(
86 ErrorCode::UnexpectedNullArgument,
87 "Passed array instances is null when num_elements> 0."
88 );
89 } else {
90 return Loggable<rerun::datatypes::TensorData>::to_arrow(
91 &instances->data,
92 num_instances
93 );
94 }
95 }
96 };
97} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:95
All built-in components. See Types in the Rerun manual.
Definition rerun.hpp:80
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Component: An N-dimensional array of numbers.
Definition tensor_data.hpp:23
TensorData(Collection< datatypes::TensorDimension > shape, const TElement *data_)
New tensor data from dimensions and pointer to tensor data.
Definition tensor_data.hpp:43
TensorData(rerun::Collection< rerun::datatypes::TensorDimension > shape, rerun::datatypes::TensorBuffer buffer)
New tensor data from shape and tensor buffer.
Definition tensor_data.hpp:31
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:99
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:30