Skip to content

Commit

Permalink
squeeze is now dropdims (#618)
Browse files Browse the repository at this point in the history
* squeeze is now dropdims

`squeeze` was renamed `dropdims` in [#28303](JuliaLang/julia#28303)

Fixes #617

* Support dropdims for dev versions where squeeze had KW arg

Also, remove README information about squeeze support, since dropdims is the
preferred replacement.

* Export dropdims
  • Loading branch information
galenlynch authored and martinholters committed Aug 21, 2018
1 parent 5a66c69 commit 268aae6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `selectdim` to obtain a view of an array with a specified index for a specified dimension ([#26009]).

* `squeeze` with `dims` as keyword argument ([#26660]).

* Single-argument `permutedims(x)` for matrices and vectors ([#24839]).

* `fetch` for `Task`s ([#25940]).
Expand Down Expand Up @@ -434,6 +432,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `realmin` and `realmax` are now `floatmin` and `floatmax` ([#28302])

* `squeeze` is now `dropdims` ([#28303], [#26660]).

## New macros

* `@__DIR__` has been added ([#18380])
Expand Down Expand Up @@ -671,3 +671,4 @@ includes this fix. Find the minimum version from there.
[#27828]: https://github.com/JuliaLang/julia/issues/27828
[#27834]: https://github.com/JuliaLang/julia/issues/27834
[#28302]: https://github.com/JuliaLang/julia/issues/28302
[#28303]: https://github.com/JuliaLang/julia/issues/28303
19 changes: 19 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,25 @@ if VERSION < v"0.7.0-beta2.169"
export floatmin, floatmax
end

# https://github.com/JuliaLang/julia/pull/28303
if VERSION < v"0.7.0-beta2.143"
export dropdims
# https://github.com/JuliaLang/julia/pull/26660
if VERSION >= v"0.7.0-DEV.4738"
dropdims(
X;
dims = throw(
UndefKeywordError("dropdims: keyword argument dims not assigned"))
) = squeeze(X, dims = dims)
else
dropdims(
X;
dims = throw(
UndefKeywordError("dropdims: keyword argument dims not assigned"))
) = squeeze(X, dims)
end
end

include("deprecated.jl")

end # module Compat
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1935,4 +1935,12 @@ end
@test floatmax(Float32) == @eval $(Core.Intrinsics.bitcast(Float32, 0x7f7fffff))
@test floatmin(zero(Float64)) == floatmin(Float64)

# 0.7.0-beta2.143
if VERSION < v"0.7.0-beta2.143"
let a = reshape(Vector(1:4),(2,2,1,1)), b = reshape(Vector(1:4), (2,2,1))
@test dropdims(a; dims=3) == b
@test_throws UndefKeywordError dropdims(a)
end
end

nothing

0 comments on commit 268aae6

Please sign in to comment.