Skip to content

Commit

Permalink
Fix getproperty lowering, fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Apr 4, 2021
1 parent e4ff272 commit f09bb74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ function totype!(funcs::Expr, arguments::Vector, defined::Set, q::Expr, expr::Ex
end
end
return Expr(:call, ex)
elseif head === :(.)
push!(defined, args[2].value)
end
for a args
push!(t.args, totype!(funcs, arguments, defined, q, a))
Expand Down Expand Up @@ -125,8 +127,13 @@ end
toexpr(x) = x
function (toexpr(@nospecialize(_::Expression{H,A}))::Expr) where {H,A}
ex = Expr(H)
for a A
push!(ex.args, toexpr(a))
if H === :(.)
push!(ex.args, toexpr(A[1]))
push!(ex.args, QuoteNode(A[2]))
else
for a A
push!(ex.args, toexpr(a))
end
end
ex
end
Expand Down
42 changes: 27 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,32 @@ function rowsum_batch!(x, A)
x[n] = s
end
end

@testset "Range Map" begin
function rangemap!(f::F, allargs, start, stop) where {F}
dest = first(allargs)
args = Base.tail(allargs)
@inbounds @simd for i start:stop
dest[i] = f(Base.unsafe_getindex.(args, i)...)
end
nothing
function bar!(dest, src)
@batch for i in eachindex(dest)
dest[i] = src.a.b[i]
end
dest
end

function tmap!(f::F, args::Vararg{AbstractArray,K}) where {K,F}
dest = first(args)
N = length(dest)
mapfun! = (allargs, start, stop) -> rangemap!(f, allargs, start, stop)
batch(mapfun!, (N, num_threads()), args...)
dest
function rangemap!(f::F, allargs, start, stop) where {F}
dest = first(allargs)
args = Base.tail(allargs)
@inbounds @simd for i start:stop
dest[i] = f(Base.unsafe_getindex.(args, i)...)
end
nothing
end

function tmap!(f::F, args::Vararg{AbstractArray,K}) where {K,F}
dest = first(args)
N = length(dest)
mapfun! = (allargs, start, stop) -> rangemap!(f, allargs, start, stop)
batch(mapfun!, (N, num_threads()), args...)
dest
end


@testset "Range Map" begin

x = rand(1024); y = rand(length(x)); z = similar(x);
foo(x,y) = exp(-0.5abs2(x-y))
Expand Down Expand Up @@ -82,6 +90,10 @@ end
A = rand(200,300); x = Vector{Float64}(undef, 300);
rowsum_batch!(x, A);
@test x vec(sum(A,dims=1))

dest = zeros(10^3); src = (; a = (; b = rand(length(dest))));
@test bar!(dest, src) == src.a.b

end

@testset "start and stop values" begin
Expand Down

2 comments on commit f09bb74

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/33530

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.9 -m "<description of version>" f09bb742db042965e4b8f267d09710e40859ee13
git push origin v0.1.9

Please sign in to comment.