Skip to content

Commit c23d447

Browse files
Add squeeze with dims as keyword argument (#528)
* Add `squeeze` with `dims` as keyword argument * Add test that `squeeze([1,2])` throws
1 parent fa09434 commit c23d447

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

README.md

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

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

296+
* `squeeze` with `dims` as keyword argument ([#26660]).
297+
296298
## Renaming
297299

298300
* `Display` is now `AbstractDisplay` ([#24831]).
@@ -618,3 +620,4 @@ includes this fix. Find the minimum version from there.
618620
[#26369]: https://github.com/JuliaLang/julia/issues/26369
619621
[#26436]: https://github.com/JuliaLang/julia/issues/26436
620622
[#26442]: https://github.com/JuliaLang/julia/issues/26442
623+
[#26660]: https://github.com/JuliaLang/julia/issues/26660

src/Compat.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,9 @@ if VERSION < v"0.7.0-DEV.4534"
17771777
reverse(a::AbstractArray; dims=nothing) =
17781778
dims===nothing ? Base.reverse(a) : Base.flipdim(a, dims)
17791779
end
1780+
if VERSION < v"0.7.0-DEV.4738"
1781+
Base.squeeze(A; dims=error("squeeze: keyword argument dims not assigned")) = squeeze(A, dims)
1782+
end
17801783

17811784
if !isdefined(Base, :selectdim) # 0.7.0-DEV.3976
17821785
export selectdim

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,13 @@ end
16731673
@test length(Compat.CartesianIndices((1:2,))) == 2
16741674
@test length(Compat.CartesianIndices((1:2, -1:1))) == 6
16751675

1676+
# 0.7.0-DEV.4738
1677+
@test squeeze([1 2], dims=1) == [1, 2]
1678+
@test_throws ArgumentError squeeze([1 2], dims=2)
1679+
@test_throws ArgumentError squeeze(hcat([1, 2]), dims=1)
1680+
@test squeeze(hcat([1, 2]), dims=2) == [1, 2]
1681+
@test_throws Exception squeeze([1,2])
1682+
16761683
# 0.7.0-DEV.3976
16771684
let A = rand(5,5)
16781685
@test selectdim(A, 1, 3) == A[3, :]

0 commit comments

Comments
 (0)