-
Notifications
You must be signed in to change notification settings - Fork 166
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
Introduced few query methods: is_Add, is_Mul & is_Pow #2351
Conversation
The PR is good. Can you add tests for this? |
Yeah I have raised 2 Prs for introducing query methods through SymEngine's Cwrapper
Once we have these I think we get most of the query methods covered ! |
I see, this PR was assuming some functionality in SymEngine that doesn't exist yet. I think we should rework it to do the changes ourselves. I think the |
Yes let me give it a try and get back to you ! |
Well
A TypeID is nothing but an enumeration registered in
Well we could obviously introduce a similar enumeration but if we aren't looking forward to having query methods for each class, we just need to know the numbers (integers) which the
And we can just compare the integer returned with the expected integer for the class (eg 17 for Pow). |
I've just used up the enum values as of now. Maybe we could replicate the enumeration from SymEngine if we want to add more class types. Also we can currently support
But if we would like to support cases like
We would have to edit |
I'll add a simple test for our implementation. |
ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)), nullptr, nullptr)); | ||
// Using 16 as the right value of the IntegerCompare node as it represents SYMENGINE_ADD through SYMENGINE_ENUM | ||
return ASRUtils::EXPR(ASR::make_IntegerCompare_t(al, loc, function_call, ASR::cmpopType::Eq, | ||
ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, loc, 16, ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a variable / macro and define these all at one place in this file. They will be dependent on the SymEngine version, but I think that's fine. If this becomes a problem, we can revisit the SymEngine API then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I'll look into this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use basic_get_class_id("Integer")
to get the value.
SymEngine.py supports both:
Is supporting I think just do |
I think we should be able to do handle |
Regarding supporting |
Thanks for raising the issue up, I'm still not fully sure what's the best approach here but I'll try to introduce the |
Well I think so the
So we essentially would like to return a class type through the
|
I am not sure what is the significance of what we are returning (depends on the use case). We surely won't face any confusion like this through a query method like
|
You can use the |
I asked about the stability of the type ordering here: symengine/symengine#1982 |
Query methods for class |
These are some query methods to check for the type of the expression. Couple other methods like
is_Log
andis_Exp
would be introduced through subsequent PRs.