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

Add method to modify elements in place #153

Closed
bluss opened this issue Mar 15, 2016 · 3 comments
Closed

Add method to modify elements in place #153

bluss opened this issue Mar 15, 2016 · 3 comments

Comments

@bluss
Copy link
Member

bluss commented Mar 15, 2016

A value-to-value mapper would be convenient, something like array.apply(f32::abs) it could even be called lift.

@bluss
Copy link
Member Author

bluss commented Mar 15, 2016

We want to find a nice convention to make it consistent.

Maybe something like this, saying map for an operation that makes a new array, and apply for modifying in place. Since all the float functions are by value "|A| -> A", it would be important to offer this.

 .map(&self, |&A| -> B) -> OwnedArray<B, D>
 .mapv(&self, |A| -> B) -> OwnedArray<B, D>
 .apply(&mut self, |&mut A|)
 .applyv(&mut self, |A| -> A)
 .visit(&self, |&A|)

@jdroenner
Copy link

Maybe the map operations could be lazy like iterator adapters. A MapView(or something like this) would have a reference/view of an array and a map function. This would allow to use get(dim)without processing the total array first (could be useful for sampling). Also chaining of multiple map operations could be possible. A function like collect could be used to materialize into a new OwnedArray. This could also be interesting for #120 or #127.

@bluss
Copy link
Member Author

bluss commented Mar 16, 2016

That's a nice idea. It's similar to this #88 (comment)

Making an operation an object that itself can participate in operations on arrays makes particular sense in an even more generic-heavy implementation. For that reason ndarray will not take that route now, I think.

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