-
-
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
cumsum inconvenient for RowVector #20041
Comments
So I just add a special case for a row vector, overriding the default? |
Note that |
If we did decide to treat it as one-dimensional for these functions, we'd probably want to do the same for a larger group of functions to ensure consistency. |
Isn't the point that it should be treated as one-dimensional when possible? As reflected in its name, |
That wasn't my understanding given the inheritance structure:
|
Despite the inheritance structure, a RowVector is intuitively
1-dimensional. I vote that we treat it as such for cumsum and related
functions.
…On Sat, Jan 14, 2017 at 9:50 PM, John Myles White ***@***.***> wrote:
That wasn't my understanding giving the inheritance structure:
julia> RowVector <: AbstractVector
false
julia> RowVector <: AbstractMatrix
true
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#20041 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANoEhG7BM3aliKhfnzzrDBTCTt0Rk2Fks5rSbOXgaJpZM4LjzCg>
.
|
What (i.e. which methods) is (are) actually inherited by the "inheritance structure"? |
So treat 1D row vector as column vector for cumsum? Which other functions can be modify like this? |
Given
I'd say these are not acting 1-dimensional at all. There's a row orientation behavior here. |
in any number of discussions around mit, we felt cumsum of a row vector should be a row vector. At one point I wanted to argue against row vectors acting two dimensionally even for broadcast, hcat and vcat, but after listening to Steven Johnson, I couldn't find a strong argument. So far my list of the triple status of a Julia row vector is something like this:
My opinions (this week): |
If we want to change this, we should be thorough and do it on all Collecting such a list might be a good opportunity for some rationalization and to decide whether we want to continue the Matlab-ism of having dimensions as a positional argument in many places (which leads to a number of ambiguities and inconsistent APIs), or make |
Notice that |
In preparing the PR, I was leaving all the behavior of So that said, I'm not surprised by the by the behavior reported in the OP. This doesn't mean we shouldn't aim for improvement in the future. But given that "soft" feature-freeze was 18 days ago, and what is the current implemented behavior is the minimally breaking change to get the linear algebra properties desired, it was my assumption that further breaking changes had to wait until post v0.6. If this is not the consensus, we should decide that ASAP. But if we rush we risk that the result may be somewhat incoherent. |
The primary problem here is that scan functions default to Instead we could define scan functions to do something that's useful for row matrices or column matrices and consistent for both. I think a useful definition which fits the bill is to e.g. have
With this behavior |
Yes, I was thinking the same thing, actually! |
Note that this computation is independent of memory layout modulo floating-point associativity. I.e. it would be independent if computations were exact, but we'll want to do the computation in memory order, scanning along the first column and then scanning along the second column, adding the corresponding element of the first column, etc. Regardless, I think that's good enough. |
Also known as Summed Area Table and Integral Image. |
Also, if we want to generalize this to |
Continuing the thought of generalizing this idea to |
Resolving #23018 first would make this better perhaps? |
I believe this can now be closed? Current behaviour is as follows: julia> w = [1, 2, 3]'
1×3 Adjoint{Int64,Array{Int64,1}}:
1 2 3
julia> cumsum(w)
┌ Warning: `cumsum(A::AbstractArray)` is deprecated, use `cumsum(A, 1)` instead.
│ caller = top-level scope
└ @ Core :0
1×3 Adjoint{Int64,Array{Int64,1}}:
1 2 3
julia> cumsum(w, 1)
1×3 Adjoint{Int64,Array{Int64,1}}:
1 2 3
julia> cumsum(w, 2)
1×3 Adjoint{Int64,Array{Int64,1}}:
1 3 6 |
Just to be sure: is |
I imagine I misunderstand your question, so let's iterate :). My understanding: If we remove but do not replace the deprecated single-argument |
I'm fine with deprecating and adding full functionality latere – just checking 👍 |
This is deprecated, so moving off the milestone. In 1.x we can implement the summed area table interpretation if we want. |
This thread's concerns might still apply to |
They all seem to be deprecated so I think we're fine for now: julia> cumsum(rand(3)')
┌ Warning: `cumsum(A::AbstractArray)` is deprecated, use `cumsum(A, 1)` instead.
│ caller = top-level scope
└ @ Core :0
1×3 Adjoint{Float64,Array{Float64,1}}:
0.635384 0.89566 0.875083
julia> cumsum(Adjoint(rand(3)))
┌ Warning: `cumsum(A::AbstractArray)` is deprecated, use `cumsum(A, 1)` instead.
│ caller = top-level scope
└ @ Core :0
1×3 Adjoint{Float64,Array{Float64,1}}:
0.58616 0.56026 0.552915
julia> cumsum(Transpose(rand(3)))
┌ Warning: `cumsum(A::AbstractArray)` is deprecated, use `cumsum(A, 1)` instead.
│ caller = top-level scope
└ @ Core :0
1×3 Transpose{Float64,Array{Float64,1}}:
0.380938 0.0475339 0.624499 |
Are there any other functions like |
Yes, that's a good point: julia> diff([1,2,3]')
0×3 Array{Int64,2} whereas it should behave more like this: julia> diff([1,2,3]', 2)
1×2 Array{Int64,2}:
1 1 however, I think that should probably produce a row vector when the input is a row vector. |
Adding to the list :). Though IIRC deprecating |
Deprecating it entirely? But it seems like such a basic, useful function. Note that n-d |
IIRC both deprecating |
I'm rather surprised to find that All that said, my preference would be to fix this behavior and let it be. |
These observations seem like a strong argument for at least a more appropriate / specific name? |
|
As an instance of |
Of course, one might just want to call |
One might, but that 107:1 ratio... 😄 |
Akin to `cumsum`, `diff` now requires a `dim` argument in cases where the array has more than one dimension. Final piece of #20041 for the 1.0 milestone.
The evidence strongly suggests that this is something Julia can do better :). |
* Deprecate diff(::AbstractMatrix), require a dim argument Akin to `cumsum`, `diff` now requires a `dim` argument in cases where the array has more than one dimension. Final piece of #20041 for the 1.0 milestone. * Add reference to this PR in NEWS.md
We're going to start calling you "Sacha, breaker of eggs" soon... 😝 |
Regrettably I am ignorant of the reference; enlighten me? :) |
Is Julia an omelette? 😄 |
It feels like a
RowVector
should act one-dimensionally in the following:cf. #4774 (comment)
The text was updated successfully, but these errors were encountered: