Ah, this was tried once before to get included in Base, and it was turned 
down.  Colon makes much more sense here (and works better, too). 
 https://github.com/JuliaLang/julia/pull/4263

One final iteration (I'll see if we can get this version into Base):

function Base.reshape{N}(a::AbstractArray, dims::NTuple{N, Union(Int, 
Colon)})
    missing_mask = [isa(x, Colon) for x in dims]
    sum(missing_mask) == 1 || throw(DimensionMismatch("new dimensions 
$(dims) may only have up to one omitted dimension"))
    sz = length(a) / prod(dims[!missing_mask])
    sz == int(sz) || throw(DimensionMismatch("array size $(length(a)) must 
be divisible by the product of the new dimensions $(dims[!missing_mask])"))
    reshape(a, map(x->isa(x, Colon) ? int(sz) : x, dims))
end


Reply via email to