14 std::vector<Dim> ret_shape(shape.size());
15 for (
size_t i =0; i < shape.size(); i++){
16 ret_shape[i].dim = shape[i];
25 std::vector<size_t> ret_shape(shape.size());
26 for (
size_t i =0; i < shape.size(); i++){
27 if (shape[i].isParam) {
31 ret_shape[i] = shape[i].dim;
39 std::size_t fLength = 1;
40 for (
auto& dim: shape) fLength *= dim;
80 if(
type ==
"float32" ||
type ==
"float" ||
type ==
"Float"){
83 else if(
type ==
"int64" ||
type ==
"int64_t"){
86 else if (
type ==
"double" ||
type ==
"float64"){
89 else if (
type ==
"bool" ){
98 std::stringstream out;
100 for (
size_t i = 0; i < shape.size(); i++) {
102 if (i < shape.size()-1) out <<
" , ";
109 std::stringstream out;
111 for (
size_t i = 0; i < shape.size(); i++) {
112 out << shape[i].GetVal();
113 if (i < shape.size()-1) out <<
" , ";
123 size_t int_length = 0;
124 for (
size_t i = 0; i < shape.size(); i++) {
125 if (shape[i].isParam) {
130 int_length = shape[i].dim;
132 int_length *= shape[i].dim;
136 if (int_length > 0) {
138 length += std::to_string(int_length);
146 std::memcpy(
target,
input, input_size *
sizeof(T));
147 int_t already_copied = 1;
149 while (already_copied * 2 <= no_of_copies){
150 std::memcpy(
target + already_copied * input_size,
target, already_copied * input_size *
sizeof(T));
154 if (already_copied < no_of_copies){
155 std::memcpy(
target + already_copied * input_size,
target, (no_of_copies - already_copied) * input_size *
sizeof(T));
161 if (shapeA.size() != shapeB.size()) {
164 for (
size_t dim = 0; dim < shapeA.size(); dim++) {
165 if (shapeA[dim] != shapeB[dim]) {
172 if (shapeA.size() != shapeB.size()) {
175 for (
size_t dim = 0; dim < shapeA.size(); dim++) {
176 if (shapeB[dim].isParam)
return false;
177 if (shapeA[dim] != shapeB[dim].dim) {
184 if (shapeA.size() != shapeB.size()) {
187 for (
size_t dim = 0; dim < shapeA.size(); dim++) {
188 if (shapeA[dim].GetVal() != shapeB[dim].GetVal()) {
197 if (shape.size() < 2) {
199 std::runtime_error(
"TMVA::SOFIE - MultidirectionalBroadcastShape requires at least 2 input shapes.");
202 size_t n = shape.size();
204 size_t targetSize = shape[0].size();
205 for (
size_t i = 1; i <
n; i++) {
206 targetSize = std::max(targetSize, shape[i].
size());
209 bool sameSize =
true;
210 for (
size_t i = 0; i <
n; i++) {
211 if (shape[i].
size() != targetSize) {
218 bool sameShape =
true;
219 for (
size_t i = 1; i <
n; i++) {
220 for (
size_t dim = 0; dim < shape[0].size(); dim++) {
221 if (shape[i][dim] != shape[0][dim]) {
234 std::vector<size_t> targetShape(targetSize, 1);
235 for (
size_t i = 0; i <
n; i++) {
236 for (
size_t dim = 0; dim < targetSize; dim++) {
237 targetShape[dim] = std::max(targetShape[dim], shape[i][dim]);
241 bool broadcastable =
true;
242 for (
size_t i = 0; i <
n; i++) {
243 for (
size_t dim = 0; dim < targetSize; dim++) {
244 if (shape[i][dim] != 1 && targetShape[dim] != 1 && shape[i][dim] != targetShape[dim]) {
245 broadcastable =
false;
248 if (!broadcastable) {
257 std::stringstream ss;
258 ss <<
"TMVA::SOFIE - Error multidirectional broadcasting shapes ";
259 for (
size_t i = 0; i <
n; i++) {
261 if (
n > 2 && i <
n - 2) {
263 }
else if (
n >=2 && i ==
n - 2) {
267 ss <<
" to the same shape.";
269 std::runtime_error(ss.str());
274 for (
size_t i = 0; i <
n; i++) {
275 if (shape[i].
size() < targetSize) {
276 std::vector<size_t> newShape(targetSize, 1);
277 size_t offset = targetSize - shape[i].size();
278 std::copy(shape[i].begin(), shape[i].end(), newShape.begin() +
offset);
283 std::vector<size_t> targetShape(targetSize, 1);
284 for (
size_t i = 0; i <
n; i++) {
285 for (
size_t dim = 0; dim < targetSize; dim++) {
286 targetShape[dim] = std::max(targetShape[dim], shape[i][dim]);
290 bool broadcastable =
true;
291 for (
size_t i = 0; i <
n; i++) {
292 for (
size_t dim = 0; dim < targetSize; dim++) {
293 if (shape[i][dim] != targetShape[dim] && shape[i][dim] != 1 && targetShape[dim] != 1) {
294 broadcastable =
false;
298 if (!broadcastable) {
305 std::stringstream ss;
306 ss <<
"TMVA::SOFIE - Error multidirectional broadcasting shapes ";
307 for (
size_t i = 0; i <
n; i++) {
309 if (
n > 2 && i <
n - 2) {
311 }
else if (
n >=2 && i ==
n - 2) {
315 ss <<
" to the same shape.";
317 std::runtime_error(ss.str());
323 size_t sizeA = shapeA.size();
324 size_t sizeB = shapeB.size();
330 size_t size = std::max(sizeA, sizeB);
332 std::vector<size_t> newShapeA(
size, 1);
334 std::copy(shapeA.begin(), shapeA.end(), newShapeA.begin() +
offset);
335 shapeA = std::move(newShapeA);
338 std::vector<size_t> newShapeB(
size, 1);
340 std::copy(shapeB.begin(), shapeB.end(), newShapeB.begin() +
offset);
341 shapeB = std::move(newShapeB);
343 bool broadcastable =
true;
344 for (
size_t i = 0; i <
size; i++) {
345 if (shapeA[i] != shapeB[i] && shapeA[i] != 1 && shapeB[i] != 1) {
346 broadcastable =
false;
352 std::vector<size_t> targetShape(
size, 1);
353 for (
size_t i = 0; i <
size; i++) {
354 targetShape[i] = std::max(shapeA[i], shapeB[i]);
359 std::runtime_error(
"TMVA::SOFIE - Error unidirectional broadcasting tensors of shape "
361 +
" to a common shape.");
366 std::string s (input_tensor_name);
367 s.erase(std::remove_if(s.begin(), s.end(), [](
char const&
c ) ->
bool { return !std::isalnum(c); } ), s.end());
373 const auto size = shape.size();
374 std::vector<size_t> strides(
size,1);
375 for (std::size_t i = 1; i <
size; i++) {
376 strides[
size - 1 - i] = strides[
size - i ] * shape[
size - i];
383 const auto size = shape.size();
384 std::vector<Dim> strides(
size);
386 for (std::size_t i = 1; i <
size; i++) {
387 if (!shape[
size-i].isParam && !strides[
size-i].isParam)
390 strides[
size - 1 - i] =
Dim{std::string(strides[
size-i].GetVal() +
"*" + shape[
size-i].GetVal())};
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 length
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)
Convert shape from integer format to dynamic one (based on Dim)
std::string ConvertDynamicShapeToLength(std::vector< Dim > shape)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::string ConvertTypeToString(ETensorType type)
std::string ConvertDynamicShapeToString(std::vector< Dim > shape)
ETensorType ConvertStringToType(std::string type)
std::vector< size_t > ConvertShapeToInt(std::vector< Dim > shape)
Convert shape based on Dim to integer format.
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations