From 8699d98dda845f0c3d0ca4052981c17da813cfc3 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 16 Dec 2017 14:03:07 -0800 Subject: [PATCH 1/5] Rewrite isolated ' calls in base/ to preserve behavior through ' lowering changes. --- base/deprecated.jl | 4 ++-- base/linalg/bidiag.jl | 4 ++-- base/linalg/cholesky.jl | 10 +++++----- base/linalg/conjarray.jl | 4 ---- base/linalg/dense.jl | 2 +- base/linalg/diagonal.jl | 2 +- base/linalg/generic.jl | 4 ++-- base/linalg/lq.jl | 2 +- base/linalg/qr.jl | 2 +- base/linalg/rowvector.jl | 6 +++--- base/linalg/svd.jl | 4 ++-- base/linalg/symmetric.jl | 22 +++++++++++----------- base/linalg/triangular.jl | 4 ++-- base/operators.jl | 2 +- base/pkg/resolve/maxsum.jl | 2 +- base/rational.jl | 2 +- base/sparse/linalg.jl | 2 +- base/sparse/sparsevector.jl | 2 +- base/statistics.jl | 2 +- 19 files changed, 39 insertions(+), 43 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index ffa6761f0808f..5d2963ed8f8e6 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -3047,7 +3047,7 @@ end ```jldoctest julia> v = [1; im]; - julia> vc = v'; + julia> vc = RowVector(v); julia> norm(vc, 1) 1.0 @@ -3103,7 +3103,7 @@ end *(transA::Transpose{<:Any,<:AbstractTriangular}, transrowvec::Transpose{<:Any,<:RowVector}) = transA * rvtranspose(transrowvec.parent) *(rowvec::RowVector, adjA::Adjoint{<:Any,<:AbstractTriangular}) = rvadjoint(adjA.parent * rvadjoint(rowvec)) *(A::AbstractTriangular, adjrowvec::Adjoint{<:Any,<:RowVector}) = A * rvadjoint(adjrowvec.parent) - *(adjA::Adjoint{<:Any,<:AbstractTriangular}, adjrowvec::Adjoint{<:Any,<:RowVector}) = adjA.parent' * rvadjoint(adjrowvec.parent) + *(adjA::Adjoint{<:Any,<:AbstractTriangular}, adjrowvec::Adjoint{<:Any,<:RowVector}) = adjA * rvadjoint(adjrowvec.parent) \(::Union{UpperTriangular,LowerTriangular}, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) \(::Union{UnitUpperTriangular,UnitLowerTriangular}, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) \(::Adjoint{<:Any,<:Union{UpperTriangular,LowerTriangular}}, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index d9a64b244931e..aba2c0196f282 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -522,7 +522,7 @@ function ldiv!(adjA::Adjoint{<:Any,<:Union{Bidiagonal,AbstractTriangular}}, B::A tmp = similar(B,size(B,1)) n = size(B, 1) if mA != n - throw(DimensionMismatch("size of A' is ($mA,$nA), corresponding dimension of B is $n")) + throw(DimensionMismatch("size of adjoint of A is ($mA,$nA), corresponding dimension of B is $n")) end for i = 1:size(B,2) copyto!(tmp, 1, B, (i - 1)*n + 1, n) @@ -537,7 +537,7 @@ function ldiv!(transA::Transpose{<:Any,<:Union{Bidiagonal,AbstractTriangular}}, tmp = similar(B,size(B,1)) n = size(B, 1) if mA != n - throw(DimensionMismatch("size of A' is ($mA,$nA), corresponding dimension of B is $n")) + throw(DimensionMismatch("size of transpose of A is ($mA,$nA), corresponding dimension of B is $n")) end for i = 1:size(B,2) copyto!(tmp, 1, B, (i - 1)*n + 1, n) diff --git a/base/linalg/cholesky.jl b/base/linalg/cholesky.jl index 0e36604a6f67e..3a8f1705e8914 100644 --- a/base/linalg/cholesky.jl +++ b/base/linalg/cholesky.jl @@ -87,7 +87,7 @@ function _chol!(A::AbstractMatrix, ::Type{UpperTriangular}) return UpperTriangular(A), info end A[k,k] = Akk - AkkInv = inv(Akk') + AkkInv = inv(adjoint(Akk)) for j = k + 1:n for i = 1:k - 1 A[k,j] -= A[i,k]'A[i,j] @@ -381,14 +381,14 @@ size(C::Union{Cholesky, CholeskyPivoted}) = size(C.factors) size(C::Union{Cholesky, CholeskyPivoted}, d::Integer) = size(C.factors, d) function getindex(C::Cholesky, d::Symbol) - d == :U && return UpperTriangular(Symbol(C.uplo) == d ? C.factors : C.factors') - d == :L && return LowerTriangular(Symbol(C.uplo) == d ? C.factors : C.factors') + d == :U && return UpperTriangular(Symbol(C.uplo) == d ? C.factors : adjoint(C.factors)) + d == :L && return LowerTriangular(Symbol(C.uplo) == d ? C.factors : adjoint(C.factors)) d == :UL && return Symbol(C.uplo) == :U ? UpperTriangular(C.factors) : LowerTriangular(C.factors) throw(KeyError(d)) end function getindex(C::CholeskyPivoted{T}, d::Symbol) where T<:BlasFloat - d == :U && return UpperTriangular(Symbol(C.uplo) == d ? C.factors : C.factors') - d == :L && return LowerTriangular(Symbol(C.uplo) == d ? C.factors : C.factors') + d == :U && return UpperTriangular(Symbol(C.uplo) == d ? C.factors : adjoint(C.factors)) + d == :L && return LowerTriangular(Symbol(C.uplo) == d ? C.factors : adjoint(C.factors)) d == :p && return C.piv if d == :P n = size(C, 1) diff --git a/base/linalg/conjarray.jl b/base/linalg/conjarray.jl index c43bc0436b0b1..2f743cdf403b8 100644 --- a/base/linalg/conjarray.jl +++ b/base/linalg/conjarray.jl @@ -10,10 +10,6 @@ other arrays, the `ConjArray` constructor can be used directly. # Examples ```jldoctest -julia> [1+im, 1-im]' -1×2 RowVector{Complex{Int64},ConjArray{Complex{Int64},1,Array{Complex{Int64},1}}}: - 1-1im 1+1im - julia> ConjArray([1+im 0; 0 1-im]) 2×2 ConjArray{Complex{Int64},2,Array{Complex{Int64},2}}: 1-1im 0+0im diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 89615a7771bab..8b75edbef4686 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -1350,7 +1350,7 @@ function nullspace(A::StridedMatrix{T}) where T (m == 0 || n == 0) && return Matrix{T}(I, n, n) SVD = svdfact(A, full = true) indstart = sum(SVD.S .> max(m,n)*maximum(SVD.S)*eps(eltype(SVD.S))) + 1 - return SVD.Vt[indstart:end,:]' + return adjoint(SVD.Vt[indstart:end,:]) end nullspace(a::StridedVector) = nullspace(reshape(a, length(a), 1)) diff --git a/base/linalg/diagonal.jl b/base/linalg/diagonal.jl index a90d8dfdeab13..a1190103df936 100644 --- a/base/linalg/diagonal.jl +++ b/base/linalg/diagonal.jl @@ -471,7 +471,7 @@ function svd(D::Diagonal{<:Number}) end function svdfact(D::Diagonal) U, s, V = svd(D) - SVD(U, s, V') + SVD(U, s, adjoint(V)) end # dismabiguation methods: * of Diagonal and Adj/Trans AbsVec diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index d0991145d0dfa..744dc0885a5cc 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -882,7 +882,7 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat) end (\)(a::AbstractVector, b::AbstractArray) = pinv(a) * b -(/)(A::AbstractVecOrMat, B::AbstractVecOrMat) = (B' \ A')' +(/)(A::AbstractVecOrMat, B::AbstractVecOrMat) = adjoint(Adjoint(B) \ Adjoint(A)) # \(A::StridedMatrix,x::Number) = inv(A)*x Should be added at some point when the old elementwise version has been deprecated long enough # /(x::Number,A::StridedMatrix) = x*inv(A) /(x::Number, v::AbstractVector) = x*pinv(v) @@ -1290,7 +1290,7 @@ end vAj += x[i]'*A[i, j] end - vAj = τ'*vAj + vAj = conj(τ)*vAj # ger A[1, j] -= vAj diff --git a/base/linalg/lq.jl b/base/linalg/lq.jl index 1738e1c3a13ee..a096b7f6ed3d8 100644 --- a/base/linalg/lq.jl +++ b/base/linalg/lq.jl @@ -70,7 +70,7 @@ convert(::Type{AbstractArray}, A::LQ) = convert(AbstractMatrix, A) convert(::Type{Matrix}, A::LQ) = convert(Array, convert(AbstractArray, A)) convert(::Type{Array}, A::LQ) = convert(Matrix, A) -adjoint(A::LQ{T}) where {T} = QR{T,typeof(A.factors)}(A.factors', A.τ) +adjoint(A::LQ{T}) where {T} = QR{T,typeof(A.factors)}(adjoint(A.factors), A.τ) function getindex(A::LQ, d::Symbol) m, n = size(A) diff --git a/base/linalg/qr.jl b/base/linalg/qr.jl index b7292a4c80816..6b4392af26f54 100644 --- a/base/linalg/qr.jl +++ b/base/linalg/qr.jl @@ -796,7 +796,7 @@ function ldiv!(A::QR{T}, B::StridedMatrix{T}) where T for k = m:-1:1 # Trapezoid to triangular by elementary operation x = view(R, k, [k; m + 1:n]) τk = reflector!(x) - τ[k] = τk' + τ[k] = adjoint(τk) for i = 1:k - 1 vRi = R[i,k] for j = m + 1:n diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index 65e544a008535..0ad9ca8a69a35 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -199,8 +199,8 @@ IndexStyle(::Type{<:RowVector}) = IndexLinear() # inner product -> dot product specializations @inline *(rowvec::RowVector{T}, vec::AbstractVector{T}) where {T<:Real} = dot(parent(rowvec), vec) -@inline *(rowvec::ConjRowVector{T}, vec::AbstractVector{T}) where {T<:Real} = dot(rowvec', vec) -@inline *(rowvec::ConjRowVector, vec::AbstractVector) = dot(rowvec', vec) +@inline *(rowvec::ConjRowVector{T}, vec::AbstractVector{T}) where {T<:Real} = dot(rvadjoint(rowvec), vec) +@inline *(rowvec::ConjRowVector, vec::AbstractVector) = dot(rvadjoint(rowvec), vec) # Generic behavior @inline function *(rowvec::RowVector, vec::AbstractVector) @@ -261,7 +261,7 @@ end *(adjvec::Adjoint{<:Any,<:AbstractVector}, adjrowvec::Adjoint{<:Any,<:RowVector}) = adjoint(adjvec.parent)*rvadjoint(adjrowvec.parent) *(adjmat::Adjoint{<:Any,<:AbstractMatrix}, adjrowvec::Adjoint{<:Any,<:RowVector}) = - (adjmat.parent)' * rvadjoint(adjrowvec.parent) + adjoint(adjmat.parent) * rvadjoint(adjrowvec.parent) *(::Adjoint{<:Any,<:RowVector}, ::AbstractVector) = throw(DimensionMismatch("Cannot multiply two vectors")) *(adjrowvec1::Adjoint{<:Any,<:RowVector}, rowvec2::RowVector) = rvadjoint(adjrowvec1.parent) * rowvec2 diff --git a/base/linalg/svd.jl b/base/linalg/svd.jl index e33dfb9167042..d6993ab192759 100644 --- a/base/linalg/svd.jl +++ b/base/linalg/svd.jl @@ -165,7 +165,7 @@ function svd(A::AbstractArray; full::Bool = false, thin::Union{Bool,Void} = noth full::Bool = !thin end F = svdfact(A, full = full) - F.U, F.S, F.Vt' + F.U, F.S, adjoint(F.Vt) end function svd(x::Number; full::Bool = false, thin::Union{Bool,Void} = nothing) # DEPRECATION TODO: remove deprecated thin argument and associated logic after 0.7 @@ -186,7 +186,7 @@ function getindex(F::SVD, d::Symbol) elseif d == :Vt return F.Vt elseif d == :V - return F.Vt' + return adjoint(F.Vt) else throw(KeyError(d)) end diff --git a/base/linalg/symmetric.jl b/base/linalg/symmetric.jl index 03f22a396f258..047a7b62a4a2b 100644 --- a/base/linalg/symmetric.jl +++ b/base/linalg/symmetric.jl @@ -73,7 +73,7 @@ julia> Hlower = Hermitian(A, :L) 2+2im 0+0im 3-3im 0+0im 4+0im ``` -Note that `Hupper` will not be equal to `Hlower` unless `A` is itself Hermitian (e.g. if `A == A'`). +Note that `Hupper` will not be equal to `Hlower` unless `A` is itself Hermitian (e.g. if `A == adjoint(A)`). All non-real parts of the diagonal will be ignored. @@ -249,13 +249,13 @@ Base.conj!(A::HermOrSym) = typeof(A)(conj!(A.data), A.uplo) # tril/triu function tril(A::Hermitian, k::Integer=0) if A.uplo == 'U' && k <= 0 - return tril!(A.data',k) + return tril!(adjoint(A.data),k) elseif A.uplo == 'U' && k > 0 - return tril!(A.data',-1) + tril!(triu(A.data),k) + return tril!(adjoint(A.data),-1) + tril!(triu(A.data),k) elseif A.uplo == 'L' && k <= 0 return tril(A.data,k) else - return tril(A.data,-1) + tril!(triu!(A.data'),k) + return tril(A.data,-1) + tril!(triu!(adjoint(A.data)),k) end end @@ -275,11 +275,11 @@ function triu(A::Hermitian, k::Integer=0) if A.uplo == 'U' && k >= 0 return triu(A.data,k) elseif A.uplo == 'U' && k < 0 - return triu(A.data,1) + triu!(tril!(A.data'),k) + return triu(A.data,1) + triu!(tril!(adjoint(A.data)),k) elseif A.uplo == 'L' && k >= 0 - return triu!(A.data',k) + return triu!(adjoint(A.data),k) else - return triu!(A.data',1) + triu!(tril(A.data),k) + return triu!(adjoint(A.data),1) + triu!(tril(A.data),k) end end @@ -536,18 +536,18 @@ eigmax(A::RealHermSymComplexHerm{<:Real,<:StridedMatrix}) = eigvals(A, size(A, 1 eigmin(A::RealHermSymComplexHerm{<:Real,<:StridedMatrix}) = eigvals(A, 1:1)[1] function eigfact!(A::HermOrSym{T,S}, B::HermOrSym{T,S}) where {T<:BlasReal,S<:StridedMatrix} - vals, vecs, _ = LAPACK.sygvd!(1, 'V', A.uplo, A.data, B.uplo == A.uplo ? B.data : B.data') + vals, vecs, _ = LAPACK.sygvd!(1, 'V', A.uplo, A.data, B.uplo == A.uplo ? B.data : adjoint(B.data)) GeneralizedEigen(vals, vecs) end function eigfact!(A::Hermitian{T,S}, B::Hermitian{T,S}) where {T<:BlasComplex,S<:StridedMatrix} - vals, vecs, _ = LAPACK.sygvd!(1, 'V', A.uplo, A.data, B.uplo == A.uplo ? B.data : B.data') + vals, vecs, _ = LAPACK.sygvd!(1, 'V', A.uplo, A.data, B.uplo == A.uplo ? B.data : adjoint(B.data)) GeneralizedEigen(vals, vecs) end eigvals!(A::HermOrSym{T,S}, B::HermOrSym{T,S}) where {T<:BlasReal,S<:StridedMatrix} = - LAPACK.sygvd!(1, 'N', A.uplo, A.data, B.uplo == A.uplo ? B.data : B.data')[1] + LAPACK.sygvd!(1, 'N', A.uplo, A.data, B.uplo == A.uplo ? B.data : adjoint(B.data))[1] eigvals!(A::Hermitian{T,S}, B::Hermitian{T,S}) where {T<:BlasComplex,S<:StridedMatrix} = - LAPACK.sygvd!(1, 'N', A.uplo, A.data, B.uplo == A.uplo ? B.data : B.data')[1] + LAPACK.sygvd!(1, 'N', A.uplo, A.data, B.uplo == A.uplo ? B.data : adjoint(B.data))[1] eigvecs(A::HermOrSym) = eigvecs(eigfact(A)) diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index e1f2a132022b6..f2d0c5a40e373 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -590,13 +590,13 @@ function eigvecs(A::UnitUpperTriangular{<:BlasFloat,<:StridedMatrix}) LAPACK.trevc!('R', 'A', BlasInt[], triu!(A.data)) end function eigvecs(A::LowerTriangular{<:BlasFloat,<:StridedMatrix}) - LAPACK.trevc!('L', 'A', BlasInt[], tril!(A.data)') + LAPACK.trevc!('L', 'A', BlasInt[], adjoint(tril!(A.data))) end function eigvecs(A::UnitLowerTriangular{<:BlasFloat,<:StridedMatrix}) for i = 1:size(A, 1) A.data[i,i] = 1 end - LAPACK.trevc!('L', 'A', BlasInt[], tril!(A.data)') + LAPACK.trevc!('L', 'A', BlasInt[], adjoint(tril!(A.data))) end #################### diff --git a/base/operators.jl b/base/operators.jl index f71175b455de8..0d0f70e410eee 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -500,7 +500,7 @@ julia> inv(A) * x 4.5 ``` """ -\(x,y) = (y'/x')' +\(x,y) = adjoint(Adjoint(y)/Adjoint(x)) # Core <<, >>, and >>> take either Int or UInt as second arg. Signed shift # counts can shift in either direction, and are translated here to unsigned diff --git a/base/pkg/resolve/maxsum.jl b/base/pkg/resolve/maxsum.jl index 58efa9b970c87..cc22a8abe3555 100644 --- a/base/pkg/resolve/maxsum.jl +++ b/base/pkg/resolve/maxsum.jl @@ -122,7 +122,7 @@ mutable struct Graph adjdict[p0][p1] = j1 bm = trues(spp[p1], spp[p0]) - bmt = bm' + bmt = adjoint(bm) push!(gmsk[p0], bm) push!(gmsk[p1], bmt) diff --git a/base/rational.jl b/base/rational.jl index 9b74e57535b61..43a4332b512fb 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -54,7 +54,7 @@ function //(x::Rational, y::Rational) end //(x::Complex, y::Real) = complex(real(x)//y,imag(x)//y) -//(x::Number, y::Complex) = x*y'//abs2(y) +//(x::Number, y::Complex) = x*conj(y)//abs2(y) //(X::AbstractArray, y::Number) = X .// y diff --git a/base/sparse/linalg.jl b/base/sparse/linalg.jl index ccc44fe784268..f68b58fc1419b 100644 --- a/base/sparse/linalg.jl +++ b/base/sparse/linalg.jl @@ -580,7 +580,7 @@ function cond(A::SparseMatrixCSC, p::Real=2) normA = norm(A, 1) return normA * normAinv elseif p == Inf - normAinv = normestinv(A') + normAinv = normestinv(adjoint(A)) normA = norm(A, Inf) return normA * normAinv elseif p == 2 diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index a96bdbe44d46e..b02f62724ca11 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -1553,7 +1553,7 @@ function LinAlg.lowrankupdate!(A::StridedMatrix, x::StridedVector, y::SparseVect nzi = nonzeroinds(y) nzv = nonzeros(y) @inbounds for (j,v) in zip(nzi,nzv) - αv = α*v' + αv = α*conj(v) for i in axes(x, 1) A[i,j] += x[i]*αv end diff --git a/base/statistics.jl b/base/statistics.jl index b7c1cf49c5bd2..a866a5ed28315 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -418,7 +418,7 @@ function cov2cor!(C::AbstractMatrix{T}, xsd::AbstractArray) where T size(C) == (nx, nx) || throw(DimensionMismatch("inconsistent dimensions")) for j = 1:nx for i = 1:j-1 - C[i,j] = C[j,i]' + C[i,j] = adjoint(C[j,i]) end C[j,j] = oneunit(T) for i = j+1:nx From 9ec817f8d69bf4521d52049682e9e24baff4fb0c Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 16 Dec 2017 14:16:26 -0800 Subject: [PATCH 2/5] Rewrite isolated ' calls in stdlib/ to preserve behavior through ' lowering changes. --- .../src/IterativeEigensolvers.jl | 2 +- stdlib/IterativeEigensolvers/test/runtests.jl | 6 ++--- stdlib/SharedArrays/test/runtests.jl | 2 +- stdlib/SuiteSparse/test/cholmod.jl | 22 +++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl b/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl index 50910bb3b50ff..047dc564b149a 100644 --- a/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl +++ b/stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl @@ -321,7 +321,7 @@ function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxite end # right_sv = sqrt(2) * ex[2][ size(X,1)+1:end, ind ] - return (SVD(U, svals, V'), ex[3], ex[4], ex[5], ex[6]) + return (SVD(U, svals, adjoint(V)), ex[3], ex[4], ex[5], ex[6]) else #The sort is necessary to work around #10329 return (SVD(zeros(eltype(svals), n, 0), diff --git a/stdlib/IterativeEigensolvers/test/runtests.jl b/stdlib/IterativeEigensolvers/test/runtests.jl index e7486d4876a13..c18ec5c73d6fa 100644 --- a/stdlib/IterativeEigensolvers/test/runtests.jl +++ b/stdlib/IterativeEigensolvers/test/runtests.jl @@ -23,11 +23,11 @@ using Test end a_evs = eigvals(Array(a)) a = convert(SparseMatrixCSC{elty}, a) - asym = a' + a # symmetric indefinite + asym = adjoint(a) + a # symmetric indefinite apd = a'*a # symmetric positive-definite b = convert(SparseMatrixCSC{elty}, b) - bsym = b' + b + bsym = adjoint(b) + b bpd = b'*b (d,v) = eigs(a, nev=3) @@ -167,7 +167,7 @@ let v = real(v) # @test vecnorm(v-v')/2 ≈ 0. # it should be Hermitian # Since this fails sometimes (numerical precision error),this test is commented out - v = (v+v')/2 + v = (v+adjoint(v))/2 @test isposdef(v) # Repeat with starting vector diff --git a/stdlib/SharedArrays/test/runtests.jl b/stdlib/SharedArrays/test/runtests.jl index bbac018635746..f2ec02a6c65d0 100644 --- a/stdlib/SharedArrays/test/runtests.jl +++ b/stdlib/SharedArrays/test/runtests.jl @@ -212,7 +212,7 @@ d[5,1:2:4,8] = 19 AA = rand(4,2) A = @inferred(convert(SharedArray, AA)) -B = @inferred(convert(SharedArray, AA')) +B = @inferred(convert(SharedArray, adjoint(AA))) @test B*A == adjoint(AA)*AA d=SharedArray{Int64,2}((10,10); init = D->fill!(D.loc_subarr_1d, myid()), pids=[id_me, id_other]) diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index 7da1870f46fc0..9ebaf1c2c8963 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -182,7 +182,7 @@ end @test sparse(cmA'*cmA) ≈ A'*A # A_mul_Ac for symmetric A - A = 0.5*(A + A') + A = 0.5*(A + adjoint(A)) cmA = CHOLMOD.Sparse(A) @test sparse(cmA*cmA') ≈ A*A' end @@ -373,14 +373,14 @@ end @test_throws ArgumentError cholfact(A1, shift=1.0) @test_throws ArgumentError ldltfact(A1) @test_throws ArgumentError ldltfact(A1, shift=1.0) - @test_throws LinAlg.PosDefException cholfact(A1 + A1' - 2eigmax(Array(A1 + A1'))*I)\ones(size(A1, 1)) - @test_throws LinAlg.PosDefException cholfact(A1 + A1', shift=-2eigmax(Array(A1 + A1')))\ones(size(A1, 1)) - @test_throws ArgumentError ldltfact(A1 + A1' - 2real(A1[1,1])*I)\ones(size(A1, 1)) - @test_throws ArgumentError ldltfact(A1 + A1', shift=-2real(A1[1,1]))\ones(size(A1, 1)) - @test !isposdef(cholfact(A1 + A1' - 2eigmax(Array(A1 + A1'))*I)) - @test !isposdef(cholfact(A1 + A1', shift=-2eigmax(Array(A1 + A1')))) - @test !LinAlg.issuccess(ldltfact(A1 + A1' - 2real(A1[1,1])*I)) - @test !LinAlg.issuccess(ldltfact(A1 + A1', shift=-2real(A1[1,1]))) + @test_throws LinAlg.PosDefException cholfact(A1 + adjoint(A1) - 2eigmax(Array(A1 + adjoint(A1)))*I)\ones(size(A1, 1)) + @test_throws LinAlg.PosDefException cholfact(A1 + adjoint(A1), shift=-2eigmax(Array(A1 + adjoint(A1))))\ones(size(A1, 1)) + @test_throws ArgumentError ldltfact(A1 + adjoint(A1) - 2real(A1[1,1])*I)\ones(size(A1, 1)) + @test_throws ArgumentError ldltfact(A1 + adjoint(A1), shift=-2real(A1[1,1]))\ones(size(A1, 1)) + @test !isposdef(cholfact(A1 + adjoint(A1) - 2eigmax(Array(A1 + adjoint(A1)))*I)) + @test !isposdef(cholfact(A1 + adjoint(A1), shift=-2eigmax(Array(A1 + adjoint(A1))))) + @test !LinAlg.issuccess(ldltfact(A1 + adjoint(A1) - 2real(A1[1,1])*I)) + @test !LinAlg.issuccess(ldltfact(A1 + adjoint(A1), shift=-2real(A1[1,1]))) F = cholfact(A1pd) tmp = IOBuffer() show(tmp, F) @@ -402,7 +402,7 @@ end @test logdet(ldltfact(A1pd)) ≈ logdet(Array(A1pd)) @test isposdef(A1pd) @test !isposdef(A1) - @test !isposdef(A1 + A1' |> t -> t - 2eigmax(Array(t))*I) + @test !isposdef(A1 + adjoint(A1) |> t -> t - 2eigmax(Array(t))*I) if elty <: Real @test CHOLMOD.issymmetric(Sparse(A1pd, 0)) @@ -685,7 +685,7 @@ end @testset "Make sure that ldltfact performs an LDLt (Issue #19032)" begin m, n = 400, 500 A = sprandn(m, n, .2) - M = [I A'; A -I] + M = [I adjoint(A); A -I] b = M * ones(m + n) F = ldltfact(M) s = unsafe_load(pointer(F)) From 90cf0ba533b7c39216db65066dfb43a5289b1c6d Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 16 Dec 2017 17:56:37 -0800 Subject: [PATCH 3/5] Rewrite isolated ' calls in test/ to preserve behavior through ' lowering changes. --- test/arrayops.jl | 6 +++--- test/examples.jl | 4 ++-- test/linalg/blas.jl | 4 ++-- test/linalg/cholesky.jl | 2 +- test/linalg/conjarray.jl | 2 +- test/linalg/dense.jl | 14 +++++++------- test/linalg/diagonal.jl | 2 +- test/linalg/eigen.jl | 6 +++--- test/linalg/lapack.jl | 8 ++++---- test/linalg/lq.jl | 4 ++-- test/linalg/lu.jl | 2 +- test/linalg/matmul.jl | 2 +- test/linalg/qr.jl | 10 +++++----- test/linalg/schur.jl | 2 +- test/linalg/svd.jl | 6 +++--- test/linalg/symmetric.jl | 12 ++++++------ test/linalg/triangular.jl | 8 ++++---- test/mod2pi.jl | 4 ++-- test/offsetarray.jl | 4 ++-- test/perf/lapack/eig.jl | 4 ++-- test/show.jl | 2 +- test/sparse/higherorderfns.jl | 4 ++-- test/sparse/sparse.jl | 22 +++++++++++----------- test/statistics.jl | 12 ++++++------ 24 files changed, 73 insertions(+), 73 deletions(-) diff --git a/test/arrayops.jl b/test/arrayops.jl index 6db4148f13694..6a90094e6894f 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -48,7 +48,7 @@ using Main.TestHelpers.OAs a[1,2] = 2 a[2,1] = 3 a[2,2] = 4 - b = a' + b = adjoint(a) @test a[1,1] == 1. && a[1,2] == 2. && a[2,1] == 3. && a[2,2] == 4. @test b[1,1] == 1. && b[2,1] == 2. && b[1,2] == 3. && b[2,2] == 4. a[[1 2 3 4]] = 0 @@ -624,7 +624,7 @@ end @testset "large matrices transpose" begin for i = 1 : 3 a = rand(200, 300) - @test isequal(a', permutedims(a, [2, 1])) + @test isequal(adjoint(a), permutedims(a, [2, 1])) end end @@ -2050,7 +2050,7 @@ end # module AutoRetType @test isa([[1,2,3]'; [1,2,3]'], Matrix{Int}) @test isa([[1,2,3]' [1,2,3]'], Transpose{Int, Vector{Int}}) @test isa([Any[1.0, 2]'; Any[2.0, 2]'], Matrix{Any}) - @test isa([Any[1.0, 2]' Any[2.0, 2']'], Adjoint{Any, Vector{Any}}) + @test isa([Any[1.0, 2]' Any[2.0, 2]'], Adjoint{Any, Vector{Any}}) # Test that concatenations of heterogeneous Matrix-Vector pairs yield dense matrices @test isa(hcat(densemat, densevec), Array) @test isa(hcat(densevec, densemat), Array) diff --git a/test/examples.jl b/test/examples.jl index 378e9038deda2..a3002e3240171 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -24,9 +24,9 @@ include(joinpath(dir, "ndgrid.jl")) r = repmat(1:10,1,10) r1, r2 = ndgrid(1:10, 1:10) @test r1 == r -@test r2 == r' +@test r2 == adjoint(r) r3, r4 = meshgrid(1:10,1:10) -@test r3 == r' +@test r3 == adjoint(r) @test r4 == r include(joinpath(dir, "queens.jl")) diff --git a/test/linalg/blas.jl b/test/linalg/blas.jl index 51ef32e0d7a0b..1c877e6464bcc 100644 --- a/test/linalg/blas.jl +++ b/test/linalg/blas.jl @@ -141,7 +141,7 @@ srand(100) if elty <: Complex A = rand(elty,n,n) - A = A + A' + A = A + adjoint(A) α = real(α) @test triu(BLAS.her!('U',α,x,copy(A))) ≈ triu(A + α*x*x') @test_throws DimensionMismatch BLAS.her!('U',α,ones(elty,n+1),copy(A)) @@ -278,7 +278,7 @@ srand(100) @test_throws DimensionMismatch BLAS.gemm!('N','N', one(elty), I43, I4, elm1, I4) @test_throws DimensionMismatch BLAS.gemm!('T','N', one(elty), I43, I4, elm1, I43) @test_throws DimensionMismatch BLAS.gemm!('N','T', one(elty), I43, I43, elm1, I43) - @test_throws DimensionMismatch BLAS.gemm!('T','T', one(elty), I43, I43, elm1, I43') + @test_throws DimensionMismatch BLAS.gemm!('T','T', one(elty), I43, I43, elm1, adjoint(I43)) end @testset "gemm compared to (sy)(he)rk" begin if eltype(elm1) <: Complex diff --git a/test/linalg/cholesky.jl b/test/linalg/cholesky.jl index 09d56e19f8037..2333d0defc64a 100644 --- a/test/linalg/cholesky.jl +++ b/test/linalg/cholesky.jl @@ -219,7 +219,7 @@ end for uplo in (:U, :L) AcA = A'A BcB = AcA + v*v' - BcB = (BcB + BcB')/2 + BcB = (BcB + adjoint(BcB))/2 F = cholfact(Hermitian(AcA, uplo)) G = cholfact(Hermitian(BcB, uplo)) @test LinAlg.lowrankupdate(F, v)[uplo] ≈ G[uplo] diff --git a/test/linalg/conjarray.jl b/test/linalg/conjarray.jl index 29839ff81bb5b..99663f9a12684 100644 --- a/test/linalg/conjarray.jl +++ b/test/linalg/conjarray.jl @@ -6,7 +6,7 @@ @test cm[1,1] == 1-im @test cm[1] == 1-im @test trace(cm*m) == 27 - @test cm' == m + @test adjoint(cm) == m cm[:,2] = [3; 3-im] #setindex! with a vector @test conj(cm) == [1+im 3; 2 3+im] diff --git a/test/linalg/dense.jl b/test/linalg/dense.jl index e7c7d6d31e01d..a37b2f85489dc 100644 --- a/test/linalg/dense.jl +++ b/test/linalg/dense.jl @@ -66,7 +66,7 @@ bimg = randn(n,2)/2 end @testset "Test nullspace" begin - a15null = nullspace(a[:,1:n1]') + a15null = nullspace(adjoint(a[:,1:n1])) @test rank([a[:,1:n1] a15null]) == 10 @test norm(a[:,1:n1]'a15null,Inf) ≈ zero(eltya) atol=300ε @test norm(a15null'a[:,1:n1],Inf) ≈ zero(eltya) atol=400ε @@ -95,7 +95,7 @@ bimg = randn(n,2)/2 @testset "Matrix square root" begin asq = sqrt(a) @test asq*asq ≈ a - asym = a'+a # symmetric indefinite + asym = adjoint(a)+a # symmetric indefinite asymsq = sqrt(asym) @test asymsq*asymsq ≈ asym end @@ -349,9 +349,9 @@ end @testset "Matrix exponential" begin @testset "Tests for $elty" for elty in (Float32, Float64, ComplexF32, ComplexF64) A1 = convert(Matrix{elty}, [4 2 0; 1 4 1; 1 1 4]) - eA1 = convert(Matrix{elty}, [147.866622446369 127.781085523181 127.781085523182; + eA1 = convert(Matrix{elty}, adjoint([147.866622446369 127.781085523181 127.781085523182; 183.765138646367 183.765138646366 163.679601723179; - 71.797032399996 91.8825693231832 111.968106246371]') + 71.797032399996 91.8825693231832 111.968106246371])) @test exp(A1) ≈ eA1 A2 = convert(Matrix{elty}, @@ -365,9 +365,9 @@ end @test exp(A2) ≈ eA2 A3 = convert(Matrix{elty}, [-131 19 18;-390 56 54;-387 57 52]) - eA3 = convert(Matrix{elty}, [-1.50964415879218 -5.6325707998812 -4.934938326092; + eA3 = convert(Matrix{elty}, adjoint([-1.50964415879218 -5.6325707998812 -4.934938326092; 0.367879439109187 1.47151775849686 1.10363831732856; - 0.135335281175235 0.406005843524598 0.541341126763207]') + 0.135335281175235 0.406005843524598 0.541341126763207])) @test exp(A3) ≈ eA3 A4 = convert(Matrix{elty}, [0.25 0.25; 0 0]) @@ -790,7 +790,7 @@ end @testset "/ and \\ consistency with pinv for vectors" begin @testset "Tests for type $elty" for elty in (Float32, Float64, ComplexF32, ComplexF64) c = rand(elty, 5) - r = rand(elty, 5)' + r = (elty <: Complex ? Adjoint : Transpose)(rand(elty, 5)) cm = rand(elty, 5, 1) rm = rand(elty, 1, 5) @testset "inner prodcuts" begin diff --git a/test/linalg/diagonal.jl b/test/linalg/diagonal.jl index f6053dae67206..2029ba69e201d 100644 --- a/test/linalg/diagonal.jl +++ b/test/linalg/diagonal.jl @@ -182,7 +182,7 @@ srand(1) r = VV * Transpose(Array(D)) @test Array(mul!(VV, Transpose(DD))) ≈ r DD = copy(D) - r = VV * (Array(D)') + r = VV * Array(D)' @test Array(mul!(VV, Adjoint(DD))) ≈ r end @testset "triu/tril" begin diff --git a/test/linalg/eigen.jl b/test/linalg/eigen.jl index a5c224f9f1489..eddca4d4f43a7 100644 --- a/test/linalg/eigen.jl +++ b/test/linalg/eigen.jl @@ -17,7 +17,7 @@ aimg = randn(n,n)/2 @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64, Int) aa = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) - asym = aa'+aa # symmetric indefinite + asym = adjoint(aa)+aa # symmetric indefinite apd = aa'*aa # symmetric positive-definite for (a, asym, apd) in ((aa, asym, apd), (view(aa, 1:n, 1:n), @@ -49,8 +49,8 @@ aimg = randn(n,n)/2 h = asym @test minimum(eigvals(h)) ≈ eigmin(h) @test maximum(eigvals(h)) ≈ eigmax(h) - @test_throws DomainError eigmin(a - a') - @test_throws DomainError eigmax(a - a') + @test_throws DomainError eigmin(a - adjoint(a)) + @test_throws DomainError eigmax(a - adjoint(a)) end @testset "symmetric generalized eigenproblem" begin if isa(a, Array) diff --git a/test/linalg/lapack.jl b/test/linalg/lapack.jl index 9c9117dc4c3b6..255e5a2ac97fa 100644 --- a/test/linalg/lapack.jl +++ b/test/linalg/lapack.jl @@ -167,7 +167,7 @@ end lU,lS,lVt = LAPACK.gesvd!('S','S',A) @test U ≈ lU @test S ≈ lS - @test V' ≈ lVt + @test adjoint(V) ≈ lVt B = rand(elty,10,10) # xggsvd3 replaced xggsvd in LAPACK 3.6.0 if LAPACK.version() < v"3.6.0" @@ -391,7 +391,7 @@ end @testset "hetrf, hetrs" begin @testset for elty in (ComplexF32, ComplexF64) A = rand(elty,10,10) - A = A + A' #hermitian! + A = A + adjoint(A) #hermitian! B = copy(A) B,ipiv = LAPACK.hetrf!('U',B) @test_throws DimensionMismatch LAPACK.hetrs!('U',B,ipiv,rand(elty,11,5)) @@ -449,14 +449,14 @@ end @testset for elty in (ComplexF32, ComplexF64) srand(935) A = rand(elty,10,10) - A = A + A' #hermitian! + A = A + adjoint(A) #hermitian! b = rand(elty,10) c = A \ b b,A = LAPACK.hesv!('U',A,b) @test b ≈ c @test_throws DimensionMismatch LAPACK.hesv!('U',A,rand(elty,11)) A = rand(elty,10,10) - A = A + A' #hermitian! + A = A + adjoint(A) #hermitian! b = rand(elty,10) c = A \ b b,A = LAPACK.hesv_rook!('U',A,b) diff --git a/test/linalg/lq.jl b/test/linalg/lq.jl index adf7bb36323a3..15ab15101748b 100644 --- a/test/linalg/lq.jl +++ b/test/linalg/lq.jl @@ -27,7 +27,7 @@ rectangularQ(Q::LinAlg.LQPackedQ) = convert(Array, Q) @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64) a = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) a2 = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(a2real, a2img) : a2real) - asym = a'+a # symmetric indefinite + asym = adjoint(a)+a # symmetric indefinite apd = a'*a # symmetric positive-definite ε = εa = eps(abs(float(one(eltya)))) @@ -54,7 +54,7 @@ rectangularQ(Q::LinAlg.LQPackedQ) = convert(Array, Q) @test size(lqa[:Q],3) == 1 @test Base.LinAlg.getq(lqa) == lqa[:Q] @test_throws KeyError lqa[:Z] - @test Array(lqa') ≈ a' + @test Array(adjoint(lqa)) ≈ adjoint(a) @test lqa * lqa' ≈ a * a' @test lqa' * lqa ≈ a' * a @test q*squareQ(q)' ≈ Matrix(I, n, n) diff --git a/test/linalg/lu.jl b/test/linalg/lu.jl index 83368fc8c1dea..706aad0745654 100644 --- a/test/linalg/lu.jl +++ b/test/linalg/lu.jl @@ -106,7 +106,7 @@ dimg = randn(n)/2 for (bb, cc) in ((Bs, Cs), (view(Bs, 1:n, 1), view(Cs, 1:n))) @test norm(a*(lua\bb) - bb, 1) < ε*κ*n*2 # Two because the right hand side has two columns @test norm(a'*(lua'\bb) - bb, 1) < ε*κ*n*2 # Two because the right hand side has two columns - @test norm(a'*(lua'\a') - a', 1) < ε*κ*n^2 + @test norm(a'*(lua'\a') - adjoint(a), 1) < ε*κ*n^2 @test norm(a*(lua\cc) - cc, 1) < ε*κ*n # cc is a vector @test norm(a'*(lua'\cc) - cc, 1) < ε*κ*n # cc is a vector @test AbstractArray(lua) ≈ a diff --git a/test/linalg/matmul.jl b/test/linalg/matmul.jl index 0a4c87ff2a985..9afe483dabc14 100644 --- a/test/linalg/matmul.jl +++ b/test/linalg/matmul.jl @@ -179,7 +179,7 @@ end res = Float64[135228751 9979252 -115270247; 9979252 10481254 10983256; -115270247 10983256 137236759] for A in (copy(AA), view(AA, 1:501, 1:3)) @test *(Transpose(A), A) == res - @test *(A', Transpose(A')) == res + @test *(Adjoint(A), Transpose(adjoint(A))) == res end cutoff = 501 A = reshape(1:6*cutoff,2*cutoff,3).-(6*cutoff)/2 diff --git a/test/linalg/qr.jl b/test/linalg/qr.jl index 65fba4cf3dcad..1ad6a0d566fde 100644 --- a/test/linalg/qr.jl +++ b/test/linalg/qr.jl @@ -26,7 +26,7 @@ rectangularQ(Q::LinAlg.AbstractQ) = convert(Array, Q) @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64, BigFloat, Int) raw_a = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) raw_a2 = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(a2real, a2img) : a2real) - asym = raw_a' + raw_a # symmetric indefinite + asym = adjoint(raw_a) + raw_a # symmetric indefinite apd = raw_a' * raw_a # symmetric positive-definite ε = εa = eps(abs(float(one(eltya)))) @@ -53,9 +53,9 @@ rectangularQ(Q::LinAlg.AbstractQ) = convert(Array, Q) @test_throws KeyError qra[:Z] @test q'*squareQ(q) ≈ Matrix(I, a_1, a_1) @test q*squareQ(q)' ≈ Matrix(I, a_1, a_1) - @test q'*Matrix(1.0I, a_1, a_1)' ≈ squareQ(q)' + @test q'*Matrix(1.0I, a_1, a_1)' ≈ adjoint(squareQ(q)) @test squareQ(q)'q ≈ Matrix(I, a_1, a_1) - @test Matrix(1.0I, a_1, a_1)'q' ≈ squareQ(q)' + @test Matrix(1.0I, a_1, a_1)'q' ≈ adjoint(squareQ(q)) @test q*r ≈ a @test a*(qra\b) ≈ b atol=3000ε @test Array(qra) ≈ a @@ -135,7 +135,7 @@ rectangularQ(Q::LinAlg.AbstractQ) = convert(Array, Q) a = raw_a qrpa = factorize(a[:,1:n1]) q, r = qrpa[:Q], qrpa[:R] - @test mul!(squareQ(q)', q) ≈ Matrix(I, n, n) + @test mul!(adjoint(squareQ(q)), q) ≈ Matrix(I, n, n) @test_throws DimensionMismatch mul!(Matrix{eltya}(I, n+1, n+1),q) @test mul!(squareQ(q), Adjoint(q)) ≈ Matrix(I, n, n) @test_throws DimensionMismatch mul!(Matrix{eltya}(I, n+1, n+1), Adjoint(q)) @@ -145,7 +145,7 @@ rectangularQ(Q::LinAlg.AbstractQ) = convert(Array, Q) qra = qrfact(a[:,1:n1], Val(false)) q, r = qra[:Q], qra[:R] - @test mul!(squareQ(q)', q) ≈ Matrix(I, n, n) + @test mul!(adjoint(squareQ(q)), q) ≈ Matrix(I, n, n) @test_throws DimensionMismatch mul!(Matrix{eltya}(I, n+1, n+1),q) @test mul!(squareQ(q), Adjoint(q)) ≈ Matrix(I, n, n) @test_throws DimensionMismatch mul!(Matrix{eltya}(I, n+1, n+1),Adjoint(q)) diff --git a/test/linalg/schur.jl b/test/linalg/schur.jl index 2115124d4d087..2dc9e81ac6a48 100644 --- a/test/linalg/schur.jl +++ b/test/linalg/schur.jl @@ -17,7 +17,7 @@ aimg = randn(n,n)/2 @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64, Int) a = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) - asym = a'+a # symmetric indefinite + asym = adjoint(a)+a # symmetric indefinite apd = a'*a # symmetric positive-definite for (a, asym, apd) in ((a, asym, apd), (view(a, 1:n, 1:n), diff --git a/test/linalg/svd.jl b/test/linalg/svd.jl index 28e1b8d4159a3..1e1b9d904d692 100644 --- a/test/linalg/svd.jl +++ b/test/linalg/svd.jl @@ -46,7 +46,7 @@ a2img = randn(n,n)/2 @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64, Int) aa = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) aa2 = eltya == Int ? rand(1:7, n, n) : convert(Matrix{eltya}, eltya <: Complex ? complex.(a2real, a2img) : a2real) - asym = aa'+aa # symmetric indefinite + asym = adjoint(aa)+aa # symmetric indefinite apd = aa'*aa # symmetric positive-definite for (a, a2) in ((aa, aa2), (view(aa, 1:n, 1:n), view(aa2, 1:n, 1:n))) ε = εa = eps(abs(float(one(eltya)))) @@ -56,7 +56,7 @@ a2img = randn(n,n)/2 @test usv[:S] === svdvals(usv) @test usv[:U] * (Diagonal(usv[:S]) * usv[:Vt]) ≈ a @test convert(Array, usv) ≈ a - @test usv[:Vt]' ≈ usv[:V] + @test adjoint(usv[:Vt]) ≈ usv[:V] @test_throws KeyError usv[:Z] b = rand(eltya,n) @test usv\b ≈ a\b @@ -73,7 +73,7 @@ a2img = randn(n,n)/2 gsvd = svdfact(a,a_svd) @test gsvd[:U]*gsvd[:D1]*gsvd[:R]*gsvd[:Q]' ≈ a @test gsvd[:V]*gsvd[:D2]*gsvd[:R]*gsvd[:Q]' ≈ a_svd - @test usv[:Vt]' ≈ usv[:V] + @test adjoint(usv[:Vt]) ≈ usv[:V] @test_throws KeyError usv[:Z] @test_throws KeyError gsvd[:Z] @test gsvd[:vals] ≈ svdvals(a,a_svd) diff --git a/test/linalg/symmetric.jl b/test/linalg/symmetric.jl index ec2959a7af7ca..6664a0750926d 100644 --- a/test/linalg/symmetric.jl +++ b/test/linalg/symmetric.jl @@ -11,15 +11,15 @@ end @testset "Hermitian matrix exponential/log" begin A1 = randn(4,4) + im*randn(4,4) - A2 = A1 + A1' + A2 = A1 + adjoint(A1) @test exp(A2) ≈ exp(Hermitian(A2)) @test log(A2) ≈ log(Hermitian(A2)) - A3 = A1 * A1' # posdef + A3 = A1 * adjoint(A1) # posdef @test exp(A3) ≈ exp(Hermitian(A3)) @test log(A3) ≈ log(Hermitian(A3)) A1 = randn(4,4) - A3 = A1 * A1' + A3 = A1 * adjoint(A1) A4 = A1 + transpose(A1) @test exp(A4) ≈ exp(Symmetric(A4)) @test log(A3) ≈ log(Symmetric(A3)) @@ -121,7 +121,7 @@ end elseif eltya <: Complex # test that zero imaginary component is # handled properly - @test ishermitian(Symmetric(b + b')) + @test ishermitian(Symmetric(b + adjoint(b))) end end @@ -255,7 +255,7 @@ end let A = a[:,1:5]*a[:,1:5]' # Make sure A is Hermitian even in the presence of rounding error # xianyi/OpenBLAS#729 - A = (A' + A) / 2 + A = (adjoint(A) + A) / 2 @test rank(A) == rank(Hermitian(A)) end end @@ -383,7 +383,7 @@ end @test conj(c) == conj(Array(c)) cc = copy(c) @test conj!(c) == conj(Array(cc)) - c = Hermitian(b + b') + c = Hermitian(b + adjoint(b)) @test conj(c) == conj(Array(c)) cc = copy(c) @test conj!(c) == conj(Array(cc)) diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index 4b1c5ec8bdfab..adbf0c7e8bf74 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -136,14 +136,14 @@ for elty1 in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFlo @test transpose(A1) == transpose(Matrix(A1)) @test transpose(viewA1) == transpose(Matrix(viewA1)) # adjoint - @test A1' == Matrix(A1)' - @test viewA1' == Matrix(viewA1)' + @test adjoint(A1) == adjoint(Matrix(A1)) + @test adjoint(viewA1) == adjoint(Matrix(viewA1)) # transpose! @test transpose!(copy(A1)) == transpose(A1) @test transpose!(t1(view(copy(A1).data, vrange, vrange))) == transpose(viewA1) # adjoint! - @test adjoint!(copy(A1)) == A1' - @test adjoint!(t1(view(copy(A1).data, vrange, vrange))) == viewA1' + @test adjoint!(copy(A1)) == adjoint(A1) + @test adjoint!(t1(view(copy(A1).data, vrange, vrange))) == adjoint(viewA1) end # diag diff --git a/test/mod2pi.jl b/test/mod2pi.jl index e064eb02545a7..f0fe43b9ed776 100644 --- a/test/mod2pi.jl +++ b/test/mod2pi.jl @@ -222,7 +222,7 @@ testModPi() # ieee754_rem_pio2_return contains the returned value from the ieee754_rem_pio2 # function in openlibm: https://github.com/JuliaLang/openlibm/blob/0598080ca09468490a13ae393ba17d8620c1b201/src/e_rem_pio2.c - ieee754_rem_pio2_return = [1.5707963267948966 1.5707963267948966; + ieee754_rem_pio2_return = adjoint([1.5707963267948966 1.5707963267948966; 1.0471975511965979 -1.0471975511965979; 0.10000000000000014 -0.10000000000000014; 6.123233995736766e-17 -6.123233995736766e-17; @@ -238,7 +238,7 @@ testModPi() -0.6853981633974484 0.6853981633974484; 3.135095805817224e-14 -3.135095805817224e-14; 3.287386219680602e-8 -3.287386219680602e-8; - -0.1757159771004682 0.1757159771004682]' + -0.1757159771004682 0.1757159771004682]) for (i, case) in enumerate(cases) # negative argument diff --git a/test/offsetarray.jl b/test/offsetarray.jl index e669562ae87ea..9b5168c62a6af 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -327,8 +327,8 @@ cv = copy(v) A = OffsetArray(rand(4,4), (-3,5)) @test A ≈ A -@test axes(A') === (6:9, -2:1) -@test parent(A') == parent(A)' +@test axes(adjoint(A)) === (6:9, -2:1) +@test parent(adjoint(A)) == adjoint(parent(A)) @test collect(A) == parent(A) @test maximum(A) == maximum(parent(A)) @test minimum(A) == minimum(parent(A)) diff --git a/test/perf/lapack/eig.jl b/test/perf/lapack/eig.jl index 48036c481e19c..47d980bff88ea 100644 --- a/test/perf/lapack/eig.jl +++ b/test/perf/lapack/eig.jl @@ -14,7 +14,7 @@ end # Symmetric function symeigtest(n, iter) A = rand(n,n) - A = A + A' + A = A + adjoint(A) d = Vector{eltype(A)} v = similar(A) for i = 1:iter @@ -26,7 +26,7 @@ end # Hermitian function hermitianeigtest(n, iter) A = rand(n,n) + im*rand(n,n) - A = A + A' + A = A + adjoint(A) d = Vector{eltype(A)} v = similar(A) for i = 1:iter diff --git a/test/show.jl b/test/show.jl index 152c3549e0fe0..228e7e0c5bf05 100644 --- a/test/show.jl +++ b/test/show.jl @@ -608,7 +608,7 @@ let A = reshape(1:16, 4, 4) @test replstr(Diagonal(A)) == "4×4 Diagonal{$(Int),Array{$(Int),1}}:\n 1 ⋅ ⋅ ⋅\n ⋅ 6 ⋅ ⋅\n ⋅ ⋅ 11 ⋅\n ⋅ ⋅ ⋅ 16" @test replstr(Bidiagonal(A, :U)) == "4×4 Bidiagonal{$(Int),Array{$(Int),1}}:\n 1 5 ⋅ ⋅\n ⋅ 6 10 ⋅\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16" @test replstr(Bidiagonal(A, :L)) == "4×4 Bidiagonal{$(Int),Array{$(Int),1}}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n ⋅ 7 11 ⋅\n ⋅ ⋅ 12 16" - @test replstr(SymTridiagonal(A + A')) == "4×4 SymTridiagonal{$(Int),Array{$(Int),1}}:\n 2 7 ⋅ ⋅\n 7 12 17 ⋅\n ⋅ 17 22 27\n ⋅ ⋅ 27 32" + @test replstr(SymTridiagonal(A + adjoint(A))) == "4×4 SymTridiagonal{$(Int),Array{$(Int),1}}:\n 2 7 ⋅ ⋅\n 7 12 17 ⋅\n ⋅ 17 22 27\n ⋅ ⋅ 27 32" @test replstr(Tridiagonal(diag(A, -1), diag(A), diag(A, +1))) == "4×4 Tridiagonal{$(Int),Array{$(Int),1}}:\n 1 5 ⋅ ⋅\n 2 6 10 ⋅\n ⋅ 7 11 15\n ⋅ ⋅ 12 16" @test replstr(UpperTriangular(copy(A))) == "4×4 UpperTriangular{$Int,Array{$Int,2}}:\n 1 5 9 13\n ⋅ 6 10 14\n ⋅ ⋅ 11 15\n ⋅ ⋅ ⋅ 16" @test replstr(LowerTriangular(copy(A))) == "4×4 LowerTriangular{$Int,Array{$Int,2}}:\n 1 ⋅ ⋅ ⋅\n 2 6 ⋅ ⋅\n 3 7 11 ⋅\n 4 8 12 16" diff --git a/test/sparse/higherorderfns.jl b/test/sparse/higherorderfns.jl index d25b5eabd0ba6..719e9fa83ffdb 100644 --- a/test/sparse/higherorderfns.jl +++ b/test/sparse/higherorderfns.jl @@ -415,8 +415,8 @@ end @test broadcast(*, s, V, A, X)::SparseMatrixCSC == sparse(broadcast(*, s, fV, fA, X)) @test broadcast!(*, Z, s, V, A, X) == sparse(broadcast(*, s, fV, fA, X)) # Issue #20954 combinations of sparse arrays and Adjoint/Transpose vectors - @test broadcast(+, A, X')::SparseMatrixCSC == sparse(broadcast(+, fA, X')) - @test broadcast(*, V, X')::SparseMatrixCSC == sparse(broadcast(*, fV, X')) + @test broadcast(+, A, adjoint(X))::SparseMatrixCSC == sparse(broadcast(+, fA, adjoint(X))) + @test broadcast(*, V, adjoint(X))::SparseMatrixCSC == sparse(broadcast(*, fV, adjoint(X))) end @test V .+ ntuple(identity, N) isa Vector @test A .+ ntuple(identity, N) isa Matrix diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index cbcb5b2288981..4dc81a7619e53 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -201,7 +201,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) @test (maximum(abs.((a'*c + d) - (Array(a)'*c + d))) < 1000*eps()) @test (maximum(abs.((α*Transpose(a)*c + β*d) - (α*Transpose(Array(a))*c + β*d))) < 1000*eps()) @@ -216,7 +216,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) a = I + tril(0.1*sprandn(5, 5, 0.2)) @@ -225,7 +225,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) a = I + tril(0.1*sprandn(5, 5, 0.2) + 0.1*im*sprandn(5, 5, 0.2)) @@ -234,7 +234,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) a = I + triu(0.1*sprandn(5, 5, 0.2)) @@ -243,7 +243,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) a = I + triu(0.1*sprandn(5, 5, 0.2) + 0.1*im*sprandn(5, 5, 0.2)) @@ -252,7 +252,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) a = I + triu(0.1*sprandn(5, 5, 0.2)) @@ -261,7 +261,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) # UpperTriangular/LowerTriangular solve @@ -284,7 +284,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) b = randn(5,3) + im*randn(5,3) @@ -292,7 +292,7 @@ end @test (maximum(abs.(a'b - Array(a)'b)) < 100*eps()) @test (maximum(abs.(Transpose(a)*b - Transpose(Array(a))*b)) < 100*eps()) @test (maximum(abs.(a\b - Array(a)\b)) < 1000*eps()) - @test (maximum(abs.(a'\b - Array(a')\b)) < 1000*eps()) + @test (maximum(abs.(a'\b - Array(adjoint(a))\b)) < 1000*eps()) @test (maximum(abs.(Transpose(a)\b - Array(transpose(a))\b)) < 1000*eps()) end end @@ -1313,7 +1313,7 @@ end end @testset "issue #9917" begin - @test sparse([]') == reshape(sparse([]), 1, 0) + @test sparse(adjoint([])) == reshape(sparse([]), 1, 0) @test Array(sparse([])) == zeros(0) @test_throws BoundsError sparse([])[1] @test_throws BoundsError sparse([])[1] = 1 @@ -2014,7 +2014,7 @@ end A = guardsrand(1234) do sprand(5, 5, 1/5) end - A = max.(A, A') + A = max.(A, adjoint(A)) LinAlg.fillstored!(A, 1) B = A[5:-1:1, 5:-1:1] @test issymmetric(B) diff --git a/test/statistics.jl b/test/statistics.jl index 84d3ea0616ee7..757a3565c19d0 100644 --- a/test/statistics.jl +++ b/test/statistics.jl @@ -137,8 +137,8 @@ end @test var((1,2,3); mean=0, corrected=false) ≈ 14.0/3 @test_throws ArgumentError var((1,2,3); mean=()) - @test var([1 2 3 4 5; 6 7 8 9 10], 2) ≈ [2.5 2.5]' - @test var([1 2 3 4 5; 6 7 8 9 10], 2; corrected=false) ≈ [2.0 2.0]' + @test var([1 2 3 4 5; 6 7 8 9 10], 2) ≈ adjoint([2.5 2.5]) + @test var([1 2 3 4 5; 6 7 8 9 10], 2; corrected=false) ≈ adjoint([2.0 2.0]) @test stdm([1,2,3], 2) ≈ 1. @test std([1,2,3]) ≈ 1. @@ -152,8 +152,8 @@ end @test std((1,2,3); mean=0) ≈ sqrt(7.0) @test std((1,2,3); mean=0, corrected=false) ≈ sqrt(14.0/3) - @test std([1 2 3 4 5; 6 7 8 9 10], 2) ≈ sqrt.([2.5 2.5]') - @test std([1 2 3 4 5; 6 7 8 9 10], 2; corrected=false) ≈ sqrt.([2.0 2.0]') + @test std([1 2 3 4 5; 6 7 8 9 10], 2) ≈ sqrt.(adjoint([2.5 2.5])) + @test std([1 2 3 4 5; 6 7 8 9 10], 2; corrected=false) ≈ sqrt.(adjoint([2.0 2.0])) let A = ComplexF64[exp(i*im) for i in 1:10^4] @test varm(A, 0.) ≈ sum(map(abs2, A)) / (length(A) - 1) @@ -169,8 +169,8 @@ function safe_cov(x, y, zm::Bool, cr::Bool) end dot(vec(x), vec(y)) / (n - Int(cr)) end -X = [1. 2. 3. 4. 5.; 5. 4. 6. 2. 1.]' -Y = [6. 1. 5. 3. 2.; 2. 7. 8. 4. 3.]' +X = adjoint([1. 2. 3. 4. 5.; 5. 4. 6. 2. 1.]) +Y = adjoint([6. 1. 5. 3. 2.; 2. 7. 8. 4. 3.]) @testset "covariance" begin for vd in [1, 2], zm in [true, false], cr in [true, false] From 664fc98d745fd1fb60d9e4a5f26b5580289d638b Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sun, 17 Dec 2017 14:48:01 -0800 Subject: [PATCH 4/5] Make A' lower to Core.postfixapostrophize(A) with default def = Adjoint(A) and clean up fallout. --- base/boot.jl | 2 ++ base/linalg/generic.jl | 9 ++++++--- base/operators.jl | 3 ++- src/julia-syntax.scm | 2 +- test/arrayops.jl | 2 +- test/show.jl | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index 2d293d2d9ab3c..d409957535667 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -208,6 +208,8 @@ macro _noinline_meta() Expr(:meta, :noinline) end +function postfixapostrophize end + struct BoundsError <: Exception a::Any i::Any diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index 744dc0885a5cc..a14f2981146d8 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -816,15 +816,18 @@ function inv(A::AbstractMatrix{T}) where T ldiv!(factorize(convert(AbstractMatrix{S}, A)), dest) end -function pinv(v::AbstractVector{T}, tol::Real=real(zero(T))) where T - res = similar(v, typeof(zero(T) / (abs2(one(T)) + abs2(one(T)))))' +pinv(v::AbstractVector{T}, tol::Real = real(zero(T))) where {T<:Real} = _vectorpinv(Transpose, v, tol) +pinv(v::AbstractVector{T}, tol::Real = real(zero(T))) where {T<:Complex} = _vectorpinv(Adjoint, v, tol) +pinv(v::AbstractVector{T}, tol::Real = real(zero(T))) where {T} = _vectorpinv(Adjoint, v, tol) +function _vectorpinv(dualfn::Tf, v::AbstractVector{Tv}, tol) where {Tv,Tf} + res = dualfn(similar(v, typeof(zero(Tv) / (abs2(one(Tv)) + abs2(one(Tv)))))) den = sum(abs2, v) # as tol is the threshold relative to the maximum singular value, for a vector with # single singular value σ=√den, σ ≦ tol*σ is equivalent to den=0 ∨ tol≥1 if iszero(den) || tol >= one(tol) fill!(res, zero(eltype(res))) else - res .= v' ./ den + res .= dualfn(v) ./ den end return res end diff --git a/base/operators.jl b/base/operators.jl index 0d0f70e410eee..99a7bea638a19 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -739,7 +739,8 @@ fldmod1(x::T, y::T) where {T<:Real} = (fld1(x,y), mod1(x,y)) # efficient version for integers fldmod1(x::T, y::T) where {T<:Integer} = (fld1(x,y), mod1(x,y)) -# transpose +# postfix apostophre +Core.postfixapostrophize(x) = Adjoint(x) """ adjoint(A) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index ba58b7915dcee..ad47490d0f7f1 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -2396,7 +2396,7 @@ ,.(apply append rows))) `(call (top typed_vcat) ,t ,@a))))) - '|'| (lambda (e) (expand-forms `(call adjoint ,(cadr e)))) + '|'| (lambda (e) (expand-forms `(call (core postfixapostrophize) ,(cadr e)))) '|.'| (lambda (e) (begin (deprecation-message (string "The syntax `.'` for transposition is deprecated, " "and the special lowering of `.'` in multiplication " "(`*`), left-division (`\\`), and right-division (`/`) " diff --git a/test/arrayops.jl b/test/arrayops.jl index 6a90094e6894f..3d2edc4127869 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2048,7 +2048,7 @@ end # module AutoRetType @test isa(cat((1,2), densearray, densearray), Array) end @test isa([[1,2,3]'; [1,2,3]'], Matrix{Int}) - @test isa([[1,2,3]' [1,2,3]'], Transpose{Int, Vector{Int}}) + @test isa([[1,2,3]' [1,2,3]'], Adjoint{Int, Vector{Int}}) @test isa([Any[1.0, 2]'; Any[2.0, 2]'], Matrix{Any}) @test isa([Any[1.0, 2]' Any[2.0, 2]'], Adjoint{Any, Vector{Any}}) # Test that concatenations of heterogeneous Matrix-Vector pairs yield dense matrices diff --git a/test/show.jl b/test/show.jl index 228e7e0c5bf05..3219e6c919e5e 100644 --- a/test/show.jl +++ b/test/show.jl @@ -557,7 +557,7 @@ end @test replstr(Matrix(1.0I, 10, 10)) == "10×10 Array{Float64,2}:\n 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0\n 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0" # an array too long vertically to fit on screen, and too long horizontally: @test replstr(collect(1.:100.)) == "100-element Array{Float64,1}:\n 1.0\n 2.0\n 3.0\n 4.0\n 5.0\n 6.0\n 7.0\n 8.0\n 9.0\n 10.0\n ⋮ \n 92.0\n 93.0\n 94.0\n 95.0\n 96.0\n 97.0\n 98.0\n 99.0\n 100.0" -@test replstr(collect(1.:100.)') == "1×100 Transpose{Float64,Array{Float64,1}}:\n 1.0 2.0 3.0 4.0 5.0 6.0 7.0 … 95.0 96.0 97.0 98.0 99.0 100.0" +@test replstr(collect(1.:100.)') == "1×100 Adjoint{Float64,Array{Float64,1}}:\n 1.0 2.0 3.0 4.0 5.0 6.0 7.0 … 95.0 96.0 97.0 98.0 99.0 100.0" # too big in both directions to fit on screen: @test replstr((1.:100.)*(1:100)') == "100×100 Array{Float64,2}:\n 1.0 2.0 3.0 4.0 5.0 6.0 … 97.0 98.0 99.0 100.0\n 2.0 4.0 6.0 8.0 10.0 12.0 194.0 196.0 198.0 200.0\n 3.0 6.0 9.0 12.0 15.0 18.0 291.0 294.0 297.0 300.0\n 4.0 8.0 12.0 16.0 20.0 24.0 388.0 392.0 396.0 400.0\n 5.0 10.0 15.0 20.0 25.0 30.0 485.0 490.0 495.0 500.0\n 6.0 12.0 18.0 24.0 30.0 36.0 … 582.0 588.0 594.0 600.0\n 7.0 14.0 21.0 28.0 35.0 42.0 679.0 686.0 693.0 700.0\n 8.0 16.0 24.0 32.0 40.0 48.0 776.0 784.0 792.0 800.0\n 9.0 18.0 27.0 36.0 45.0 54.0 873.0 882.0 891.0 900.0\n 10.0 20.0 30.0 40.0 50.0 60.0 970.0 980.0 990.0 1000.0\n ⋮ ⋮ ⋱ \n 92.0 184.0 276.0 368.0 460.0 552.0 8924.0 9016.0 9108.0 9200.0\n 93.0 186.0 279.0 372.0 465.0 558.0 9021.0 9114.0 9207.0 9300.0\n 94.0 188.0 282.0 376.0 470.0 564.0 9118.0 9212.0 9306.0 9400.0\n 95.0 190.0 285.0 380.0 475.0 570.0 9215.0 9310.0 9405.0 9500.0\n 96.0 192.0 288.0 384.0 480.0 576.0 … 9312.0 9408.0 9504.0 9600.0\n 97.0 194.0 291.0 388.0 485.0 582.0 9409.0 9506.0 9603.0 9700.0\n 98.0 196.0 294.0 392.0 490.0 588.0 9506.0 9604.0 9702.0 9800.0\n 99.0 198.0 297.0 396.0 495.0 594.0 9603.0 9702.0 9801.0 9900.0\n 100.0 200.0 300.0 400.0 500.0 600.0 9700.0 9800.0 9900.0 10000.0" From 6e3c1ce413441929883b052c89595e843aeac624 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Mon, 18 Dec 2017 12:44:31 -0800 Subject: [PATCH 5/5] Remove special lowering of ' in *, /, and \ expressions to A[c]_(mul|ldiv|rdiv)_B[c]. --- src/julia-syntax.scm | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index ad47490d0f7f1..dccf06cdf4bff 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1515,22 +1515,6 @@ (kwcall-unless-empty f pa kw-container kw-container) `(call (call (core kwfunc) ,f) ,kw-container ,f ,@pa))))) -;; convert e.g. A'*B to Ac_mul_B(A,B) -(define (expand-transposed-op e ops) - (let ((a (caddr e)) - (b (cadddr e))) - (cond ((ctrans? a) - (if (ctrans? b) - `(call ,(aref ops 0) #;Ac_mul_Bc ,(expand-forms (cadr a)) - ,(expand-forms (cadr b))) - `(call ,(aref ops 1) #;Ac_mul_B ,(expand-forms (cadr a)) - ,(expand-forms b)))) - ((ctrans? b) - `(call ,(aref ops 2) #;A_mul_Bc ,(expand-forms a) - ,(expand-forms (cadr b)))) - (else - `(call ,(cadr e) ,(expand-forms a) ,(expand-forms b)))))) - ;; convert `a+=b` to `a=a+b` (define (expand-update-operator- op op= lhs rhs declT) (let ((e (remove-argument-side-effects lhs))) @@ -2212,19 +2196,6 @@ ((and (eq? f '^) (length= e 4) (integer? (cadddr e))) (expand-forms `(call (top literal_pow) ^ ,(caddr e) (call (call (core apply_type) (top Val) ,(cadddr e)))))) - - ((and (eq? f '*) (length= e 4)) - (expand-transposed-op - e - #(Ac_mul_Bc Ac_mul_B A_mul_Bc))) - ((and (eq? f '/) (length= e 4)) - (expand-transposed-op - e - #(Ac_rdiv_Bc Ac_rdiv_B A_rdiv_Bc))) - ((and (eq? f '\\) (length= e 4)) - (expand-transposed-op - e - #(Ac_ldiv_Bc Ac_ldiv_B A_ldiv_Bc))) (else (map expand-forms e)))) (map expand-forms e)))