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

Archetype: An N-dimensional array of numbers. 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

RR_DISABLE_MAYBE_UNINITIALIZED_PUSH Tensor (Collection< uint64_t > shape, datatypes::TensorBuffer buffer)
 New Tensor from dimensions and tensor buffer.
 
template<typename TElement >
RR_DISABLE_MAYBE_UNINITIALIZED_POP Tensor (Collection< uint64_t > 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 (const Tensor &other)=default
 
Tensoroperator= (const Tensor &other)=default
 
Tensoroperator= (Tensor &&other)=default
 
 Tensor (rerun::components::TensorData _data)
 
Tensor with_data (const rerun::components::TensorData &_data) &&
 The tensor data.
 
Tensor with_many_data (const Collection< rerun::components::TensorData > &_data) &&
 This method makes it possible to pack multiple data in a single component batch.
 
Tensor with_value_range (const rerun::components::ValueRange &_value_range) &&
 The expected range of values.
 
Tensor with_many_value_range (const Collection< rerun::components::ValueRange > &_value_range) &&
 This method makes it possible to pack multiple value_range in a single component batch.
 
Collection< ComponentColumncolumns (const Collection< uint32_t > &lengths_)
 Partitions the component data into multiple sub-batches.
 
Collection< ComponentColumncolumns ()
 Partitions the component data into unit-length sub-batches.
 

Static Public Member Functions

static Tensor update_fields ()
 Update only some specific fields of a Tensor.
 
static Tensor clear_fields ()
 Clear all the fields of a Tensor.
 

Public Attributes

std::optional< ComponentBatchdata
 The tensor data.
 
std::optional< ComponentBatchvalue_range
 The expected range of values.
 

Static Public Attributes

static constexpr const char IndicatorComponentName [] = "rerun.components.TensorIndicator"
 
static constexpr const char ArchetypeName [] = "rerun.archetypes.Tensor"
 The name of the archetype as used in ComponentDescriptors.
 
static constexpr auto Descriptor_data
 ComponentDescriptor for the data field.
 
static constexpr auto Descriptor_value_range
 ComponentDescriptor for the value_range field.
 

Detailed Description

Archetype: An N-dimensional array of numbers.

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:60
Archetype: An N-dimensional array of numbers.
Definition tensor.hpp:55
Tensor with_dim_names(Collection< std::string > names) &&
Update the names of the contained TensorData dimensions.
std::optional< ComponentBatch > data
The tensor data.
Definition tensor.hpp:57

Constructor & Destructor Documentation

◆ Tensor()

template<typename TElement >
RR_DISABLE_MAYBE_UNINITIALIZED_POP rerun::archetypes::Tensor::Tensor ( Collection< uint64_t >  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.

◆ with_many_data()

Tensor rerun::archetypes::Tensor::with_many_data ( const Collection< rerun::components::TensorData > &  _data) &&
inline

This method makes it possible to pack multiple data in a single component batch.

This only makes sense when used in conjunction with columns. with_data should be used when logging a single row's worth of data.

◆ with_value_range()

Tensor rerun::archetypes::Tensor::with_value_range ( const rerun::components::ValueRange _value_range) &&
inline

The expected range of values.

This is typically the expected range of valid values. Everything outside of the range is clamped to the range for the purpose of colormpaping. Any colormap applied for display, will map this range.

If not specified, the range will be automatically estimated from the data. Note that the Viewer may try to guess a wider range than the minimum/maximum of values in the contents of the tensor. E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0, the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.

◆ with_many_value_range()

Tensor rerun::archetypes::Tensor::with_many_value_range ( const Collection< rerun::components::ValueRange > &  _value_range) &&
inline

This method makes it possible to pack multiple value_range in a single component batch.

This only makes sense when used in conjunction with columns. with_value_range should be used when logging a single row's worth of data.

◆ columns() [1/2]

Collection< ComponentColumn > rerun::archetypes::Tensor::columns ( const Collection< uint32_t > &  lengths_)

Partitions the component data into multiple sub-batches.

Specifically, this transforms the existing ComponentBatch data into ComponentColumns instead, via ComponentBatch::partitioned.

This makes it possible to use RecordingStream::send_columns to send columnar data directly into Rerun.

The specified lengths must sum to the total length of the component batch.

◆ columns() [2/2]

Collection< ComponentColumn > rerun::archetypes::Tensor::columns ( )

Partitions the component data into unit-length sub-batches.

This is semantically similar to calling columns with std::vector<uint32_t>(n, 1), where n is automatically guessed.

Member Data Documentation

◆ value_range

std::optional<ComponentBatch> rerun::archetypes::Tensor::value_range

The expected range of values.

This is typically the expected range of valid values. Everything outside of the range is clamped to the range for the purpose of colormpaping. Any colormap applied for display, will map this range.

If not specified, the range will be automatically estimated from the data. Note that the Viewer may try to guess a wider range than the minimum/maximum of values in the contents of the tensor. E.g. if all values are positive, some bigger than 1.0 and all smaller than 255.0, the Viewer will guess that the data likely came from an 8bit image, thus assuming a range of 0-255.

◆ Descriptor_data

constexpr auto rerun::archetypes::Tensor::Descriptor_data
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "data",
Loggable<rerun::components::TensorData>::Descriptor.component_name
)
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition tensor.hpp:78

ComponentDescriptor for the data field.

◆ Descriptor_value_range

constexpr auto rerun::archetypes::Tensor::Descriptor_value_range
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "value_range",
Loggable<rerun::components::ValueRange>::Descriptor.component_name
)

ComponentDescriptor for the value_range field.


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