Skip to content

Commit

Permalink
Make SubArray constructors parametric
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Nov 11, 2014
1 parent dd63c47 commit 066f346
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 066f346

Please sign in to comment.