-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
mean function on dimension #2265
Comments
#2266 didn't appear to address this. |
#2200 indirectly discussed this. I asked for mean, median and var treating this the same way and I guess the result is that functions along dimensions is delgated to new amap style functions (which I think is fine), but I am not sure. @StefanKarpinski may have something to add here. One problem with the Matlab way is that |
This was intentionally removed. @JeffBezanson may have some suggestions of ways to accomplish this instead. |
|
I think it is best to have |
The reason it's not in base is that it was unclear how these calls should look. The |
Fair enough. I'll take a look at what other languages do for |
There's also a point where you want to stop adding dimension arguments to every function and start using higher order functions for that kind of thing. I feel like this may be that point. |
Do you feel the same way about |
Yeah, that's the problem. Those are heavily used in Matlab style code and they are pretty handy to have a dimension argument for. So I don't know. |
Keyword arguments (#485) would probably be useful here. |
How about adding a Dim type? For example, In a simple implementation
Note it stores an I'm playing with this right now in the context of image processing, adding an |
Using |
In case of |
What if you want to support |
I would prefer to force the use of |
I was simply responding to your proposal to support both FYI Matlab behaves exactly as in the example I just gave you:
Matlab uses the ugly If we go with the |
Oh yes - it has been so long since I used matlab that I actually forgot how I hated that syntax. |
The |
I take that back, |
I like det |
I'm fairly confident that the known-mean variant is not widely used in On Fri, Feb 22, 2013 at 9:26 AM, Andreas Noack Jensen <
|
Agreed. It's actually a more serious issue for |
First pass at implemented the Dim type for JuliaLang#2265. For an array A, you can now call, e.g.: max(A, Dim(1)). The Dim type can be constructed with integers, arrays, ranges, or tuples, so all of the following are valid: Dim(1) Dim(1, 2) Dim([1]) Dim([1,2]) Dim([1 2]) Dim(1:2)
I strongly feel that the sanest thing is to use a higher-order function |
Note that @JeffBezanson, the |
An |
The performance issue is a good point; the higher-order function can't do the fastest thing unless it has lots of special cases inside it anyway. I would also not be fully comfortable telling people to write something much longer than |
If the performance problem could be solved, I'd agree with @JeffBezanson. But right now the performance gap would be too big. Simple example:
I'm not really excited about that kind of price, so I think we need a short-term solution. BTW, nice work @blakejohnson for putting this together so we can all see what it would look like in practice. |
I know this discussion has been going on for a while and consensus is emerging, but I really feel like |
I think Jeff makes a very valid point here. Personally, I'm not sold on the |
@JeffBezanson Not every language. Python/NumPy uses |
So, what's the solution here? The options suggested so far:
|
I prefer No.4 |
True, but non-numpy python also has |
Do we know how much performance we would lose with keyword arguments? If it is something like 10-25%, and we have a plan for regaining the lost performance, it would certainly be the right way to go. In general, it would be nice if people's codes do not slow down across releases. One exercise could be to implement |
Of the four suggestions above outlined by @blakejohnson, my preferences are in the order: 4, 3, 2, 1. |
I think everyone likes option 4, when it becomes available. Option 2 is the closest we can get right now, and it looks pretty clean in use. It's also no more keystrokes than a keyword argument... |
It also leverages type dispatch better than a keyword argument. |
I should explain the last comment more thoroughly. From a user's perspective,
Here, In contrast, the
The point is, the type system is actually quite good for eliminating ambiguity, which is really what we're talking about here: is that integer a comparison value or a dimension index? This is getting even better with the impending arrival of immutable types, for which the whole point (as far as I can tell) is to provide interpretive context for sequences of bits. Keyword arguments seem to be best for "overriding" behavior that you'd rather not have to specify on a regular basis, but that's really quite different from the conceptual challenge here. |
@timholy that's a very good point, and bumps option 2 ( If we go with a |
With the implementations we're considering, you could define:
So while not entirely dispatching on keyword args, still possible to dispatch on whether any are present at all. |
Aha, the first case in favor of dispatch on keyword arguments! :) |
I played around with some timings on Jeff's jb/kwargs branch. I couldn't measure any difference between |
So, please, what's the current alternative to doing:
since it disapeared in release-0.1 and broke my code ? |
Install the Stats package and then that line will work. On Tuesday, March 5, 2013 at 9:40 AM, Christophe MEYER wrote:
|
I think we made the wrong call on I mean, look at this help entry:
I vote for |
Not my specialty and not my call, but I agree with @nolta . The known-mean version is exotic enough to be renamed. Or we can add a |
Agreed. The proposed known-mean alternatives are |
I still think the names As for the help docs (which I wrote), I think their verbosity reflects the continued absence of a viable mechanism for splitting documentation into appropriate components. The current docs are an attempt to provide something like a condensed version of what R documentation would call the "Details" section. For things like variances which have different definitions for different communities, I think it's really important that the exact object being computed is described in detail somewhere in our documentation. |
@nolta So, are you also suggesting to drop support for the 'corrected' flag to choose between N and N-1 normalization? |
@blakejohnson Yes, for two reasons: 1) R's |
I'm on board with that. |
I believe in the recent shuffle that mean on dimensions of a matrix does not work.
Eg. mean([2 3 4; 1 2 3],2)
The text was updated successfully, but these errors were encountered: