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 Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GPUArrays"
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
version = "12.0.0"
version = "12.0.1"

[workspace]
projects = ["lib/GPUArraysCore", "lib/JLArrays", "test", "docs"]
Expand Down
11 changes: 7 additions & 4 deletions src/host/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ Base.mapreducedim!(f, op, R::AnyGPUArray, A::AbstractArray) =
_ak_mapreducedim!(f, op, R, A; backend=get_backend(R))
Base.mapreducedim!(f, op, R::AnyGPUArray, A::Broadcast.Broadcasted) =
_ak_mapreducedim!(f, op, R, A; backend=get_backend(R))
# (LinearAlgebra's methods for adjoint and transposed matrices are ambiguous with these)
for W in (:Adjoint, :Transpose)
# (LinearAlgebra's methods for adjoint and transposed matrices, and Base's for permuted
# arrays, are ambiguous with these)
for (W, Wnum) in ((:(Adjoint{<:Any, <:AbstractMatrix}), :(Adjoint{<:Union{Real, Complex}, <:AbstractMatrix})),
(:(Transpose{<:Any, <:AbstractMatrix}), :(Transpose{<:Union{Real, Complex}, <:AbstractMatrix})),
(:PermutedDimsArray, :(PermutedDimsArray{<:Union{Real, Complex}})))
@eval begin
Base.mapreducedim!(f, op::Union{typeof(&), typeof(|), typeof(+), typeof(Base.add_sum),
typeof(max), typeof(min), typeof(Base._extrema_rf)},
R::AnyGPUArray, A::$W{<:Any, <:AbstractMatrix}) =
R::AnyGPUArray, A::$W) =
_ak_mapreducedim!(f, op, R, A; backend=get_backend(R))
Base.mapreducedim!(f::typeof(identity), op::Union{typeof(*), typeof(Base.mul_prod)},
R::AnyGPUArray, A::$W{<:Union{Real, Complex}, <:AbstractMatrix}) =
R::AnyGPUArray, A::$Wnum) =
_ak_mapreducedim!(f, op, R, A; backend=get_backend(R))
end
end
Expand Down
10 changes: 9 additions & 1 deletion test/testsuite/reductions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ end
@test compare((A,R)->Base.mapreducedim!(abs2, +, R, A), AT, rand(range, (3,2,10)), t(zeros(ET, (2,3))))
# ... and from them (LinearAlgebra has methods for these sources)
@test compare((A,R)->Base.mapreducedim!(identity, +, R, t(A)), AT, rand(range, (3,4)), zeros(ET, (4,)))
@test compare((A,R)->Base.mapreducedim!(abs2, max, R, t(A)), AT, rand(range, (3,4)), zeros(real(ET), (1,3)))
# (small values: Intel's compiler gets `abs2` of an overflowing `Complex{Int16}` wrong)
small = ET <: Complex ? ET.(complex.(rand(-9:9, 3, 4), rand(-9:9, 3, 4))) : rand(range, (3,4))
@test compare((A,R)->Base.mapreducedim!(abs2, max, R, t(A)), AT, small, zeros(real(ET), (1,3)))
@test compare((A,R)->Base.mapreducedim!(identity, *, R, t(A)), AT, rand(range, (3,4)), ones(ET, (4,)))

# TODO: reenable once https://github.com/JuliaGPU/Metal.jl/issues/907 is fixed
Expand All @@ -50,6 +52,12 @@ end
A, R = AT(rand(range, (3,2,10))), t(AT(zeros(ET, (2,3))))
@test Base.mapreducedim!(identity, *, R, A) === R
end

# ... and from permuted arrays (Base has methods for these sources)
p(A) = PermutedDimsArray(A, (3, 1, 2))
@test compare((A,R)->Base.mapreducedim!(identity, +, R, p(A)), AT, rand(range, (3,2,4)), zeros(ET, (4,1,1)))
ET <: Real && @test compare((A,R)->Base.mapreducedim!(identity, max, R, p(A)), AT, rand(range, (3,2,4)), fill(typemin(ET), (1,3,1)))
@test compare((A,R)->Base.mapreducedim!(identity, *, R, p(A)), AT, rand(range, (3,2,4)), ones(ET, (4,1,2)))
end
end

Expand Down
Loading