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

Deprecate diff(::AbstractMatrix), require a dim argument #25457

Merged
merged 2 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,9 @@ Deprecated or removed
* `workspace` is discontinued, check out [Revise.jl](https://github.com/timholy/Revise.jl)
for an alternative workflow ([#25046]).

* `cumsum`, `cumprod`, `accumulate`, and their mutating versions now require a `dim`
argument instead of defaulting to using the first dimension ([#24684]).
* `cumsum`, `cumprod`, `accumulate`, their mutating versions, and `diff` all now require a `dim`
argument instead of defaulting to using the first dimension unless there is only
one dimension ([#24684]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a reference to this PR too :)


* The `sum_kbn` and `cumsum_kbn` functions have been moved to the
[KahanSummation](https://github.com/JuliaMath/KahanSummation.jl) package ([#24869]).
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,8 @@ end

@deprecate cumsum(A::AbstractArray) cumsum(A, 1)
@deprecate cumprod(A::AbstractArray) cumprod(A, 1)
import .LinAlg: diff
@deprecate diff(A::AbstractMatrix) diff(A, 1)

# issue #16307
@deprecate finalizer(o, f::Function) finalizer(f, o)
Expand Down
13 changes: 10 additions & 3 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ tril!(M::AbstractMatrix) = tril!(M,0)
diff(a::AbstractVector) = [ a[i+1] - a[i] for i=1:length(a)-1 ]

"""
diff(A, [dim::Integer=1])
diff(A::AbstractVector)
diff(A::AbstractMatrix, dim::Integer)

Finite difference operator of matrix or vector `A`. If `A` is a matrix,
compute the finite difference over a dimension `dim` (default `1`).
specify the dimension over which to operate with the `dim` argument.

# Examples
```jldoctest
Expand All @@ -259,9 +260,15 @@ julia> diff(a,2)
2×1 Array{Int64,2}:
2
10

julia> diff(vec(a))
3-element Array{Int64,1}:
4
-2
12
```
"""
function diff(A::AbstractMatrix, dim::Integer=1)
function diff(A::AbstractMatrix, dim::Integer)
if dim == 1
[A[i+1,j] - A[i,j] for i=1:size(A,1)-1, j=1:size(A,2)]
elseif dim == 2
Expand Down
3 changes: 2 additions & 1 deletion test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,8 @@ timesofar("cat")
@check_bit_operation diff(b1) Vector{Int}

b1 = bitrand(n1, n2)
@check_bit_operation diff(b1) Matrix{Int}
@check_bit_operation diff(b1, 1) Matrix{Int}
@check_bit_operation diff(b1, 2) Matrix{Int}

b1 = bitrand(n1, n1)
@check_bit_operation svd(b1)
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ end
Bvs = eigvecs(B)
Avs = eigvecs(A)
Bvs = LAPACK.gebak!('S','R',ilo,ihi,scale,Bvs)
@test norm(diff(Avs ./ Bvs)) < 100 * eps(abs(float(one(elty))))
@test norm(diff(Avs ./ Bvs, 1)) < 100 * eps(abs(float(one(elty))))
end
end

Expand Down