Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,34 @@ function reshape(a::AbstractArray, dims::Dims)
end
copy!(similar(a, dims), a)
end

function reshape(A::AbstractArray, dims::(Union(Int, Colon)...))
new_dims = Array(Int, length(dims))
dim_product = 1.
missing_dim_idx = -1
colon = Colon()
for i = 1:length(dims)
if dims[i] != colon
new_dims[i] = dims[i]
dim_product *= dims[i]
else
if missing_dim_idx == -1
missing_dim_idx = i
else
error("reshape: only one implicit dimension allowed")
end
end
end
missing_dim_value, remainder = divrem(length(A), dim_product)
if remainder != 0
error("reshape: invalid dimensions")
end
new_dims[missing_dim_idx] = missing_dim_value
reshape(A, new_dims...)
end

reshape(a::AbstractArray, dims::Int...) = reshape(a, dims)
reshape(a::AbstractArray, dims::Union(Int, Colon)...) = reshape(a, dims)

vec(a::AbstractArray) = reshape(a,length(a))
vec(a::AbstractVector) = a
Expand Down