Skip to content

Commit

Permalink
Improve Closure hygiene, add test for updating assignment of symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Apr 3, 2021
1 parent ab266f8 commit 07a2a5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/closure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ end

struct Closure{E,A} <: Function end

@generated function (::Closure{E,A})(args::Tuple{Vararg{Any,K}}, var"##SUBSTART##"::Int, var"##SUBSTOP##"::Int) where {K,A,E}
@generated function (::Closure{var"##E##",var"##A##"})(var"##args##"::Tuple{Vararg{Any,var"##K##"}}, var"##SUBSTART##"::Int, var"##SUBSTOP##"::Int) where {var"##K##",var"##A##",var"##E##"}
q = Expr(:block)
gf = GlobalRef(Core, :getfield)
for k 1:K
push!(q.args, Expr(:(=), A[k], Expr(:call, gf, :args, k, false)))
for k 1:var"##K##"
push!(q.args, Expr(:(=), var"##A##"[k], Expr(:call, gf, Symbol("##args##"), k, false)))
end
q = quote
@inbounds begin
$q
var"##LOOPSTART##" = var"##SUBSTART##" * var"##LOOP_STEP##" - var"##LOOPOFFSET##"
var"##LOOP_STOP##" = var"##SUBSTOP##" * var"##LOOP_STEP##" - var"##LOOPOFFSET##"
$(toexpr(E))
$(toexpr(var"##E##"))
end
nothing
end
Expand Down
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ function sin_batch_sum(v)
end
return sum(view(s, 1, :))
end
function rowsum_batch!(x, A)
@batch for n axes(A,2)
s = 0.0
@simd for m axes(A,1)
s += A[m,n]
end
x[n] = s
end
end

@testset "Range Map" begin
function rangemap!(f::F, allargs, start, stop) where {F}
Expand Down Expand Up @@ -69,6 +78,10 @@ end
bsin!(y, x)
@test y == sin.(x)
@test sum(sin,x) sin_batch_sum(x)

A = rand(200,300); x = Vector{Float64}(undef, 300);
rowsum_batch!(x, A);
@test x vec(sum(A,dims=1))
end

@testset "start and stop values" begin
Expand Down Expand Up @@ -121,7 +134,7 @@ end
batch((length(x), max(1,num_threads()>>1), 2), dx, x) do (dx,x), start, stop
CheapThreads.threaded_gradient!(f, view(dx, start%Int:stop%Int), view(x, start%Int:stop%Int), ForwardDiff.Chunk(8))
end;
@test dx == dxref
@test dx dxref
end

println("Package tests complete. Running `Aqua` checks.")
Expand Down

2 comments on commit 07a2a5a

@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/33498

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.8 -m "<description of version>" 07a2a5aee0171e46a84e4efda60165cdc1c1b79f
git push origin v0.1.8

Please sign in to comment.