Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Force stagedfunction to be explicit about eltype and ndims
Browse files Browse the repository at this point in the history
This circumvents the inference problem in
JuliaLang/julia#8504
  • Loading branch information
timholy committed Nov 10, 2014
1 parent 872458c commit 9cfd4a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/ArrayViewsAPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ parent(V::View) = V.parent
parentindexes(V::View) = V.indexes

## View creation
# APL-style.
stagedfunction sliceview(A::AbstractArray, I::ViewIndex...)

stagedfunction sliceview{T,NP}(A::AbstractArray{T,NP}, I::ViewIndex...)
N = 0
sizeexprs = Any[]
for k = 1:length(I)
Expand All @@ -50,12 +50,11 @@ stagedfunction sliceview(A::AbstractArray, I::ViewIndex...)
end
end
dims = :(tuple($(sizeexprs...)))
T = eltype(A)
:(ArrayViewsAPL.View{$T,$N,$A,$I}(A, I, $dims))
end

# Conventional style (drop trailing singleton dimensions, keep any other singletons)
stagedfunction subview(A::AbstractArray, I::ViewIndex...)
stagedfunction subview{T,NP}(A::AbstractArray{T,NP}, I::ViewIndex...)
sizeexprs = Any[]
Itypes = Any[]
Iexprs = Any[]
Expand All @@ -77,15 +76,13 @@ stagedfunction subview(A::AbstractArray, I::ViewIndex...)
end
dims = :(tuple($(sizeexprs...)))
Iext = :(tuple($(Iexprs...)))
T = eltype(A)
It = tuple(Itypes...)
:(ArrayViewsAPL.View{$T,$N,$A,$It}(A, $Iext, $dims))
end

# Constructing from another View
# This "pops" the old View and creates a more compact one
stagedfunction sliceview(V::View, I::ViewIndex...)
T, NV, PV, IV = V.parameters
stagedfunction sliceview{T,NV,PV,IV}(V::View{T,NV,PV,IV}, I::ViewIndex...)
N = 0
sizeexprs = Any[]
indexexprs = Any[]
Expand Down Expand Up @@ -128,8 +125,7 @@ stagedfunction sliceview(V::View, I::ViewIndex...)
:(ArrayViewsAPL.View{$T,$N,$PV,$It}(V.parent, $Inew, $dims))
end

stagedfunction subview(V::View, I::ViewIndex...)
T, NV, PV, IV = V.parameters
stagedfunction subview{T,NV,PV,IV}(V::View{T,NV,PV,IV}, I::ViewIndex...)
N = length(I)
while N > 0 && I[N] <: Real
N -= 1
Expand Down
12 changes: 12 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function as_sub(x::AbstractMatrix)
y = similar(x, eltype(x), tuple(([size(x)...]*2)...))
y = subview(y, 2:2:size(y,1), 2:2:size(y,2))
for j=1:size(x,2)
for i=1:size(x,1)
y[i,j] = x[i,j]
end
end
y
end

as_sub(eye(2))
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include("core.jl")
include("arrayops.jl")
include("broadcast.jl")
include("fuzz.jl")

0 comments on commit 9cfd4a9

Please sign in to comment.