-
Notifications
You must be signed in to change notification settings - Fork 156
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
add promote_symtype
for _map
and _mapreduce
.
#814
base: master
Are you sure you want to change the base?
add promote_symtype
for _map
and _mapreduce
.
#814
Conversation
This looks reasonable to me, but I wonder if this is still needed with Unityper's changes? |
I have tried the MWE in a new environment with
where #d0a80ad is the latest commit in #549. The original issue resulted from the outer most call to |
Codecov Report
@@ Coverage Diff @@
## master #814 +/- ##
==========================================
- Coverage 77.53% 77.20% -0.34%
==========================================
Files 26 26
Lines 3201 3215 +14
==========================================
Hits 2482 2482
- Misses 719 733 +14
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
`_mapreduce` 2) introduce `_promote_symtype` instead, logic taken from the respective methods 3) adapt method definitions to avoid redundancy 4) some tests for the problem described in JuliaSymbolics#814
I have thought a bit about this. I cannot think of any situation where |
) | ||
end | ||
|
||
function SymbolicUtils._promote_symtype(::typeof(_map), args) |
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.
I dont think we should be extending this function... It looks like a very internal helper function. Why can't we do this with just promote_symtype
?
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.
That's what I attempted initially in 47801aa (btw sorry for the 3rd commit, did not know about git rebase
)
I hope I remember correctly: The problem with promote_symtype
for _map
and _mapreduce
is that promote_symtype
is meant to have a signature promote_symtype(f, arg_symtypes...)
.
_promote_symtype
receives the arguments instead of their types, i.e., _promote_symtype(f, args...)
.
In case of _map
or _mapreduce
we would like to recursively call promote_symtype
for the mapped function and maybe a binary operator.
With promote_symtype
I tried to obtain function instances by accessing the corresponding field of the type:
Line 314 in 47801aa
mapreduce(Base.Fix1(promote_symtype, F.instance), promote_type, eltype.(XS)) |
With
_promote_symtype
and the arguments available, we can use exactly the same logic as if actually calling _map
and _mapreduce
to get consistent type predictions (another problem with the promote_symtype
approach).
This is meant to fix an inference problem.
MWE:
Now,
norm_squared
is aNum
, butsimplified_norm_squared
is aTerm{Any, Nothing}
.I believe the issue to be missing methods of
promote_symtype
for_map
and_mapreduce
.Now, the interactions of
symtype
,typeof
,promote_type
andpromote_symtype
are still confusing to me, which is why the pull request is marked as draft.Thoughts and comments would be appreciated :)
Anyway, these definitions appear to solve the issue and don't break the tests.
Also, we tackle the underlying problem, instead of what I suspected/suggested in this comment...