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

cwise docs out of data? #17

Open
matt-erhart opened this issue Sep 5, 2017 · 2 comments
Open

cwise docs out of data? #17

matt-erhart opened this issue Sep 5, 2017 · 2 comments

Comments

@matt-erhart
Copy link

In some of the examples, a cwise function can be called these two ways:

let somearray = cwiseFunc(arr1, arr2)
cwiseFunc(somearray, arr1, arr2)

I could only get the second to work, so I wonder if the docs aren't up to date in this and perhaps other ways. Also, is this expected to work without the browserify transform or is that just to get size down? I'm in webpack.

In the mean time, any links to repos making use of cwise would get great to check out.

@rreusser
Copy link
Member

rreusser commented Sep 5, 2017

@matt-erhart I think it depends on the specific operation what the inputs and outputs are. In particular from the docs:

If no return statement is specified, the first ndarray argument is returned

That means there's not necessarily a single answer to what the return value would be. A reduction operator (like a sum or a max, etc.) would return the sum while other operators by default would return the first ndarray argument.

If you use ndarray-ops, the functions are pretty explicit about whether it's an in-place operator or not, e.g. add (c = a + b) vs. addeq (a += b). ndarray-ops also uses precompiled operators so that you don't have to worry about the browserify transform. In other words, ndarray-ops doesn't cover every use-case but the code is already transformed, which might be helpful.

As for the browserify transform, that's correct. You can use cwise with or without it. cwise uses esprima to parse the function code. This makes writing the body of the operator very easy but allows cwise to be sophisticated about how it actually applies the transform (in particular, it performs math in an inner loop instead of actually calling body as a function). Esprima is a pretty big dependency though. Without the browserify transform, esprima is a dependency and the operator is created in user-facing code. With the transform, the operator is created at build time so that esprima is not a client-side dependency. I think you can use ify-loader to use the cwise transform with webpack. I don't have an example repo on hand, but if you have success with this method, I'd love to hear about it!

@rreusser
Copy link
Member

rreusser commented Sep 5, 2017

(Apologies for the scattered answer. You're basically correct. Things should work just fine, but if you run into problems, don't hesitate to ask more questions.)

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

2 participants