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.
32 : data(rerun::datatypes::TensorData(std::move(shape), std::move(buffer))) {}
33
34 /// New tensor data from dimensions and pointer to tensor data.
35 ///
36 /// Type must be one of the types supported by `rerun::datatypes::TensorData`.
37 /// \param shape Shape of the tensor. Determines the number of elements expected to be in `data_`.
38 /// \param data_ Target of the pointer must outlive the archetype.
39 template <typename TElement>
40 explicit TensorData(Collection<uint64_t> shape, const TElement* data_)
41 : data(rerun::datatypes::TensorData(std::move(shape), data_)) {}
42
43 // END of extensions from tensor_data_ext.cpp, start of generated code:
44
45 public:
46 TensorData() = default;
47
48 TensorData(rerun::datatypes::TensorData data_) : data(std::move(data_)) {}
49
51 data = std::move(data_);
52 return *this;
53 }
54
55 /// Cast to the underlying TensorData datatype
57 return data;
58 }
59 };
60} // namespace rerun::components
61
62namespace rerun {
63 static_assert(sizeof(rerun::datatypes::TensorData) == sizeof(components::TensorData));
64
65 /// \private
66 template <>
67 struct Loggable<components::TensorData> {
68 static constexpr ComponentDescriptor Descriptor = "rerun.components.TensorData";
69
70 /// Returns the arrow data type this type corresponds to.
71 static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
72 return Loggable<rerun::datatypes::TensorData>::arrow_datatype();
73 }
74
75 /// Serializes an array of `rerun::components::TensorData` into an arrow array.
76 static Result<std::shared_ptr<arrow::Array>> to_arrow(
77 const components::TensorData* instances, size_t num_instances
78 ) {
79 if (num_instances == 0) {
80 return Loggable<rerun::datatypes::TensorData>::to_arrow(nullptr, 0);
81 } else if (instances == nullptr) {
82 return rerun::Error(
83 ErrorCode::UnexpectedNullArgument,
84 "Passed array instances is null when num_elements> 0."
85 );
86 } else {
87 return Loggable<rerun::datatypes::TensorData>::to_arrow(
88 &instances->data,
89 num_instances
90 );
91 }
92 }
93 };
94} // 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:96
All built-in components. See Types in the Rerun manual.
Definition rerun.hpp:79
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(rerun::Collection< uint64_t > shape, rerun::datatypes::TensorBuffer buffer)
New tensor data from shape and tensor buffer.
Definition tensor_data.hpp:31
TensorData(Collection< uint64_t > shape, const TElement *data_)
New tensor data from dimensions and pointer to tensor data.
Definition tensor_data.hpp:40
Datatype: The underlying storage for archetypes::Tensor.
Definition tensor_buffer.hpp:99
Datatype: An N-dimensional array of numbers.
Definition tensor_data.hpp:31