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

Pass arbitrary data to pre/body/post #8

Closed
rreusser opened this issue Aug 14, 2015 · 4 comments
Closed

Pass arbitrary data to pre/body/post #8

rreusser opened this issue Aug 14, 2015 · 4 comments

Comments

@rreusser
Copy link
Member

It's possible to pass a scalar to the body function, but is there any way of passing arbitrary data to the functions? (arg type=object?) I've encountered a couple cases where this would be convenient and, I believe, valid:

  • Passing a function to cwise. Think of an image processing function. Unless body implements the function or the function is defined in the containing scope (which isn't always possible if you don't know the function ahead of time, right?), it's not immediately clear how to pass this.
  • More questionable uses. I'm currently trying to write a axis-wise function that computes the mean across a number of axes. This can be accomplished with transpose + blockIndices + map-reduce, but it's not clear how to pass the data in/out.

Long story short, here are the two possibilities:

  • add an object type for passing arbitrary stuff that's useful
  • this isn't really what cwise is for and would defeat the purpose of the useful optimizations it provides
@mikolalysenko
Copy link
Member

You can pass objects and functions into the scalar type. The name scalar was chosen because it wasn't an array, so I can understand the confusion. Take a look at ndarray-warp:

https://github.com/scijs/ndarray-warp

@rreusser
Copy link
Member Author

Ah, great. I can submit a PR with this clarification. Thought this might be the case but figured it was worth clarifying whether it was more than an accidental if so.

@rreusser
Copy link
Member Author

cc: @thibauts since it seemed like you might have been working with a similar use-case…

@thibauts
Copy link

I had exactly the same question. Might be worthwhile to put the information in the relevant README section so people don't miss it, or alias scalar with something like object that's generic enough for people to feel confident passing functions or arbitrary stuff.

Edit: well, looks like that's exactly what you suggested :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants