Skip to content

Commit 78e6106

Browse files
committed
Graceful exit for transpose/adjoint on size 0 arrays
1 parent a272442 commit 78e6106

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/host/linalg.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ LinearAlgebra.transpose!(B::AnyGPUArray, A::AnyGPUArray) = transpose_f!(transpos
3535
LinearAlgebra.adjoint!(B::AnyGPUArray, A::AnyGPUArray) = transpose_f!(adjoint, B, A)
3636
function transpose_f!(f, B::AnyGPUMatrix{T}, A::AnyGPUMatrix{T}) where T
3737
axes(B,1) == axes(A,2) && axes(B,2) == axes(A,1) || throw(DimensionMismatch(string(f)))
38+
# array with size zero dimension
39+
axes(A,1) == 1:0 || axes(A, 2) == 1:0 && return B
3840
@kernel function transpose_kernel!(B, A)
3941
idx = @index(Global, Cartesian)
4042
@inbounds B[idx[2], idx[1]] = f(A[idx[1], idx[2]])

test/testsuite/linalg.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
@test compare(adjoint!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32))
55
@test compare(adjoint!, AT, rand(Float32, 1, 32), rand(Float32, 32))
66
@test compare(adjoint!, AT, rand(Float32, 32), rand(Float32, 1, 32))
7+
@test compare(adjoint!, AT, rand(Float32, 32, 0), rand(Float32, 0, 32))
8+
@test compare(adjoint!, AT, rand(Float32, 0, 32), rand(Float32, 32, 0))
79
@test compare(transpose, AT, rand(Float32, 32, 32))
810
@test compare(transpose!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32))
911
@test compare(transpose!, AT, rand(Float32, 1, 32), rand(Float32, 32))
1012
@test compare(transpose!, AT, rand(Float32, 32), rand(Float32, 1, 32))
13+
@test compare(transpose!, AT, rand(Float32, 32, 0), rand(Float32, 0, 32))
14+
@test compare(transpose!, AT, rand(Float32, 0, 32), rand(Float32, 32, 0))
1115
@test compare((x,y)->copyto!(x, adjoint(y)), AT, rand(Float32, 32, 32), rand(Float32, 32, 32))
1216
@test compare((x,y)->copyto!(x, transpose(y)), AT, rand(Float32, 32, 32), rand(Float32, 32, 32))
1317
@test compare(transpose!, AT, Array{Float32}(undef, 32, 32), rand(Float32, 32, 32))

0 commit comments

Comments
 (0)