-
Notifications
You must be signed in to change notification settings - Fork 323
A few extensions I've needed of ndarray #178
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
Comments
Thank you. sqrt is simple: norm -- good idea. max -- I already use this, so I agree.. Please use the type alias
sum_sqr_cw, I wonder if there is a more general way to do this. Same with submatrix. Does submatrix select the intersection of those rows and columns? |
I wasn't clear that I've implemented all of these for myself, implementations are obvious. I think all of these are common enough operations that there should be trivial patterns for them in ndarray (or an in-repo extension crate), the questions are about designing a nice language. I think all of these should create OwnedArrays; in-place variants are a low priority IMO. OwnedArray: sure. fold: I would just change the documentation to clearly not guarantee an ordering, and SHOUT it in the changelog. I do not think you have to worry about that level of compatibility and deprecation at this early stage, using the nicest names for important operations is much more important. I am not sure what you mean by intersection. A submatrix, just like a slice, receives a spec of the rows to keep and a spec of the columns to keep. These just happen to be arbitrary, hence cannot be fulfilled by striding the existing implementation, therefore I propose to create a copy. A view version could be possible if we generalize views to allow for sufficiently general coordinate mappings, but these cannot be expected to be fast. When space matters more than speed such view might be a good idea (and I've used BTreeMaps to do something similar at least once), but I would not advocate them now. Anyway, this obviously generalizes to subarray. sum_sqr_cw: yes, this begs for finding a nice way to implement as chained expressions, but the obivous BTW, in addition to numpy idioms for arrays, another rich source worthy of mining is R. |
Here's another one, a bit more of the general combinator flavour https://github.com/bluss/rust-ndarray/blob/master/ndarray-tests/tests/accuracy.rs#L254-L268 (fold axis can help computing min/max, ptp along an axis). |
I think we need a general-specific spectrum of languages around ndarray, so everything can be expressed, but common concepts are both readable and concise. map_reduce(mapper, reducer) is very general and usable for many one-off calculations, fold_axis and fold are more specific and efficient, but (for example) by far the most common folds are going to be sums and products over rows and columns (or other axes in higher dimensions), so how about stuff like: This starts to be almost as readable as So, shall we move Utils out of tests and start building it out? is there already a place/design for the matrix and vector specific traits? |
Good suggestion about .map_sum_columns. Or .map_sum(Axis, closure) if I'm allowed to stretch the generality of it. So, Rust 1.8 is nearing. Great news -- all the iadd methods will be gone and += and so on will be enabled. My idea was to split the crate into:
|
That looks like a good architecture to me. Should I wait for that change On Thu, Apr 7, 2016 at 12:12 PM, bluss notifications@github.com wrote:
Daniel Vainsencher |
The idea is the wait need not be that long. So, I'll get the split started today or tomorrow. If not.. PR away. |
If its a plan for the coming week, I'll definitely wait and aim at the On Thu, Apr 7, 2016 at 2:24 PM, bluss notifications@github.com wrote:
|
So I have experimented with the split plan. I've finally found the pain that was foretold. Reexporting ndarray-core into ndarray does a number on rustdoc and some things come out subtly worse. It uses The core split plan is cancelled. I will have a second go at a super crate, without a core split now. |
Hmm, I didn't suspect rustdoc as a source of pain, though it makes sense. On the other hand, incremental compilation may alleviate some of the pain Daniel On Fri, Apr 8, 2016 at 11:39 AM, bluss notifications@github.com wrote:
|
Maybe it works out if we use ndarray as a strong idependent core, and a new crate that includes it and extends it (without pretending to be a facade to it).
just needs a nicer name than ndarray-numeric. It might require dropping the ndarray "brand" from the name.. I have an idea. |
I've found a split that works, but I wonder what you think.
How I ported my projects to use it:
|
Looks good to me. As usual, I think you should see design for growth first, Change that only around a 1.0 release, and not hurry to do that one.
|
Not sure how to design for growth first. I think ndarray has accomplished its original goals (an efficient nd array). Now we want to add more features, two categories, numerics and linalg. |
Ok after exploration of ndarray-core split, ndarray/ndnum split etc I don't want to split anymore. 😄 Exploration is good anyway. It's hard to divorce ndarray from numerics. The trait impls (Add and everything else) needs to be in the main crate. There's been some fruitful splitting of code anyway, for example matrixmultiply is an external crate. We can maybe continue like that. So. src/numeric/ will be a new directory. If we need any super specific types or functions, the module can even be public. Either way, new functionality is welcome there. |
For growth means convenient for you first and for other contributors. One big crate is good for that as long as compilation time stays reasonable. Not sure how to design for growth first. I think ndarray has accomplished its original goals (an efficient nd array). Now we want to add more features, two categories, numerics and linalg. — |
Thanks for expanding on that. I appreciate the feedback! |
When I write a map + fold (along an axis) combination, it seems to me it is equivalent to just .fold-axis() /// Combine an elementwise mapping with a fold along an axis
pub fn map_fold<B, C, F, G>(&self, axis: Axis, mut map: F, init: C, mut fold: G)
-> OwnedArray<C, D::Smaller>
where D: RemoveAxis,
F: FnMut(&A) -> B,
G: FnMut(&C, B) -> C,
B: Clone,
C: Clone,
{
let n = self.shape().axis(axis);
let mut res = OwnedArray::from_elem(self.dim().remove_axis(axis), init);
for subview in self.axis_iter(axis) {
res.zip_mut_with(&subview, |x, y| *x = fold(x, map(y)));
}
res
} is this the kind of map reduce you were thinking of? |
By map reduce I meant the general operation, where the aggregation can be The function you proposed above is included in fold_axis no? Daniel On Sun, Apr 10, 2016 at 12:35 PM, bluss notifications@github.com wrote:
|
I'm looking for |
They still need to be implemented. We've prioritized general operations first before adding more specific ones. |
I'd like to suggest adding |
Relevant to any dimension:
Relevant to matrices only:
BTW, I receive a warning that fold is deprecated because it forces a particular order. I am not sure what you mean by that, and what is a good replacement for it.
I can submit a PR for those if welcome.
The text was updated successfully, but these errors were encountered: