EDM4eic
EIC data model
Loading...
Searching...
No Matches
MutableTensor.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_MutableTensor_H
4#define EDM4EIC_MutableTensor_H
5
6#include "edm4eic/TensorObj.h"
7// Make the immutable class available from its mutable version but not vice versa
8#include "edm4eic/Tensor.h"
9
10#include "podio/RelationRange.h"
11#include <cstdint>
12#include <vector>
13
14#include "podio/utilities/MaybeSharedPtr.h"
15
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 edm4eic {
29
30
31/** @class MutableTensor
32 * Tensor type for use in training in inference of ML models
33 * @author: D. Kalinkin
34 */
36
37 friend class TensorCollection;
39 friend class Tensor;
40
41public:
44
45 /// default constructor
47
48 /// Constructor initializing all members
49 MutableTensor(const std::int32_t elementType);
50
51 /// copy constructor
52 MutableTensor(const MutableTensor& other) = default;
53
54 /// copy-assignment operator
55 MutableTensor& operator=(MutableTensor other) &; // Rebind this to other's internal object
56 MutableTensor& operator=(MutableTensor other) && = delete; // Prevent rebinding temporary as the changes wouldn't persist
57
58 /// create a mutable deep-copy of the object with identical relations
59 /// if cloneRelations=false, the relations are not cloned and will be empty
60 MutableTensor clone(bool cloneRelations=true) const;
61
62 /// destructor
63 ~MutableTensor() = default;
64
65
66public:
67
68 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
69 std::int32_t getElementType() const;
70
71
72
73 /// Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
74 void setElementType(const std::int32_t elementType);
75 /// Get mutable reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
76 std::int32_t& getElementType();
77 /// Get reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
78 [[deprecated("use getElementType instead")]]
79 std::int32_t& elementType();
80
81
82
83 void addToShape(const std::int64_t&);
84 std::size_t shape_size() const;
85 std::int64_t getShape(std::size_t) const;
86 std::vector<std::int64_t>::const_iterator shape_begin() const;
87 std::vector<std::int64_t>::const_iterator shape_end() const;
88 podio::RelationRange<std::int64_t> getShape() const;
89 void addToFloatData(const float&);
90 std::size_t floatData_size() const;
91 float getFloatData(std::size_t) const;
92 std::vector<float>::const_iterator floatData_begin() const;
93 std::vector<float>::const_iterator floatData_end() const;
94 podio::RelationRange<float> getFloatData() const;
95 void addToInt64Data(const std::int64_t&);
96 std::size_t int64Data_size() const;
97 std::int64_t getInt64Data(std::size_t) const;
98 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
99 std::vector<std::int64_t>::const_iterator int64Data_end() const;
100 podio::RelationRange<std::int64_t> getInt64Data() const;
101
102
103
104 /// check whether the object is actually available
105 bool isAvailable() const;
106 /// disconnect from TensorObj instance
107 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
108
109 bool operator==(const MutableTensor& other) const { return m_obj == other.m_obj; }
110 bool operator==(const Tensor& other) const;
111
112 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
113 bool operator!=(const Tensor& other) const { return !(*this == other); }
114
115 // less comparison operator, so that objects can be e.g. stored in sets.
116 bool operator<(const MutableTensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
117
118 podio::ObjectID id() const { return getObjectID(); }
119
120 const podio::ObjectID getObjectID() const;
121
122 friend std::hash<MutableTensor>;
123
124 friend void swap(MutableTensor& a, MutableTensor& b) {
125 using std::swap;
126 swap(a.m_obj, b.m_obj); // swap out the internal pointers
127 }
128
129private:
130 /// constructor from existing TensorObj
131 explicit MutableTensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
132
133 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
134};
135
136#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
137void to_json(nlohmann::json& j, const MutableTensor& value);
138#endif
139
140
141} // namespace edm4eic
142
143
144
145template<>
146struct std::hash<edm4eic::MutableTensor> {
147 std::size_t operator()(const edm4eic::MutableTensor& obj) const {
148 return std::hash<edm4eic::TensorObj*>{}(obj.m_obj.get());
149 }
150};
151
152
153#endif
Definition MutableTensor.h:35
bool isAvailable() const
check whether the object is actually available
Definition MutableTensor.cc:171
TensorCollection collection_type
Definition MutableTensor.h:43
friend class Tensor
Definition MutableTensor.h:39
MutableTensor(const MutableTensor &other)=default
copy constructor
bool operator<(const MutableTensor &other) const
Definition MutableTensor.h:116
std::vector< float >::const_iterator floatData_end() const
Definition MutableTensor.cc:105
bool operator!=(const MutableTensor &other) const
Definition MutableTensor.h:112
bool operator!=(const Tensor &other) const
Definition MutableTensor.h:113
MutableTensor clone(bool cloneRelations=true) const
Definition MutableTensor.cc:31
void addToInt64Data(const std::int64_t &)
Definition MutableTensor.cc:130
void addToFloatData(const float &)
Definition MutableTensor.cc:94
podio::ObjectID id() const
Definition MutableTensor.h:118
friend class TensorCollection
Definition MutableTensor.h:37
MutableTensor()
default constructor
Definition MutableTensor.cc:18
MutableTensor & operator=(MutableTensor other) &
copy-assignment operator
Definition MutableTensor.cc:26
podio::RelationRange< std::int64_t > getInt64Data() const
Definition MutableTensor.cc:158
Tensor object_type
Definition MutableTensor.h:42
friend void swap(MutableTensor &a, MutableTensor &b)
Definition MutableTensor.h:124
podio::RelationRange< float > getFloatData() const
Definition MutableTensor.cc:122
std::size_t floatData_size() const
Definition MutableTensor.cc:111
MutableTensor & operator=(MutableTensor other) &&=delete
std::int32_t getElementType() const
Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition MutableTensor.cc:50
~MutableTensor()=default
destructor
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition MutableTensor.cc:141
podio::RelationRange< std::int64_t > getShape() const
Definition MutableTensor.cc:86
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition MutableTensor.cc:135
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition MutableTensor.cc:63
bool operator==(const MutableTensor &other) const
Definition MutableTensor.h:109
std::size_t int64Data_size() const
Definition MutableTensor.cc:147
void setElementType(const std::int32_t elementType)
Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64.
Definition MutableTensor.cc:53
friend class TensorMutableCollectionIterator
Definition MutableTensor.h:38
std::int32_t & elementType()
Get reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition MutableTensor.cc:55
std::vector< float >::const_iterator floatData_begin() const
Definition MutableTensor.cc:99
std::size_t shape_size() const
Definition MutableTensor.cc:75
void addToShape(const std::int64_t &)
Definition MutableTensor.cc:58
std::vector< std::int64_t >::const_iterator shape_end() const
Definition MutableTensor.cc:69
void unlink()
disconnect from TensorObj instance
Definition MutableTensor.h:107
const podio::ObjectID getObjectID() const
Definition MutableTensor.cc:175
Definition TensorCollection.h:137
Definition Tensor.h:43
Definition CalorimeterHit.cc:17
OrderKey getOrderKey(const edm4eic::CalorimeterHit &obj)
Definition CalorimeterHit.cc:150
std::size_t operator()(const edm4eic::MutableTensor &obj) const
Definition MutableTensor.h:147