Skip to content

Conversation

olia110
Copy link
Contributor

@olia110 olia110 commented Aug 25, 2025

This Pull request:

This pull request refactors the ROperator_Comparision to handle broadcasting more efficiently.
Added new tests to verify the correctness of the ROperator_Comparision.

Copy link
Contributor

@sanjibansg sanjibansg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks for this change!

@@ -77,7 +77,7 @@ public:
ROperator_Comparision(const std::string & nameX1, const std::string & nameX2, const std::string & nameY):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmoneta do we need the std::vector<Dim> fDimShapeX1; std::vector<Dim> fDimShapeX2; here? They seem to be only used in two if cases

Copy link

Test Results

    19 files      19 suites   3d 4h 7m 53s ⏱️
 3 558 tests  3 419 ✅  1 💤 138 ❌
65 965 runs  65 777 ✅ 40 💤 148 ❌

For more details on these failures, see this check.

Results for commit b6041d8.

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing also this operator to avoid broadcasting and for adding the relevant test.
Apart for some issue of some deleted code which should be still valid, the other changes are for following and being consistent what has been done in the BinaryOperator:
https://github.com/root-project/root/pull/19742/files

@@ -113,6 +113,8 @@ public:
fShapeX2 = model.GetTensorShape(fNX2);
fDimShapeX2 = ConvertShapeToDim(fShapeX2);
}
fShapeX1 = model.GetTensorShape(fNX1);
fShapeX2 = model.GetTensorShape(fNX2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplication of the 107 and 113 lines above

} else if (model.IsShapeTensor(fNX2)) {
shapeData2 = model.GetShapeTensorValues(fNX2);
}
if (data1 && data2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why these lines are removed?

}
}
delete [] outData;
if (!fIsOutputConstant) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this code should be kept and not deleted!

}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

out << SP << SP << "delete[] data;\n";
out << SP << "}\n";

auto stridesX1 = UTILITY::ComputeStrideFromShape(fShapeX1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should use fDimShapeX1 and fDimShapeX2 instead of fShapeX1 and fShapeX2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same for Y

} else {
for(size_t i = 0; i<fShapeX1.size(); ++i){
if(fShapeX1[i]==1) continue;
compute_idx_X1 += " idx_"+fNY+std::to_string(i+(fShapeY.size()-fShapeX1.size()))+" * "+std::to_string(stridesX1[i])+" +";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add "fNY" to the definition of the index variables. It will pollute the name, better to keep it simple

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it would be nice to distinguish the case when the strides are equal to 1. In this case it is not needed to add a multiplication with 1 : " * 1". See examples at line 332 in https://github.com/root-project/root/pull/19742/files

auto stridesY = UTILITY::ComputeStrideFromShape(fShapeY);

std::string compute_idx_X1, compute_idx_X2, compute_idx_Y;
if (std::all_of(fShapeX1.begin(), fShapeX1.end(), [](size_t x) { return x == 1; })){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed for the case of fDimShapeX1, see
https://github.com/root-project/root/pull/19742/files


for(size_t i=0; i<fShapeY.size(); ++i){
if(fShapeY[i]!=1){
out<<std::string(i + 1, ' ')<<"for(size_t idx_"<<fNY<<i<<"=0; idx_"<<fNY<<i<<"<"<<fShapeY[i]<<"; ++idx_"<<fNY<<i<<"){\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For fixing the indentention space of the generated code see again:
https://github.com/root-project/root/pull/19742/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants