-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Map with multiple inputs #3228
Map with multiple inputs #3228
Conversation
Merge develop
Thanks for working this idea out in a PR David! About the transform function: I think the transform function should only be a small wrapper around the actual implementation, and only adjust the index in the callback function from zero based to one based. So I would expect that we have to adjust the current (recursive) map function: from |
Hi, thanks for the advice! Currently Some issue that I found is that By looking at other transform functions, I see in some cases those import the original function first, instead of duplicating the code. In the case of |
I think I'm on track again. I'm working on a way to use the create map. My plan is to make a new callback that when the callback is a typed function it makes a new typed callback that for each signature changes the function associated with the signature to be zero based depending on the number of arguments of the function. It might take a while but I think it might work. Just to let you know there is some progress. |
Hi Jos, I need your guidance again. What's a good way to get the number of arguments of const f = math.evaluate("f(x, index) = index[1]") I tried with |
Thanks for the updates. You indeed cannot safely use On a side note: since this is not easy to solve, let's stay critical: if this feature is very complex to implement (and consecutively: hard to maintain), let's think through if that is worth it. |
Thanks Jos!, I understand. The main functionality is already working, it's currently just an issue with trying to fix the transform function without copying the logic and for that I think I need to transform the callback function with the right number of arguments. Maybe it makes more sense to continue copying the logic with a modification for the index than making new logic for manipulating the callback. I don't think I'm far from having a working proposal, so we can decide then. It has some similarities with Julia's dot notation for map and broadcast. Maybe some common ground can be found. |
Sounds promising! |
I found the issue that was affecting speed. Please check this on the new commit. const a = math.random([1000])
const b = math.random([1000, 1])
console.time('add')
math.add(a, b)
console.timeEnd('add') // 1003 ms
console.time('map typed')
math.map(a, b, math.addScalar)
console.timeEnd('map typed') // 862 ms
console.time('map function')
math.map(a, b, (x, y) => math.addScalar(x, y))
console.timeEnd('map function') // 897 ms |
Ow nice 😎 I get something like this:
Anyway: the performance of using multi map is close to not using it, which is really nice and better than I had expected! |
Thanks Jos! I included some tests and added some documentation in matrices. I will try the next few days to include the type definitions. |
Hi, it's ready for review. |
That sounds good, thanks for the updates! I'll look into it after the holidays (sorry for the delay). |
Thank you Jos! |
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've reviewed the latest version @dvd101x . It's really impressive how it looks now compared to your first draft: the code is now easy to follow, good performance, all is well documented and tested. Nice job!!
I added a few minor inline comments, can you have a look at those? After that we can merge this new feature :)
Hi Jos, thank you for the thorough review and your kind words. It wouldn't be possible without your help and patience. The comments are resolved now, except for one. While looking into optimization of the multiple map feature I saw an opportunity to improve speed with applyCallback that maybe could improve I see there is also similar objective in #3251 but I think it could still be applied after that. |
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.
All looks good, merging now.
Published now in |
Thank you Jos! |
Hi, this is intended to add multiple inputs to the function map.
Currently this includes:
It's missing:
Could you please give me advice on a recommended way to implement the transform function?
I have tried or studied the following alternatives:
At this point I'm stuck so any pointers are greatly appreciated.
this is related to #3196