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
46 MutableTensor() = default;
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
78
79
80 void addToShape(const std::int64_t&);
81 std::size_t shape_size() const;
82 std::int64_t getShape(std::size_t) const;
83 std::vector<std::int64_t>::const_iterator shape_begin() const;
84 std::vector<std::int64_t>::const_iterator shape_end() const;
85 podio::RelationRange<std::int64_t> getShape() const;
86 void addToFloatData(const float&);
87 std::size_t floatData_size() const;
88 float getFloatData(std::size_t) const;
89 std::vector<float>::const_iterator floatData_begin() const;
90 std::vector<float>::const_iterator floatData_end() const;
91 podio::RelationRange<float> getFloatData() const;
92 void addToInt64Data(const std::int64_t&);
93 std::size_t int64Data_size() const;
94 std::int64_t getInt64Data(std::size_t) const;
95 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
96 std::vector<std::int64_t>::const_iterator int64Data_end() const;
97 podio::RelationRange<std::int64_t> getInt64Data() const;
98
99
100
101 /// check whether the object is actually available
102 bool isAvailable() const;
103 /// disconnect from TensorObj instance
104 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
105
106 constexpr bool operator==(const MutableTensor& other) const { return m_obj == other.m_obj; }
107 bool operator==(const Tensor& other) const;
108
109 constexpr bool operator!=(const MutableTensor& other) const { return !(*this == other); }
110 bool operator!=(const Tensor& other) const { return !(*this == other); }
111
112 // less comparison operator, so that objects can be e.g. stored in sets.
113 bool operator<(const MutableTensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
114
115 podio::ObjectID id() const { return getObjectID(); }
116
117 const podio::ObjectID getObjectID() const;
118
119 friend std::hash<MutableTensor>;
120
121 friend void swap(MutableTensor& a, MutableTensor& b) {
122 using std::swap;
123 swap(a.m_obj, b.m_obj); // swap out the internal pointers
124 }
125
126private:
127 /// constructor from existing TensorObj
128 explicit MutableTensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
129
130 podio::utils::MaybeSharedPtr<TensorObj> m_obj{new TensorObj{}, podio::utils::MarkOwned};
131};
132
133#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
134void to_json(nlohmann::json& j, const MutableTensor& value);
135#endif
136
137
138} // namespace edm4eic
139
140
141
142template<>
143struct std::hash<edm4eic::MutableTensor> {
144 std::size_t operator()(const edm4eic::MutableTensor& obj) const {
145 return std::hash<edm4eic::TensorObj*>{}(obj.m_obj.get());
146 }
147};
148
149
150#endif
Definition MutableTensor.h:35
bool isAvailable() const
check whether the object is actually available
Definition MutableTensor.cc:166
TensorCollection collection_type
Definition MutableTensor.h:43
friend class Tensor
Definition MutableTensor.h:39
constexpr bool operator!=(const MutableTensor &other) const
Definition MutableTensor.h:109
MutableTensor(const MutableTensor &other)=default
copy constructor
bool operator<(const MutableTensor &other) const
Definition MutableTensor.h:113
std::vector< float >::const_iterator floatData_end() const
Definition MutableTensor.cc:100
bool operator!=(const Tensor &other) const
Definition MutableTensor.h:110
MutableTensor clone(bool cloneRelations=true) const
Definition MutableTensor.cc:27
void addToInt64Data(const std::int64_t &)
Definition MutableTensor.cc:125
void addToFloatData(const float &)
Definition MutableTensor.cc:89
podio::ObjectID id() const
Definition MutableTensor.h:115
friend class TensorCollection
Definition MutableTensor.h:37
MutableTensor & operator=(MutableTensor other) &
copy-assignment operator
Definition MutableTensor.cc:22
podio::RelationRange< std::int64_t > getInt64Data() const
Definition MutableTensor.cc:153
Tensor object_type
Definition MutableTensor.h:42
friend void swap(MutableTensor &a, MutableTensor &b)
Definition MutableTensor.h:121
podio::RelationRange< float > getFloatData() const
Definition MutableTensor.cc:117
std::size_t floatData_size() const
Definition MutableTensor.cc:106
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:46
~MutableTensor()=default
destructor
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition MutableTensor.cc:136
podio::RelationRange< std::int64_t > getShape() const
Definition MutableTensor.cc:81
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition MutableTensor.cc:130
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition MutableTensor.cc:58
std::size_t int64Data_size() const
Definition MutableTensor.cc:142
void setElementType(const std::int32_t elementType)
Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64.
Definition MutableTensor.cc:49
friend class TensorMutableCollectionIterator
Definition MutableTensor.h:38
std::vector< float >::const_iterator floatData_begin() const
Definition MutableTensor.cc:94
std::size_t shape_size() const
Definition MutableTensor.cc:70
void addToShape(const std::int64_t &)
Definition MutableTensor.cc:53
std::vector< std::int64_t >::const_iterator shape_end() const
Definition MutableTensor.cc:64
void unlink()
disconnect from TensorObj instance
Definition MutableTensor.h:104
MutableTensor()=default
default constructor
const podio::ObjectID getObjectID() const
Definition MutableTensor.cc:170
constexpr bool operator==(const MutableTensor &other) const
Definition MutableTensor.h:106
Definition TensorCollection.h:139
Definition Tensor.h:43
Definition TensorObj.h:19
Definition ArrowMapper.cc:61
OrderKey getOrderKey(const edm4eic::CalorimeterHit &obj)
Definition CalorimeterHit.cc:146
std::size_t operator()(const edm4eic::MutableTensor &obj) const
Definition MutableTensor.h:144