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 {
24class TensorCollection;
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;
36class TensorCollection;
37class TensorCollectionData;
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();
57
58 /// Constructor initializing all members
59 Tensor(std::int32_t elementType);
60
61 /// copy constructor
62 Tensor(const Tensor& other) = default;
63
64 /// copy-assignment operator
65 Tensor& operator=(Tensor other);
66
67 /// create a mutable deep-copy of the object with identical relations
68 /// if cloneRelations=false, the relations are not cloned and will be empty
69 MutableTensor clone(bool cloneRelations=true) const;
70
71 /// destructor
72 ~Tensor() = default;
73
74 /// converting constructor from mutable object
75 Tensor(const MutableTensor& other);
76
77 static Tensor makeEmpty();
78
79public:
80
81 static constexpr auto typeName = "edm4eic::Tensor";
82
83 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
84 std::int32_t getElementType() const;
85
86
87
88 std::size_t shape_size() const;
89 std::int64_t getShape(std::size_t) const;
90 std::vector<std::int64_t>::const_iterator shape_begin() const;
91 std::vector<std::int64_t>::const_iterator shape_end() const;
92 podio::RelationRange<std::int64_t> getShape() const;
93 std::size_t floatData_size() const;
94 float getFloatData(std::size_t) const;
95 std::vector<float>::const_iterator floatData_begin() const;
96 std::vector<float>::const_iterator floatData_end() const;
97 podio::RelationRange<float> getFloatData() const;
98 std::size_t int64Data_size() const;
99 std::int64_t getInt64Data(std::size_t) const;
100 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
101 std::vector<std::int64_t>::const_iterator int64Data_end() const;
102 podio::RelationRange<std::int64_t> getInt64Data() const;
103
104
105 /// check whether the object is actually available
106 bool isAvailable() const;
107 /// disconnect from TensorObj instance
108 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
109
110 bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
111 bool operator==(const MutableTensor& other) const;
112
113 bool operator!=(const Tensor& other) const { return !(*this == other); }
114 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
115
116 // less comparison operator, so that objects can be e.g. stored in sets.
117 bool operator<(const Tensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
118
119 podio::ObjectID id() const { return getObjectID(); }
120
121 const podio::ObjectID getObjectID() const;
122
123 friend void swap(Tensor& a, Tensor& b) {
124 using std::swap;
125 swap(a.m_obj, b.m_obj); // swap out the internal pointers
126 }
127
128private:
129 /// constructor from existing TensorObj
130 explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
131 Tensor(TensorObj* obj);
132
133 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
134};
135
136std::ostream& operator<<(std::ostream& o, const Tensor& value);
137
138#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
139void to_json(nlohmann::json& j, const Tensor& value);
140#endif
141
142
143} // namespace edm4eic
144
145
146#endif
Definition MutableTensor.h:35
Definition TensorCollectionData.h:30
Definition TensorCollection.h:91
Definition TensorCollection.h:36
Definition Tensor.h:43
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition Tensor.cc:153
MutableTensor clone(bool cloneRelations=true) const
Definition Tensor.cc:33
bool isAvailable() const
check whether the object is actually available
Definition Tensor.cc:188
std::vector< float >::const_iterator floatData_begin() const
Definition Tensor.cc:121
podio::RelationRange< std::int64_t > getInt64Data() const
Definition Tensor.cc:176
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition Tensor.cc:159
std::int32_t getElementType() const
Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition Tensor.cc:85
std::size_t floatData_size() const
Definition Tensor.cc:133
podio::RelationRange< float > getFloatData() const
Definition Tensor.cc:144
std::vector< std::int64_t >::const_iterator shape_end() const
Definition Tensor.cc:95
static constexpr auto typeName
Definition Tensor.h:81
podio::ObjectID id() const
Definition Tensor.h:119
bool operator<(const Tensor &other) const
Definition Tensor.h:117
friend class TensorCollection
Definition Tensor.h:46
friend void swap(Tensor &a, Tensor &b)
Definition Tensor.h:123
std::vector< float >::const_iterator floatData_end() const
Definition Tensor.cc:127
std::size_t shape_size() const
Definition Tensor.cc:101
Tensor()
default constructor
Definition Tensor.cc:20
bool operator==(const Tensor &other) const
Definition Tensor.h:110
const podio::ObjectID getObjectID() const
Definition Tensor.cc:192
friend class MutableTensor
Definition Tensor.h:45
void unlink()
disconnect from TensorObj instance
Definition Tensor.h:108
podio::RelationRange< std::int64_t > getShape() const
Definition Tensor.cc:112
std::size_t int64Data_size() const
Definition Tensor.cc:165
Tensor & operator=(Tensor other)
copy-assignment operator
Definition Tensor.cc:28
bool operator!=(const MutableTensor &other) const
Definition Tensor.h:114
Tensor(const Tensor &other)=default
copy constructor
bool operator!=(const Tensor &other) const
Definition Tensor.h:113
static Tensor makeEmpty()
Definition Tensor.cc:81
~Tensor()=default
destructor
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition Tensor.cc:89
Definition TensorObj.h:19
Definition CalorimeterHit.cc:17
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:103
Definition CalorimeterHit.h:31
OrderKey getOrderKey(const edm4eic::CalorimeterHit &obj)
Definition CalorimeterHit.cc:150