EDM4eic
EIC data model
Loading...
Searching...
No Matches
Tensor.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_Tensor_H
4#define EDM4EIC_Tensor_H
5
6#include "edm4eic/TensorObj.h"
7
8#include "podio/RelationRange.h"
9#include <cstdint>
10#include <vector>
11
12#include "podio/utilities/MaybeSharedPtr.h"
13#include "podio/detail/OrderKey.h"
14
15#include <ostream>
16#include <cstdint>
17
18#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
19#include "nlohmann/json_fwd.hpp"
20#endif
21
22// forward declarations
23namespace edm4eic {
25}
26
27
28namespace podio::detail {
29// Internal function used in less comparison operators of the datatypes and interface types
30OrderKey getOrderKey(const edm4eic::Tensor& obj);
31};
32
33namespace edm4eic {
34
35class MutableTensor;
38
39/** @class Tensor
40 * Tensor type for use in training in inference of ML models
41 * @author: D. Kalinkin
42 */
43class Tensor {
44
45 friend class MutableTensor;
46 friend class TensorCollection;
49 friend podio::detail::OrderKey podio::detail::getOrderKey(const Tensor & obj);
50
51public:
54
55 /// default constructor
56 Tensor() = default;
57
58 /// Constructor initializing all members
59 Tensor(const std::int32_t elementType);
60
61 /// copy constructor
62 Tensor(const Tensor& other) noexcept = default;
63
64 /// move constructor
65 Tensor(Tensor&& other) noexcept = default;
66
67 /// copy-assignment operator
68 Tensor& operator=(Tensor other) &; // Rebind this to other's internal object
69 Tensor& operator=(Tensor other) && = delete; // Prevent rebinding temporary as the changes wouldn't persist
70
71 /// create a mutable deep-copy of the object with identical relations
72 /// if cloneRelations=false, the relations are not cloned and will be empty
73 MutableTensor clone(bool cloneRelations=true) const;
74
75 /// destructor
76 ~Tensor() = default;
77
78 /// converting constructor from mutable object
79 Tensor(const MutableTensor& other);
80
81 static Tensor makeEmpty();
82
83public:
84
85 static constexpr std::string_view typeName = "edm4eic::Tensor";
86
87 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
88 std::int32_t getElementType() const;
89
90
91
92 std::size_t shape_size() const;
93 std::int64_t getShape(std::size_t) const;
94 std::vector<std::int64_t>::const_iterator shape_begin() const;
95 std::vector<std::int64_t>::const_iterator shape_end() const;
96 podio::RelationRange<std::int64_t> getShape() const;
97 std::size_t floatData_size() const;
98 float getFloatData(std::size_t) const;
99 std::vector<float>::const_iterator floatData_begin() const;
100 std::vector<float>::const_iterator floatData_end() const;
101 podio::RelationRange<float> getFloatData() const;
102 std::size_t int64Data_size() const;
103 std::int64_t getInt64Data(std::size_t) const;
104 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
105 std::vector<std::int64_t>::const_iterator int64Data_end() const;
106 podio::RelationRange<std::int64_t> getInt64Data() const;
107
108
109 /// check whether the object is actually available
110 bool isAvailable() const;
111 /// disconnect from TensorObj instance
112 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
113
114 constexpr bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
115 bool operator==(const MutableTensor& other) const;
116
117 constexpr bool operator!=(const Tensor& other) const { return !(*this == other); }
118 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
119
120 // less comparison operator, so that objects can be e.g. stored in sets.
121 bool operator<(const Tensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
122
123 podio::ObjectID id() const { return getObjectID(); }
124
125 const podio::ObjectID getObjectID() const;
126
127 friend std::hash<Tensor>;
128
129 friend void swap(Tensor& a, Tensor& b) {
130 using std::swap;
131 swap(a.m_obj, b.m_obj); // swap out the internal pointers
132 }
133
134private:
135 /// constructor from existing TensorObj
136 explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
137 Tensor(TensorObj* obj);
138
139 podio::utils::MaybeSharedPtr<TensorObj> m_obj{new TensorObj{}, podio::utils::MarkOwned};
140};
141
142std::ostream& operator<<(std::ostream& o, const Tensor& value);
143
144#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
145void to_json(nlohmann::json& j, const Tensor& value);
146#endif
147
148
149} // namespace edm4eic
150
151
152
153template<>
154struct std::hash<edm4eic::Tensor> {
155 std::size_t operator()(const edm4eic::Tensor& obj) const {
156 return std::hash<edm4eic::TensorObj*>{}(obj.m_obj.get());
157 }
158};
159
160
161// This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
162// until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
163// and https://github.com/AIDASoft/podio/issues/770
164#if defined(__clang__)
165 #pragma clang diagnostic push
166 #pragma clang diagnostic ignored "-Wunknown-warning-option"
167 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
168 #pragma clang diagnostic ignored "-Wdeprecated"
169constexpr std::string_view edm4eic::Tensor::typeName;
170 #pragma clang diagnostic pop
171#elif defined(__GNUC__)
172 #pragma GCC diagnostic push
173 #pragma GCC diagnostic ignored "-Wdeprecated"
174constexpr std::string_view edm4eic::Tensor::typeName;
175 #pragma GCC diagnostic pop
176#endif
177
178
179#endif
Definition MutableTensor.h:35
Definition TensorCollectionData.h:31
Definition TensorCollection.h:139
Definition Tensor.h:43
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition Tensor.cc:149
MutableTensor clone(bool cloneRelations=true) const
Definition Tensor.cc:29
bool isAvailable() const
check whether the object is actually available
Definition Tensor.cc:184
std::vector< float >::const_iterator floatData_begin() const
Definition Tensor.cc:117
podio::RelationRange< std::int64_t > getInt64Data() const
Definition Tensor.cc:172
Tensor(const Tensor &other) noexcept=default
copy constructor
static constexpr std::string_view typeName
Definition Tensor.h:85
MutableTensor mutable_type
Definition Tensor.h:52
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition Tensor.cc:155
std::int32_t getElementType() const
Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition Tensor.cc:81
std::size_t floatData_size() const
Definition Tensor.cc:129
Tensor & operator=(Tensor other) &&=delete
podio::RelationRange< float > getFloatData() const
Definition Tensor.cc:140
TensorCollection collection_type
Definition Tensor.h:53
constexpr bool operator!=(const Tensor &other) const
Definition Tensor.h:117
std::vector< std::int64_t >::const_iterator shape_end() const
Definition Tensor.cc:91
podio::ObjectID id() const
Definition Tensor.h:123
bool operator<(const Tensor &other) const
Definition Tensor.h:121
friend class TensorCollectionIterator
Definition Tensor.h:48
friend class TensorCollection
Definition Tensor.h:46
friend void swap(Tensor &a, Tensor &b)
Definition Tensor.h:129
std::vector< float >::const_iterator floatData_end() const
Definition Tensor.cc:123
std::size_t shape_size() const
Definition Tensor.cc:97
Tensor & operator=(Tensor other) &
copy-assignment operator
Definition Tensor.cc:24
const podio::ObjectID getObjectID() const
Definition Tensor.cc:188
friend class MutableTensor
Definition Tensor.h:45
void unlink()
disconnect from TensorObj instance
Definition Tensor.h:112
podio::RelationRange< std::int64_t > getShape() const
Definition Tensor.cc:108
std::size_t int64Data_size() const
Definition Tensor.cc:161
bool operator!=(const MutableTensor &other) const
Definition Tensor.h:118
constexpr bool operator==(const Tensor &other) const
Definition Tensor.h:114
static Tensor makeEmpty()
Definition Tensor.cc:77
~Tensor()=default
destructor
Tensor(Tensor &&other) noexcept=default
move constructor
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition Tensor.cc:85
Tensor()=default
default constructor
Definition TensorObj.h:19
Definition ArrowMapper.cc:63
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:99
Definition CalorimeterHit.h:31
OrderKey getOrderKey(const edm4eic::CalorimeterHit &obj)
Definition CalorimeterHit.cc:146
std::size_t operator()(const edm4eic::Tensor &obj) const
Definition Tensor.h:155