Skip to content

Commit 066f346

Browse files
committed
Make SubArray constructors parametric
1 parent dd63c47 commit 066f346

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

base/subarray.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ parent(a::AbstractArray) = a
2727
parentindexes(a::AbstractArray) = ntuple(ndims(a), i->1:size(a,i))
2828

2929
## SubArray creation
30-
stagedfunction slice(A::AbstractArray, I::ViewIndex...)
30+
stagedfunction slice{T,NP}(A::AbstractArray{T,NP}, I::ViewIndex...)
3131
N = 0
3232
sizeexprs = Array(Any, 0)
3333
for k = 1:length(I)
@@ -38,12 +38,11 @@ stagedfunction slice(A::AbstractArray, I::ViewIndex...)
3838
end
3939
end
4040
dims = :(tuple($(sizeexprs...)))
41-
T = eltype(A)
4241
:(Base.SubArray{$T,$N,$A,$I}(A, I, $dims))
4342
end
4443

4544
# Conventional style (drop trailing singleton dimensions, keep any other singletons)
46-
stagedfunction sub(A::AbstractArray, I::ViewIndex...)
45+
stagedfunction sub{T,NP}(A::AbstractArray{T,NP}, I::ViewIndex...)
4746
sizeexprs = Array(Any, 0)
4847
Itypes = Array(Any, 0)
4948
Iexprs = Array(Any, 0)
@@ -72,8 +71,7 @@ end
7271

7372
# Constructing from another SubArray
7473
# This "pops" the old SubArray and creates a more compact one
75-
stagedfunction slice(V::SubArray, I::ViewIndex...)
76-
T, NV, PV, IV = V.parameters
74+
stagedfunction slice{T,NV,PV,IV}(V::SubArray{T,NV,PV,IV}, I::ViewIndex...)
7775
N = 0
7876
sizeexprs = Array(Any, 0)
7977
indexexprs = Array(Any, 0)
@@ -116,8 +114,7 @@ stagedfunction slice(V::SubArray, I::ViewIndex...)
116114
:(Base.SubArray{$T,$N,$PV,$It}(V.parent, $Inew, $dims))
117115
end
118116

119-
stagedfunction sub(V::SubArray, I::ViewIndex...)
120-
T, NV, PV, IV = V.parameters
117+
stagedfunction sub{T,NV,PV,IV}(V::SubArray{T,NV,PV,IV}, I::ViewIndex...)
121118
N = length(I)
122119
while N > 0 && I[N] <: Real
123120
N -= 1

0 commit comments

Comments
 (0)