Permalink
Browse files

Fix squeeze() for arrays with one item

  • Loading branch information...
1 parent 2ad96bd commit 35d615ce930f48633020cc67b3cab4bc4bac621e @timholy timholy committed Feb 3, 2013
Showing with 8 additions and 4 deletions.
  1. +8 −4 base/abstractarray.jl
View
12 base/abstractarray.jl
@@ -152,10 +152,14 @@ reshape(a::AbstractArray, dims::Int...) = reshape(a, dims)
vec(a::AbstractArray) = reshape(a,max(size(a)))
function squeeze(A::AbstractArray)
- d = ()
- for i in size(A)
- if i != 1
- d = tuple(d..., i)
+ if length(A) == 1
+ d = (1,)
+ else
+ d = ()
+ for i in size(A)
+ if i != 1
+ d = tuple(d..., i)
+ end
end
end
reshape(A, d)

4 comments on commit 35d615c

@StefanKarpinski
The Julia Language member

I would argue that the old behavior was more correct.

@StefanKarpinski
The Julia Language member

I would also argue that almost any use of the squeeze function is probably a bug.

@StefanKarpinski
The Julia Language member

We should perhaps have a squeeze macro. I'll elaborate later.

@timholy
The Julia Language member

I'm sympathetic to the notion that squeeze is a bug, but if so we should delete it. I'll wait to hear your macro suggestion.

Please sign in to comment.