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