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
23
24namespace edm4eic {
25
26
27/** @class MutableTensor
28 * Tensor type for use in training in inference of ML models
29 * @author: D. Kalinkin
30 */
32
33 friend class TensorCollection;
35 friend class Tensor;
36
37public:
40
41 /// default constructor
43
44 /// Constructor initializing all members
45 MutableTensor(std::int32_t elementType);
46
47 /// copy constructor
48 MutableTensor(const MutableTensor& other) = default;
49
50 /// copy-assignment operator
52
53 /// create a mutable deep-copy of the object with identical relations
54 /// if cloneRelations=false, the relations are not cloned and will be empty
55 MutableTensor clone(bool cloneRelations=true) const;
56
57 /// destructor
58 ~MutableTensor() = default;
59
60
61public:
62
63 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
64 std::int32_t getElementType() const;
65
66
67
68 /// Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
69 void setElementType(std::int32_t value);
70 /// Get mutable reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
71 std::int32_t& getElementType();
72 /// Get reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
73 [[deprecated("use getElementType instead")]]
74 std::int32_t& elementType();
75
76
77
78 void addToShape(const std::int64_t&);
79 std::size_t shape_size() const;
80 std::int64_t getShape(std::size_t) const;
81 std::vector<std::int64_t>::const_iterator shape_begin() const;
82 std::vector<std::int64_t>::const_iterator shape_end() const;
83 podio::RelationRange<std::int64_t> getShape() const;
84 void addToFloatData(const float&);
85 std::size_t floatData_size() const;
86 float getFloatData(std::size_t) const;
87 std::vector<float>::const_iterator floatData_begin() const;
88 std::vector<float>::const_iterator floatData_end() const;
89 podio::RelationRange<float> getFloatData() const;
90 void addToInt64Data(const std::int64_t&);
91 std::size_t int64Data_size() const;
92 std::int64_t getInt64Data(std::size_t) const;
93 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
94 std::vector<std::int64_t>::const_iterator int64Data_end() const;
95 podio::RelationRange<std::int64_t> getInt64Data() const;
96
97
98
99 /// check whether the object is actually available
100 bool isAvailable() const;
101 /// disconnect from TensorObj instance
102 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
103
104 bool operator==(const MutableTensor& other) const { return m_obj == other.m_obj; }
105 bool operator==(const Tensor& other) const;
106
107 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
108 bool operator!=(const Tensor& other) const { return !(*this == other); }
109
110 // less comparison operator, so that objects can be e.g. stored in sets.
111 bool operator<(const MutableTensor& other) const { return m_obj < other.m_obj; }
112
113 podio::ObjectID id() const { return getObjectID(); }
114
115 const podio::ObjectID getObjectID() const;
116
117 friend void swap(MutableTensor& a, MutableTensor& b) {
118 using std::swap;
119 swap(a.m_obj, b.m_obj); // swap out the internal pointers
120 }
121
122private:
123 /// constructor from existing TensorObj
124 explicit MutableTensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
125
126 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
127};
128
129#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
130void to_json(nlohmann::json& j, const MutableTensor& value);
131#endif
132
133
134} // namespace edm4eic
135
136
137#endif
Definition MutableTensor.h:31
bool isAvailable() const
check whether the object is actually available
Definition MutableTensor.cc:171
friend class Tensor
Definition MutableTensor.h:35
MutableTensor(const MutableTensor &other)=default
copy constructor
bool operator<(const MutableTensor &other) const
Definition MutableTensor.h:111
std::vector< float >::const_iterator floatData_end() const
Definition MutableTensor.cc:105
bool operator!=(const MutableTensor &other) const
Definition MutableTensor.h:107
MutableTensor & operator=(MutableTensor other)
copy-assignment operator
Definition MutableTensor.cc:26
bool operator!=(const Tensor &other) const
Definition MutableTensor.h:108
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:113
friend class TensorCollection
Definition MutableTensor.h:33
MutableTensor()
default constructor
Definition MutableTensor.cc:18
podio::RelationRange< std::int64_t > getInt64Data() const
Definition MutableTensor.cc:158
friend void swap(MutableTensor &a, MutableTensor &b)
Definition MutableTensor.h:117
podio::RelationRange< float > getFloatData() const
Definition MutableTensor.cc:122
std::size_t floatData_size() const
Definition MutableTensor.cc:111
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:104
std::size_t int64Data_size() const
Definition MutableTensor.cc:147
std::int32_t & elementType()
Get reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition MutableTensor.cc:55
void setElementType(std::int32_t value)
Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64.
Definition MutableTensor.cc:53
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:102
const podio::ObjectID getObjectID() const
Definition MutableTensor.cc:175
Definition TensorCollection.h:92
Definition Tensor.h:33
Definition TensorCollection.h:63
Definition CalorimeterHit.cc:17