diff --git a/base/linalg/adjoint.jl b/base/linalg/adjoint.jl index e69de29bb2d1d..299cdf67c715e 100644 --- a/base/linalg/adjoint.jl +++ b/base/linalg/adjoint.jl @@ -0,0 +1,42 @@ +# This file is a part of Julia. License is MIT: https://julialang.org/license + +adjoint(a::AbstractArray) = error("adjoint not defined for $(typeof(a)). Consider using `permutedims` for higher-dimensional arrays.") + +## Matrix adjoint ## + +""" + adjoint!(dest,src) + +Conjugate transpose array `src` and store the result in the preallocated array `dest`, which +should have a size corresponding to `(size(src,2),size(src,1))`. No in-place transposition +is supported and unexpected results will happen if `src` and `dest` have overlapping memory +regions. +""" +adjoint!(B::AbstractMatrix, A::AbstractMatrix) = transpose_f!(adjoint, B, A) +function adjoint!(B::AbstractVector, A::AbstractMatrix) + indices(B,1) == indices(A,2) && indices(A,1) == 1:1 || throw(DimensionMismatch("transpose")) + adjointcopy!(B, A) +end +function adjoint!(B::AbstractMatrix, A::AbstractVector) + indices(B,2) == indices(A,1) && indices(B,1) == 1:1 || throw(DimensionMismatch("transpose")) + adjointcopy!(B, A) +end + +function adjointcopy!(B, A) + RB, RA = eachindex(B), eachindex(A) + if RB == RA + for i = RB + B[i] = adjoint(A[i]) + end + else + for (i,j) = zip(RB, RA) + B[i] = adjoint(A[j]) + end + end +end + +function adjoint(A::AbstractMatrix) + ind1, ind2 = indices(A) + B = similar(A, adjoint_type(eltype(A)), (ind2, ind1)) + adjoint!(B, A) +end diff --git a/base/linalg/linalg.jl b/base/linalg/linalg.jl index 5ec561658a82c..830a41c0ee285 100644 --- a/base/linalg/linalg.jl +++ b/base/linalg/linalg.jl @@ -264,7 +264,7 @@ end include("conjarray.jl") -include("transpose.jl") +include("adjoint.jl") include("rowvector.jl") include("exceptions.jl") @@ -297,7 +297,6 @@ include("bitarray.jl") include("ldlt.jl") include("schur.jl") - include("arpack.jl") include("arnoldi.jl") diff --git a/base/linalg/transpose.jl b/base/linalg/transpose.jl deleted file mode 100644 index a5e263c804e31..0000000000000 --- a/base/linalg/transpose.jl +++ /dev/null @@ -1,42 +0,0 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license - -adjoint(a::AbstractArray) = error("adjoint not defined for $(typeof(a)). Consider using `permutedims` for higher-dimensional arrays.") - -## Matrix transposition ## - -""" - adjoint!(dest,src) - -Conjugate transpose array `src` and store the result in the preallocated array `dest`, which -should have a size corresponding to `(size(src,2),size(src,1))`. No in-place transposition -is supported and unexpected results will happen if `src` and `dest` have overlapping memory -regions. -""" -adjoint!(B::AbstractMatrix, A::AbstractMatrix) = transpose_f!(adjoint, B, A) -function adjoint!(B::AbstractVector, A::AbstractMatrix) - indices(B,1) == indices(A,2) && indices(A,1) == 1:1 || throw(DimensionMismatch("transpose")) - adjointcopy!(B, A) -end -function adjoint!(B::AbstractMatrix, A::AbstractVector) - indices(B,2) == indices(A,1) && indices(B,1) == 1:1 || throw(DimensionMismatch("transpose")) - adjointcopy!(B, A) -end - -function adjointcopy!(B, A) - RB, RA = eachindex(B), eachindex(A) - if RB == RA - for i = RB - B[i] = adjoint(A[i]) - end - else - for (i,j) = zip(RB, RA) - B[i] = adjoint(A[j]) - end - end -end - -function adjoint(A::AbstractMatrix) - ind1, ind2 = indices(A) - B = similar(A, adjoint_type(eltype(A)), (ind2, ind1)) - adjoint!(B, A) -end