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 <cstddef>
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 MutableTensor clone() const;
58
59 /// destructor
60 ~Tensor() = default;
61
62
63 static Tensor makeEmpty();
64
65public:
66
67 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
68 std::int32_t getElementType() const;
69
70
71
72 std::size_t shape_size() const;
73 std::int64_t getShape(std::size_t) const;
74 std::vector<std::int64_t>::const_iterator shape_begin() const;
75 std::vector<std::int64_t>::const_iterator shape_end() const;
76 podio::RelationRange<std::int64_t> getShape() const;
77 std::size_t floatData_size() const;
78 float getFloatData(std::size_t) const;
79 std::vector<float>::const_iterator floatData_begin() const;
80 std::vector<float>::const_iterator floatData_end() const;
81 podio::RelationRange<float> getFloatData() const;
82 std::size_t int64Data_size() const;
83 std::int64_t getInt64Data(std::size_t) const;
84 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
85 std::vector<std::int64_t>::const_iterator int64Data_end() const;
86 podio::RelationRange<std::int64_t> getInt64Data() const;
87
88
89 /// check whether the object is actually available
90 bool isAvailable() const;
91 /// disconnect from TensorObj instance
92 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
93
94 bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
95 bool operator==(const MutableTensor& other) const;
96
97 // less comparison operator, so that objects can be e.g. stored in sets.
98 bool operator<(const Tensor& other) const { return m_obj < other.m_obj; }
99
100 podio::ObjectID id() const { return getObjectID(); }
101
102 const podio::ObjectID getObjectID() const;
103
104 friend void swap(Tensor& a, Tensor& b) {
105 using std::swap;
106 swap(a.m_obj, b.m_obj); // swap out the internal pointers
107 }
108
109private:
110 /// constructor from existing TensorObj
111 explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
112 Tensor(TensorObj* obj);
113
114 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
115};
116
117std::ostream& operator<<(std::ostream& o, const Tensor& value);
118
119#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
120void to_json(nlohmann::json& j, const Tensor& value);
121#endif
122
123
124} // namespace edm4eic
125
126
127#endif
Definition MutableTensor.h:32
Definition TensorCollectionData.h:30
Definition TensorCollection.h:95
Definition TensorCollection.h:40
Definition Tensor.h:33
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition Tensor.cc:114
bool isAvailable() const
check whether the object is actually available
Definition Tensor.cc:149
std::vector< float >::const_iterator floatData_begin() const
Definition Tensor.cc:82
podio::RelationRange< std::int64_t > getInt64Data() const
Definition Tensor.cc:137
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition Tensor.cc:120
std::int32_t getElementType() const
Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition Tensor.cc:46
std::size_t floatData_size() const
Definition Tensor.cc:94
podio::RelationRange< float > getFloatData() const
Definition Tensor.cc:105
std::vector< std::int64_t >::const_iterator shape_end() const
Definition Tensor.cc:56
podio::ObjectID id() const
Definition Tensor.h:100
bool operator<(const Tensor &other) const
Definition Tensor.h:98
friend class TensorCollection
Definition Tensor.h:36
friend void swap(Tensor &a, Tensor &b)
Definition Tensor.h:104
std::vector< float >::const_iterator floatData_end() const
Definition Tensor.cc:88
std::size_t shape_size() const
Definition Tensor.cc:62
MutableTensor clone() const
create a mutable deep-copy of the object with identical relations
Definition Tensor.cc:34
Tensor()
default constructor
Definition Tensor.cc:21
bool operator==(const Tensor &other) const
Definition Tensor.h:94
const podio::ObjectID getObjectID() const
Definition Tensor.cc:156
friend class MutableTensor
Definition Tensor.h:35
void unlink()
disconnect from TensorObj instance
Definition Tensor.h:92
podio::RelationRange< std::int64_t > getShape() const
Definition Tensor.cc:73
std::size_t int64Data_size() const
Definition Tensor.cc:126
Tensor & operator=(Tensor other)
copy-assignment operator
Definition Tensor.cc:29
Tensor(const Tensor &other)=default
copy constructor
static Tensor makeEmpty()
Definition Tensor.cc:42
~Tensor()=default
destructor
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition Tensor.cc:50
Definition TensorObj.h:18
Definition CalorimeterHit.cc:18
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:97