Skip to content

Commit 268aae6

Browse files
galenlynchmartinholters
authored andcommitted
squeeze is now dropdims (#618)
* 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
1 parent 5a66c69 commit 268aae6

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ Currently, the `@compat` macro supports the following syntaxes:
292292

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

295-
* `squeeze` with `dims` as keyword argument ([#26660]).
296-
297295
* Single-argument `permutedims(x)` for matrices and vectors ([#24839]).
298296

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

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

435+
* `squeeze` is now `dropdims` ([#28303], [#26660]).
436+
437437
## New macros
438438

439439
* `@__DIR__` has been added ([#18380])
@@ -671,3 +671,4 @@ includes this fix. Find the minimum version from there.
671671
[#27828]: https://github.com/JuliaLang/julia/issues/27828
672672
[#27834]: https://github.com/JuliaLang/julia/issues/27834
673673
[#28302]: https://github.com/JuliaLang/julia/issues/28302
674+
[#28303]: https://github.com/JuliaLang/julia/issues/28303

src/Compat.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,25 @@ if VERSION < v"0.7.0-beta2.169"
20112011
export floatmin, floatmax
20122012
end
20132013

2014+
# https://github.com/JuliaLang/julia/pull/28303
2015+
if VERSION < v"0.7.0-beta2.143"
2016+
export dropdims
2017+
# https://github.com/JuliaLang/julia/pull/26660
2018+
if VERSION >= v"0.7.0-DEV.4738"
2019+
dropdims(
2020+
X;
2021+
dims = throw(
2022+
UndefKeywordError("dropdims: keyword argument dims not assigned"))
2023+
) = squeeze(X, dims = dims)
2024+
else
2025+
dropdims(
2026+
X;
2027+
dims = throw(
2028+
UndefKeywordError("dropdims: keyword argument dims not assigned"))
2029+
) = squeeze(X, dims)
2030+
end
2031+
end
2032+
20142033
include("deprecated.jl")
20152034

20162035
end # module Compat

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,4 +1935,12 @@ end
19351935
@test floatmax(Float32) == @eval $(Core.Intrinsics.bitcast(Float32, 0x7f7fffff))
19361936
@test floatmin(zero(Float64)) == floatmin(Float64)
19371937

1938+
# 0.7.0-beta2.143
1939+
if VERSION < v"0.7.0-beta2.143"
1940+
let a = reshape(Vector(1:4),(2,2,1,1)), b = reshape(Vector(1:4), (2,2,1))
1941+
@test dropdims(a; dims=3) == b
1942+
@test_throws UndefKeywordError dropdims(a)
1943+
end
1944+
end
1945+
19381946
nothing

0 commit comments

Comments
 (0)