Skip to content

Commit

Permalink
New function fixate_eltype
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Jun 13, 2016
1 parent bb16a82 commit c574b4d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ length(t::AbstractArray) = prod(size(t))::Int
endof(a::AbstractArray) = length(a)
first(a::AbstractArray) = a[first(eachindex(a))]

function fixate_eltype{T<:AbstractArray}(::Type{T}, default::Type)
@_pure_meta
aa_type = T
while aa_type.name.primary != AbstractArray
aa_type = supertype(aa_type)
end
if isa(aa_type.parameters[1], TypeVar)
varname = aa_type.parameters[1].name
new_params = collect(T.parameters)
for (i, p) in enumerate(new_params)
if isa(p, TypeVar) && p.name == varname
new_params[i] = default
end
end
return T.name.primary{new_params...}
else
return T
end
end

function check_array_size(dims::DimsInteger)
for i in 1:length(dims)
dims[i] >= 0 || throw(ArgumentError("dimension size must be ≥ 0, got $(dims[i]) for dimension $i"))
Expand Down

0 comments on commit c574b4d

Please sign in to comment.