|
2 | 2 |
|
3 | 3 | ## transpose and adjoint
|
4 | 4 |
|
5 |
| -function transpose_f!(f, At::AbstractGPUArray{T, 2}, A::AbstractGPUArray{T, 2}) where T |
6 |
| - gpu_call(At, A) do ctx, At, A |
7 |
| - idx = @cartesianidx A |
8 |
| - @inbounds At[idx[2], idx[1]] = f(A[idx[1], idx[2]]) |
| 5 | +function LinearAlgebra.transpose!(B::AbstractGPUVector, A::AbstractGPUMatrix) |
| 6 | + axes(B,1) == axes(A,2) && axes(A,1) == 1:1 || throw(DimensionMismatch("transpose")) |
| 7 | + copyto!(B, A) |
| 8 | +end |
| 9 | +function LinearAlgebra.transpose!(B::AbstractGPUMatrix, A::AbstractGPUVector) |
| 10 | + axes(B,2) == axes(A,1) && axes(B,1) == 1:1 || throw(DimensionMismatch("transpose")) |
| 11 | + copyto!(B, A) |
| 12 | +end |
| 13 | +function LinearAlgebra.adjoint!(B::AbstractGPUVector, A::AbstractGPUMatrix) |
| 14 | + axes(B,1) == axes(A,2) && axes(A,1) == 1:1 || throw(DimensionMismatch("adjoint")) |
| 15 | + gpu_call(B, A) do ctx, B, A |
| 16 | + idx = @linearidx B |
| 17 | + @inbounds B[idx] = adjoint(A[1, idx]) |
| 18 | + return |
| 19 | + end |
| 20 | + B |
| 21 | +end |
| 22 | +function LinearAlgebra.adjoint!(B::AbstractGPUMatrix, A::AbstractGPUVector) |
| 23 | + axes(B,2) == axes(A,1) && axes(B,1) == 1:1 || throw(DimensionMismatch("adjoint")) |
| 24 | + gpu_call(B, A) do ctx, B, A |
| 25 | + idx = @linearidx A |
| 26 | + @inbounds B[1, idx] = adjoint(A[idx]) |
9 | 27 | return
|
10 | 28 | end
|
11 |
| - At |
| 29 | + B |
12 | 30 | end
|
13 | 31 |
|
14 |
| -LinearAlgebra.transpose!(At::AbstractGPUArray, A::AbstractGPUArray) = transpose_f!(transpose, At, A) |
15 |
| -LinearAlgebra.adjoint!(At::AbstractGPUArray, A::AbstractGPUArray) = transpose_f!(adjoint, At, A) |
| 32 | +LinearAlgebra.transpose!(B::AbstractGPUArray, A::AbstractGPUArray) = transpose_f!(transpose, B, A) |
| 33 | +LinearAlgebra.adjoint!(B::AbstractGPUArray, A::AbstractGPUArray) = transpose_f!(adjoint, B, A) |
| 34 | +function transpose_f!(f, B::AbstractGPUMatrix{T}, A::AbstractGPUMatrix{T}) where T |
| 35 | + axes(B,1) == axes(A,2) && axes(B,2) == axes(A,1) || throw(DimensionMismatch(string(f))) |
| 36 | + gpu_call(B, A) do ctx, B, A |
| 37 | + idx = @cartesianidx A |
| 38 | + @inbounds B[idx[2], idx[1]] = f(A[idx[1], idx[2]]) |
| 39 | + return |
| 40 | + end |
| 41 | + B |
| 42 | +end |
16 | 43 |
|
17 | 44 | function Base.copyto!(A::AbstractGPUArray{T,N}, B::Adjoint{T, <: AbstractGPUArray{T,N}}) where {T,N}
|
18 | 45 | adjoint!(A, B.parent)
|
|
0 commit comments