From 066f346b39f0d0ee7962fc61ff72e681b8787329 Mon Sep 17 00:00:00 2001 From: timholy Date: Sat, 8 Nov 2014 11:37:14 -0600 Subject: [PATCH] Make SubArray constructors parametric --- base/subarray.jl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/base/subarray.jl b/base/subarray.jl index 6e3c6c74a5643c..e3a398a08e9f48 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -27,7 +27,7 @@ parent(a::AbstractArray) = a parentindexes(a::AbstractArray) = ntuple(ndims(a), i->1:size(a,i)) ## SubArray creation -stagedfunction slice(A::AbstractArray, I::ViewIndex...) +stagedfunction slice{T,NP}(A::AbstractArray{T,NP}, I::ViewIndex...) N = 0 sizeexprs = Array(Any, 0) for k = 1:length(I) @@ -38,12 +38,11 @@ stagedfunction slice(A::AbstractArray, I::ViewIndex...) end end dims = :(tuple($(sizeexprs...))) - T = eltype(A) :(Base.SubArray{$T,$N,$A,$I}(A, I, $dims)) end # Conventional style (drop trailing singleton dimensions, keep any other singletons) -stagedfunction sub(A::AbstractArray, I::ViewIndex...) +stagedfunction sub{T,NP}(A::AbstractArray{T,NP}, I::ViewIndex...) sizeexprs = Array(Any, 0) Itypes = Array(Any, 0) Iexprs = Array(Any, 0) @@ -72,8 +71,7 @@ end # Constructing from another SubArray # This "pops" the old SubArray and creates a more compact one -stagedfunction slice(V::SubArray, I::ViewIndex...) - T, NV, PV, IV = V.parameters +stagedfunction slice{T,NV,PV,IV}(V::SubArray{T,NV,PV,IV}, I::ViewIndex...) N = 0 sizeexprs = Array(Any, 0) indexexprs = Array(Any, 0) @@ -116,8 +114,7 @@ stagedfunction slice(V::SubArray, I::ViewIndex...) :(Base.SubArray{$T,$N,$PV,$It}(V.parent, $Inew, $dims)) end -stagedfunction sub(V::SubArray, I::ViewIndex...) - T, NV, PV, IV = V.parameters +stagedfunction sub{T,NV,PV,IV}(V::SubArray{T,NV,PV,IV}, I::ViewIndex...) N = length(I) while N > 0 && I[N] <: Real N -= 1