Skip to content

Commit

Permalink
Add squeeze with dims as keyword argument (#528)
Browse files Browse the repository at this point in the history
* Add  `squeeze` with `dims` as keyword argument

* Add test that `squeeze([1,2])` throws
  • Loading branch information
martinholters authored Apr 16, 2018
1 parent fa09434 commit c23d447
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ 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]).

## Renaming

* `Display` is now `AbstractDisplay` ([#24831]).
Expand Down Expand Up @@ -618,3 +620,4 @@ includes this fix. Find the minimum version from there.
[#26369]: https://github.com/JuliaLang/julia/issues/26369
[#26436]: https://github.com/JuliaLang/julia/issues/26436
[#26442]: https://github.com/JuliaLang/julia/issues/26442
[#26660]: https://github.com/JuliaLang/julia/issues/26660
3 changes: 3 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,9 @@ if VERSION < v"0.7.0-DEV.4534"
reverse(a::AbstractArray; dims=nothing) =
dims===nothing ? Base.reverse(a) : Base.flipdim(a, dims)
end
if VERSION < v"0.7.0-DEV.4738"
Base.squeeze(A; dims=error("squeeze: keyword argument dims not assigned")) = squeeze(A, dims)
end

if !isdefined(Base, :selectdim) # 0.7.0-DEV.3976
export selectdim
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,13 @@ end
@test length(Compat.CartesianIndices((1:2,))) == 2
@test length(Compat.CartesianIndices((1:2, -1:1))) == 6

# 0.7.0-DEV.4738
@test squeeze([1 2], dims=1) == [1, 2]
@test_throws ArgumentError squeeze([1 2], dims=2)
@test_throws ArgumentError squeeze(hcat([1, 2]), dims=1)
@test squeeze(hcat([1, 2]), dims=2) == [1, 2]
@test_throws Exception squeeze([1,2])

# 0.7.0-DEV.3976
let A = rand(5,5)
@test selectdim(A, 1, 3) == A[3, :]
Expand Down

0 comments on commit c23d447

Please sign in to comment.