11 std::vector<Dim> fshape(shape.size());
12 for (
size_t i =0; i < shape.size(); i++){
13 fshape[i].dim = shape[i];
20 std::size_t fLength = 1;
21 for (
auto& dim: shape) fLength *= dim;
58 if(
type ==
"float32" ||
type ==
"float" ||
type ==
"Float"){
61 else if(
type ==
"int64"){
64 else if (
type ==
"double" ||
type ==
"float64"){
73 std::stringstream out;
75 for (
size_t i = 0; i < shape.size(); i++) {
77 if (i < shape.size()-1) out <<
" , ";
87 int_t already_copied = 1;
89 while (already_copied * 2 <= no_of_copies){
90 std::memcpy(
target + already_copied * input_size,
target, already_copied * input_size *
sizeof(T));
94 if (already_copied < no_of_copies){
95 std::memcpy(
target + already_copied * input_size,
target, (no_of_copies - already_copied) * input_size *
sizeof(T));
101 if (shapeA.size() != shapeB.size()) {
104 for (
size_t dim = 0; dim < shapeA.size(); dim++) {
105 if (shapeA[dim] != shapeB[dim]) {
114 if (shape.size() < 2) {
116 std::runtime_error(
"TMVA::SOFIE - MultidirectionalBroadcastShape requires at least 2 input shapes.");
119 size_t n = shape.size();
121 size_t targetSize = shape[0].size();
122 for (
size_t i = 1; i <
n; i++) {
123 targetSize = std::max(targetSize, shape[i].
size());
126 bool sameSize =
true;
127 for (
size_t i = 0; i <
n; i++) {
128 if (shape[i].
size() != targetSize) {
135 bool sameShape =
true;
136 for (
size_t i = 1; i <
n; i++) {
137 for (
size_t dim = 0; dim < shape[0].size(); dim++) {
138 if (shape[i][dim] != shape[0][dim]) {
151 std::vector<size_t> targetShape(targetSize, 1);
152 for (
size_t i = 0; i <
n; i++) {
153 for (
size_t dim = 0; dim < targetSize; dim++) {
154 targetShape[dim] = std::max(targetShape[dim], shape[i][dim]);
158 bool broadcastable =
true;
159 for (
size_t i = 0; i <
n; i++) {
160 for (
size_t dim = 0; dim < targetSize; dim++) {
161 if (shape[i][dim] != 1 && targetShape[dim] != 1 && shape[i][dim] != targetShape[dim]) {
162 broadcastable =
false;
165 if (!broadcastable) {
174 std::stringstream ss;
175 ss <<
"TMVA::SOFIE - Error multidirectional broadcasting shapes ";
176 for (
size_t i = 0; i <
n; i++) {
178 if (
n > 2 && i <
n - 2) {
180 }
else if (
n >=2 && i ==
n - 2) {
184 ss <<
" to the same shape.";
186 std::runtime_error(ss.str());
191 for (
size_t i = 0; i <
n; i++) {
192 if (shape[i].
size() < targetSize) {
193 std::vector<size_t> newShape(targetSize, 1);
194 size_t offset = targetSize - shape[i].size();
195 std::copy(shape[i].begin(), shape[i].end(), newShape.begin() +
offset);
200 std::vector<size_t> targetShape(targetSize, 1);
201 for (
size_t i = 0; i <
n; i++) {
202 for (
size_t dim = 0; dim < targetSize; dim++) {
203 targetShape[dim] = std::max(targetShape[dim], shape[i][dim]);
207 bool broadcastable =
true;
208 for (
size_t i = 0; i <
n; i++) {
209 for (
size_t dim = 0; dim < targetSize; dim++) {
210 if (shape[i][dim] != targetShape[dim] && shape[i][dim] != 1 && targetShape[dim] != 1) {
211 broadcastable =
false;
215 if (!broadcastable) {
222 std::stringstream ss;
223 ss <<
"TMVA::SOFIE - Error multidirectional broadcasting shapes ";
224 for (
size_t i = 0; i <
n; i++) {
226 if (
n > 2 && i <
n - 2) {
228 }
else if (
n >=2 && i ==
n - 2) {
232 ss <<
" to the same shape.";
234 std::runtime_error(ss.str());
240 size_t sizeA = shapeA.size();
241 size_t sizeB = shapeB.size();
247 size_t size = std::max(sizeA, sizeB);
249 std::vector<size_t> newShapeA(
size, 1);
251 std::copy(shapeA.begin(), shapeA.end(), newShapeA.begin() +
offset);
252 shapeA = std::move(newShapeA);
255 std::vector<size_t> newShapeB(
size, 1);
257 std::copy(shapeB.begin(), shapeB.end(), newShapeB.begin() +
offset);
258 shapeB = std::move(newShapeB);
260 bool broadcastable =
true;
261 for (
size_t i = 0; i <
size; i++) {
262 if (shapeA[i] != shapeB[i] && shapeA[i] != 1 && shapeB[i] != 1) {
263 broadcastable =
false;
269 std::vector<size_t> targetShape(
size, 1);
270 for (
size_t i = 0; i <
size; i++) {
271 targetShape[i] = std::max(shapeA[i], shapeB[i]);
276 std::runtime_error(
"TMVA::SOFIE - Error unidirectional broadcasting tensors of shape "
278 +
" to a common shape.");
283 std::string s (input_tensor_name);
284 s.erase(std::remove_if(s.begin(), s.end(), [](
char const&
c ) ->
bool { return !std::isalnum(c); } ), s.end());
290 const auto size = shape.size();
291 std::vector<size_t> strides(
size,1);
292 for (std::size_t i = 1; i <
size; i++) {
293 strides[
size - 1 - i] = strides[
size - 1 - i + 1] * shape[
size - 1 - i + 1];
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
bool AreSameShape(const std::vector< size_t > &, const std::vector< size_t > &)
std::vector< size_t > UnidirectionalBroadcastShape(std::vector< size_t >, std::vector< size_t >)
std::string Clean_name(std::string input_tensor_name)
std::vector< size_t > MultidirectionalBroadcastShape(std::vector< std::vector< size_t > >)
std::vector< size_t > ComputeStrideFromShape(const std::vector< size_t > &shape)
compute stride of a tensor given its shape (assume layout is row-major)
std::vector< Dim > ConvertShapeToDim(std::vector< size_t > shape)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::string ConvertTypeToString(ETensorType type)
ETensorType ConvertStringToType(std::string type)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations