12 std::vector<Dim> fshape(shape.size());
13 for (
size_t i =0; i < shape.size(); i++){
14 fshape[i].dim = shape[i];
21 std::size_t fLength = 1;
22 for (
auto& dim: shape) fLength *= dim;
59 if(
type ==
"float32" ||
type ==
"float" ||
type ==
"Float"){
62 else if(
type ==
"int64"){
65 else if (
type ==
"double" ||
type ==
"float64"){
74 std::stringstream out;
76 for (
size_t i = 0; i < shape.size(); i++) {
78 if (i < shape.size()-1) out <<
" , ";
88 int_t already_copied = 1;
90 while (already_copied * 2 <= no_of_copies){
91 std::memcpy(
target + already_copied * input_size,
target, already_copied * input_size *
sizeof(T));
95 if (already_copied < no_of_copies){
96 std::memcpy(
target + already_copied * input_size,
target, (no_of_copies - already_copied) * input_size *
sizeof(T));
102 if (shapeA.size() != shapeB.size()) {
105 for (
size_t dim = 0; dim < shapeA.size(); dim++) {
106 if (shapeA[dim] != shapeB[dim]) {
115 if (shape.size() < 2) {
117 std::runtime_error(
"TMVA::SOFIE - MultidirectionalBroadcastShape requires at least 2 input shapes.");
120 size_t n = shape.size();
122 size_t targetSize = shape[0].size();
123 for (
size_t i = 1; i <
n; i++) {
124 targetSize = std::max(targetSize, shape[i].
size());
127 bool sameSize =
true;
128 for (
size_t i = 0; i <
n; i++) {
129 if (shape[i].
size() != targetSize) {
136 bool sameShape =
true;
137 for (
size_t i = 1; i <
n; i++) {
138 for (
size_t dim = 0; dim < shape[0].size(); dim++) {
139 if (shape[i][dim] != shape[0][dim]) {
152 std::vector<size_t> targetShape(targetSize, 1);
153 for (
size_t i = 0; i <
n; i++) {
154 for (
size_t dim = 0; dim < targetSize; dim++) {
155 targetShape[dim] = std::max(targetShape[dim], shape[i][dim]);
159 bool broadcastable =
true;
160 for (
size_t i = 0; i <
n; i++) {
161 for (
size_t dim = 0; dim < targetSize; dim++) {
162 if (shape[i][dim] != 1 && targetShape[dim] != 1 && shape[i][dim] != targetShape[dim]) {
163 broadcastable =
false;
166 if (!broadcastable) {
175 std::stringstream ss;
176 ss <<
"TMVA::SOFIE - Error multidirectional broadcasting shapes ";
177 for (
size_t i = 0; i <
n; i++) {
179 if (
n > 2 && i <
n - 2) {
181 }
else if (
n >=2 && i ==
n - 2) {
185 ss <<
" to the same shape.";
187 std::runtime_error(ss.str());
192 for (
size_t i = 0; i <
n; i++) {
193 if (shape[i].
size() < targetSize) {
194 std::vector<size_t> newShape(targetSize, 1);
195 size_t offset = targetSize - shape[i].size();
196 std::copy(shape[i].begin(), shape[i].end(), newShape.begin() +
offset);
201 std::vector<size_t> targetShape(targetSize, 1);
202 for (
size_t i = 0; i <
n; i++) {
203 for (
size_t dim = 0; dim < targetSize; dim++) {
204 targetShape[dim] = std::max(targetShape[dim], shape[i][dim]);
208 bool broadcastable =
true;
209 for (
size_t i = 0; i <
n; i++) {
210 for (
size_t dim = 0; dim < targetSize; dim++) {
211 if (shape[i][dim] != targetShape[dim] && shape[i][dim] != 1 && targetShape[dim] != 1) {
212 broadcastable =
false;
216 if (!broadcastable) {
223 std::stringstream ss;
224 ss <<
"TMVA::SOFIE - Error multidirectional broadcasting shapes ";
225 for (
size_t i = 0; i <
n; i++) {
227 if (
n > 2 && i <
n - 2) {
229 }
else if (
n >=2 && i ==
n - 2) {
233 ss <<
" to the same shape.";
235 std::runtime_error(ss.str());
241 size_t sizeA = shapeA.size();
242 size_t sizeB = shapeB.size();
248 size_t size = std::max(sizeA, sizeB);
250 std::vector<size_t> newShapeA(
size, 1);
252 std::copy(shapeA.begin(), shapeA.end(), newShapeA.begin() +
offset);
253 shapeA = std::move(newShapeA);
256 std::vector<size_t> newShapeB(
size, 1);
258 std::copy(shapeB.begin(), shapeB.end(), newShapeB.begin() +
offset);
259 shapeB = std::move(newShapeB);
261 bool broadcastable =
true;
262 for (
size_t i = 0; i <
size; i++) {
263 if (shapeA[i] != shapeB[i] && shapeA[i] != 1 && shapeB[i] != 1) {
264 broadcastable =
false;
270 std::vector<size_t> targetShape(
size, 1);
271 for (
size_t i = 0; i <
size; i++) {
272 targetShape[i] = std::max(shapeA[i], shapeB[i]);
277 std::runtime_error(
"TMVA::SOFIE - Error unidirectional broadcasting tensors of shape "
279 +
" to a common shape.");
284 std::string s (input_tensor_name);
285 s.erase(std::remove_if(s.begin(), s.end(), [](
char const&
c ) ->
bool { return !std::isalnum(c); } ), s.end());
291 const auto size = shape.size();
292 std::vector<size_t> strides(
size,1);
293 for (std::size_t i = 1; i <
size; i++) {
294 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