Rerun C++ SDK
Loading...
Searching...
No Matches
rerun::archetypes::Tensor Struct Reference

Archetype: A generic n-dimensional Tensor. More...

#include <rerun/archetypes/tensor.hpp>

Public Types

using IndicatorComponent = rerun::components::IndicatorComponent< IndicatorComponentName >
 Indicator component, used to identify the archetype when converting to a list of components.
 

Public Member Functions

 Tensor (Collection< datatypes::TensorDimension > shape, datatypes::TensorBuffer buffer)
 New Tensor from dimensions and tensor buffer.
 
template<typename TElement >
 Tensor (Collection< datatypes::TensorDimension > shape, const TElement *data_)
 New tensor from dimensions and pointer to tensor data.
 
Tensor with_dim_names (Collection< std::string > names) &&
 Update the names of the contained TensorData dimensions.
 
 Tensor (Tensor &&other)=default
 
 Tensor (rerun::components::TensorData _data)
 
size_t num_instances () const
 Returns the number of primary instances of this archetype.
 

Public Attributes

rerun::components::TensorData data
 The tensor data.
 

Static Public Attributes

static constexpr const char IndicatorComponentName [] = "rerun.components.TensorIndicator"
 

Detailed Description

Archetype: A generic n-dimensional Tensor.

Since the underlying rerun::datatypes::TensorData uses rerun::Collection internally, data can be passed in without a copy from raw pointers or by reference from std::vector/std::array/c-arrays. If needed, this "borrow-behavior" can be extended by defining your own rerun::CollectionAdapter.

Example

Simple tensor

image

#include <rerun.hpp>
#include <algorithm> // std::generate
#include <random>
#include <vector>
int main() {
const auto rec = rerun::RecordingStream("rerun_example_tensor");
rec.spawn().exit_on_failure();
std::default_random_engine gen;
// On MSVC uint8_t distributions are not supported.
std::uniform_int_distribution<int> dist(0, 255);
std::vector<uint8_t> data(8 * 6 * 3 * 5);
std::generate(data.begin(), data.end(), [&] { return static_cast<uint8_t>(dist(gen)); });
rec.log(
"tensor",
rerun::Tensor({8, 6, 3, 5}, data).with_dim_names({"width", "height", "channel", "batch"})
);
}
A RecordingStream handles everything related to logging data into Rerun.
Definition recording_stream.hpp:57
Archetype: A generic n-dimensional Tensor.
Definition tensor.hpp:52
rerun::components::TensorData data
The tensor data.
Definition tensor.hpp:54
Tensor with_dim_names(Collection< std::string > names) &&
Update the names of the contained TensorData dimensions.

Constructor & Destructor Documentation

◆ Tensor()

template<typename TElement >
rerun::archetypes::Tensor::Tensor ( Collection< datatypes::TensorDimension shape,
const TElement *  data_ 
)
inlineexplicit

New tensor from dimensions and pointer to tensor data.

Type must be one of the types supported by rerun::datatypes::TensorData.

Parameters
shapeShape of the image. Determines the number of elements expected to be in data.
data_Target of the pointer must outlive the archetype.

Member Function Documentation

◆ with_dim_names()

Tensor rerun::archetypes::Tensor::with_dim_names ( Collection< std::string >  names) &&

Update the names of the contained TensorData dimensions.

Any existing Dimension names will be overwritten.

If too many, or too few names are provided, this function will call Error::handle and then proceed to only update the subset of names that it can.


The documentation for this struct was generated from the following file: