EyeAI
Loading...
Searching...
No Matches
TensorBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <span>
6#include <variant>
7#include <vector>
8
11template<typename T, typename Format, Format FORMAT_CONSTANT>
13 explicit TensorBuffer(
14 std::variant<std::shared_ptr<std::vector<T>>, std::span<T>> data
15 )
16 : data_container(std::move(data)) {}
17 explicit TensorBuffer(std::span<T> data) : data_container(data) {}
18 explicit TensorBuffer(std::shared_ptr<std::vector<T>> data)
19 : data_container(std::move(data)) {}
20 explicit TensorBuffer(std::vector<T>&& data)
21 : data_container(std::make_shared<std::vector<T>>(std::move(data))) {}
22
23 TensorBuffer(const TensorBuffer&) = default;
27 ~TensorBuffer() = default;
28
29 template<Format NEW_FORMAT>
31 return TensorBuffer<T, Format, NEW_FORMAT>(data_container);
32 }
33
34 [[nodiscard]] std::span<T> data() {
35 return std::visit(
36 [](auto& data_container) -> std::span<T> {
37 using data_container_t = std::decay_t<decltype(data_container)>;
38
39 if constexpr (std::is_same_v<
40 data_container_t,
41 std::shared_ptr<std::vector<T>>>) {
42 return std::span<T>(*data_container);
43 } else if constexpr (std::is_same_v<
44 data_container_t, std::span<T>>) {
45 return data_container;
46 }
47 },
48 data_container
49 );
50 }
51 [[nodiscard]] std::span<const T> data() const {
52 return std::visit(
53 [](const auto& data_container) -> std::span<const T> {
54 using data_container_t = std::decay_t<decltype(data_container)>;
55
56 if constexpr (std::is_same_v<
57 data_container_t,
58 std::shared_ptr<std::vector<T>>>) {
59 return std::span<const T>(*data_container);
60 } else if constexpr (std::is_same_v<
61 data_container_t, std::span<T>>) {
62 return data_container;
63 }
64 },
65 data_container
66 );
67 }
68
69 private:
70 std::variant<std::shared_ptr<std::vector<T>>, std::span<T>> data_container;
71};
72
102
103std::string_view format_float_tensor_format(FloatTensorFormat format);
104
105template<FloatTensorFormat FORMAT>
std::string_view format_float_tensor_format(FloatTensorFormat format)
Definition TensorBuffer.cpp:3
FloatTensorFormat
Definition TensorBuffer.hpp:73
@ RelativeDepth
1 float per pixel for relative depth in range [0.f, 1.f]
Definition TensorBuffer.hpp:83
@ YoloOutput
special yolo output of detected objects and their confidence
Definition TensorBuffer.hpp:96
@ ImageRGB255
3 floats for r, g, b, all in range [0.f, 255.f]
Definition TensorBuffer.hpp:77
@ MiDaSImageRGB
3 floats for r, g, b, each in the range [-1.f, 1.f]
Definition TensorBuffer.hpp:79
@ Rel2AbsDepthCoefficientOutput
Definition TensorBuffer.hpp:92
@ NLPInput
input string for nlp
Definition TensorBuffer.hpp:100
@ RawRelativeDepth
1 float per pixel for relative depth, all values possible
Definition TensorBuffer.hpp:85
@ NLPOutput
output for nlp model
Definition TensorBuffer.hpp:98
@ ImageRGB
3 floats for r, g, b, all in range [0.f, 1.f]
Definition TensorBuffer.hpp:75
@ YoloImageRGB
3 floats for r, g, b, all in range [0.f, 1.f]
Definition TensorBuffer.hpp:81
@ MetricDepth
1 float per pixel for metric depth in meters
Definition TensorBuffer.hpp:94
@ Rel2AbsDepthInput
Definition TensorBuffer.hpp:89
TensorBuffer< float, FloatTensorFormat, FORMAT > FloatTensorBuffer
Definition TensorBuffer.hpp:106
Definition TensorBuffer.hpp:12
~TensorBuffer()=default
TensorBuffer(TensorBuffer &&)=default
TensorBuffer(std::shared_ptr< std::vector< T > > data)
Definition TensorBuffer.hpp:18
TensorBuffer(const TensorBuffer &)=default
std::span< const T > data() const
Definition TensorBuffer.hpp:51
TensorBuffer(std::span< T > data)
Definition TensorBuffer.hpp:17
std::span< float > data()
Definition TensorBuffer.hpp:34
TensorBuffer(std::vector< T > &&data)
Definition TensorBuffer.hpp:20
TensorBuffer< T, Format, NEW_FORMAT > convert_format() const
Definition TensorBuffer.hpp:30
TensorBuffer(std::variant< std::shared_ptr< std::vector< T > >, std::span< T > > data)
Definition TensorBuffer.hpp:13
TensorBuffer & operator=(const TensorBuffer &)=default
TensorBuffer & operator=(TensorBuffer &&)=default