Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exp] Add GetMaxDepth #11970

Merged
merged 7 commits into from
Jan 22, 2024
Merged

[Exp] Add GetMaxDepth #11970

merged 7 commits into from
Jan 22, 2024

Conversation

sunethwarna
Copy link
Member

📝 Description
This PR adds Expression::GetMaxDepth to compute the maximum depth of the lazy expression tree structure.

🆕 Changelog

  • Added 'Expression::GetMaxDepth'
  • Added tests

Comment on lines 118 to 124
return (*std::max_element(
mSourceExpressions.begin(),
mSourceExpressions.end(),
[](const auto& rV1, const auto& rV2) {
return rV1->GetMaxDepth() < rV2->GetMaxDepth();
}))->GetMaxDepth() + 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

that's a lot of repeated depth calculations. It might be worth to consider adding a depth member variable that gets computed at construction time (provided that child Expressions are immutable), instead of always recomputing every depth for each child over and over again.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but I don't see it getting called several times. [At the moment, it will only be called when the future Collapse is called, but that happens when we Collapse at the end. There is no point in Collapsing every time]. I would say, we can move it to a member variable if this gets out of hand.

In any case, I simpliifed the recursions, so there are no redundant recursive calculations.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a warning as well for future reference.

kratos/tests/test_container_expression.py Outdated Show resolved Hide resolved
@sunethwarna
Copy link
Member Author

@matekelemen I have addressed your comments. Could you have a look?

@sunethwarna sunethwarna merged commit 216bb7d into master Jan 22, 2024
17 checks passed
@sunethwarna sunethwarna deleted the exp/add_get_max_depth branch January 22, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants