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