add promote_symtype for _map and _mapreduce.#814
add promote_symtype for _map and _mapreduce.#814manuelbb-upb wants to merge 3 commits intoJuliaSymbolics:masterfrom
promote_symtype for _map and _mapreduce.#814Conversation
|
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.
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.
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
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_squaredis aNum, butsimplified_norm_squaredis aTerm{Any, Nothing}.I believe the issue to be missing methods of
promote_symtypefor_mapand_mapreduce.Now, the interactions of
symtype,typeof,promote_typeandpromote_symtypeare 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...