Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/JLArrays/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JLArrays"
uuid = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
authors = ["Tim Besard <tim.besard@gmail.com>"]
version = "0.3.1"
version = "0.3.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
5 changes: 4 additions & 1 deletion lib/JLArrays/src/JLArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,15 @@ else
end
end

struct ArrayNoCopy end
Adapt.adapt_storage(::ArrayNoCopy, x::JLArray) = typed_data(x)

function GPUArrays.mapreducedim!(f, op, R::AnyJLArray, A::Union{AbstractArray,Broadcast.Broadcasted};
init=nothing)
if init !== nothing
fill!(R, init)
end
@allowscalar Base.reducedim!(op, typed_data(R), map(f, A))
@allowscalar Base.reducedim!(op, adapt(ArrayNoCopy(), R), map(f, A))
R
end

Expand Down
12 changes: 12 additions & 0 deletions test/testsuite/reductions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ end
# implicit singleton dimensions
@test compare((A,R)->Base.mapreducedim!(identity, +, R, A), AT, rand(range, (2,2)), zeros(ET, (2,)))
@test compare((A,R)->Base.mapreducedim!(identity, +, R, A), AT, rand(range, (2,3)), zeros(ET, (2,)))

# mapreducedim! into wrapper types
for t in [transpose, adjoint]
@test compare((A,R)->Base.mapreducedim!(identity, +, R, A), AT, rand(range, (2,2)), t(zeros(ET, (2,))))
@test compare((A,R)->Base.mapreducedim!(abs2, +, R, A), AT, rand(range, (3,2,10)), t(zeros(ET, (2,3))))

# TODO: reenable once https://github.com/JuliaGPU/Metal.jl/issues/907 is fixed
# @test compare((A,R)->sum!(abs2, R, A), AT, rand(range, (3,2,10)), t(zeros(ET, (2,3))))

A, R = AT(rand(range, (3,2,10))), t(AT(zeros(ET, (2,3))))
@test Base.mapreducedim!(identity, *, R, A) === R
end
end
end

Expand Down
Loading