diff --git a/base/linalg/conjarray.jl b/base/linalg/conjarray.jl index a74faacf445ad..3fe2077ce45be 100644 --- a/base/linalg/conjarray.jl +++ b/base/linalg/conjarray.jl @@ -20,7 +20,7 @@ julia> ConjArray([1+im 0; 0 1-im]) 0+0im 1+1im ``` """ -struct ConjArray{T,N,A<:AbstractArray} <: AbstractArray{T,N} +struct ConjArray{T,N,A<:AbstractArray{<:Any,N}} <: AbstractArray{T,N} parent::A end @@ -51,12 +51,8 @@ IndexStyle(::Type{CA}) where {CA<:ConjArray} = IndexStyle(parent_type(CA)) @inline similar(a::ConjArray, ::Type{T}, dims::Dims{N}) where {T,N} = similar(parent(a), T, dims) -# Currently, this is default behavior for RowVector only -@inline conj(a::ConjArray) = parent(a) -@inline adjoint(a::ConjArray) = ConjAdjointArray(parent(a)) - """ -AdjointArray(array) + AdjointArray(array) A lazy-view wrapper of an `AbstractArray`, taking the elementwise adjoint. This type is usually constructed (and unwrapped) via the [`adjoint`](@ref) function, but @@ -75,7 +71,7 @@ julia> AdjointArray([1+im 0; 0 1-im]) 0+0im 1+1im ``` """ -struct AdjointArray{T,N,A<:AbstractArray} <: AbstractArray{T,N} +struct AdjointArray{T,N,A<:AbstractArray{<:Any,N}} <: AbstractArray{T,N} parent::A end @@ -106,12 +102,8 @@ IndexStyle(::Type{AA}) where {AA<:AdjointArray} = IndexStyle(parent_type(AA)) @inline similar(a::AdjointArray, ::Type{T}, dims::Dims{N}) where {T,N} = similar(parent(a), T, dims) -# Currently, this is default behavior for RowVector only -@inline adjoint(a::AdjointArray) = parent(a) -@inline conj(a::AdjointArray) = ConjAdjointArray(parent(a)) - """ -ConjAdjointArray(array) + ConjAdjointArray(array) A lazy-view wrapper of an `AbstractArray`, mapping each element `i` to `conj(adjoint(i))`. This type is usually constructed (and unwrapped) via consecutive [`adjoint`](@ref) and @@ -130,7 +122,7 @@ julia> ConjAdjointArray([1+im 0; 0 1-im]) 0+0im 1-1im ``` """ -struct ConjAdjointArray{T,N,A<:AbstractArray} <: AbstractArray{T,N} +struct ConjAdjointArray{T,N,A<:AbstractArray{<:Any,N}} <: AbstractArray{T,N} parent::A end @@ -162,11 +154,16 @@ IndexStyle(::Type{A}) where {A<:ConjAdjointArray} = IndexStyle(parent_type(A)) @inline similar(a::ConjAdjointArray, ::Type{T}, dims::Dims{N}) where {T,N} = similar(parent(a), T, dims) # Currently, this is default behavior for RowVector only -@inline adjoint(a::ConjAdjointArray) = ConjArray(parent(a)) +@inline conj(a::ConjArray) = parent(a) +@inline conj(a::AdjointArray) = ConjAdjointArray(parent(a)) @inline conj(a::ConjAdjointArray) = AdjointArray(parent(a)) +@inline adjoint(a::ConjArray) = ConjAdjointArray(parent(a)) +@inline adjoint(a::AdjointArray) = parent(a) +@inline adjoint(a::ConjAdjointArray) = ConjArray(parent(a)) + # Helper functions, currently used by RowVector -# (some of these are simplify types that would not typically occur) +# (some of these simplify types that would not typically occur) @inline _conj(a::AbstractArray) = ConjArray(a) @inline _conj(a::AbstractArray{<:Real}) = a @inline _conj(a::ConjArray) = parent(a) diff --git a/base/linalg/generic.jl b/base/linalg/generic.jl index 48744296adf0a..4ab8bb177228e 100644 --- a/base/linalg/generic.jl +++ b/base/linalg/generic.jl @@ -929,7 +929,7 @@ issymmetric(x::Number) = x == x """ ishermitian(A) -> Bool -Test whether a matrix is Hermitian (such that `A = adjoint(A)`). +Test whether a matrix is Hermitian (such that `A == adjoint(A)`). # Examples ```jldoctest diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index 4fa92fb1a86d3..c4ec9ad7d7ee9 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -70,13 +70,7 @@ julia> transpose(v) @inline transpose(vec::AbstractVector) = RowVector(vec) @inline adjoint(vec::AbstractVector) = RowVector(_adjoint(vec)) -# For the moment, we remove the ConjArray wrapper from any raw vector of numbers, to allow for BLAS specializations @inline transpose(rowvec::RowVector) = parent(rowvec) -@inline transpose(rowvec::ConjRowVector{<:Number}) = copy(parent(rowvec)) - -@inline adjoint(rowvec::RowVector{<:Real}) = parent(rowvec) -@inline adjoint(rowvec::RowVector{<:Number}) = conj(parent(rowvec)) -@inline adjoint(rowvec::ConjRowVector{<:Number}) = parent(rowvec) @inline adjoint(rowvec::RowVector) = _adjoint(parent(rowvec)) """ @@ -96,7 +90,6 @@ julia> conj(v) ``` """ @inline conj(rowvec::RowVector) = RowVector(_conj(parent(rowvec))) -@inline conj(rowvec::RowVector{<:Real}) = rowvec # AbstractArray interface @inline length(rowvec::RowVector) = length(parent(rowvec)) diff --git a/test/linalg/conjarray.jl b/test/linalg/conjarray.jl index 4ba4ac90ad5bb..ff4a783856d49 100644 --- a/test/linalg/conjarray.jl +++ b/test/linalg/conjarray.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -@testset "Core" begin +@testset "ConjArray core" begin m = [1+im 2; 2 4-im] cm = ConjMatrix(m) @test cm[1,1] == 1-im @@ -16,13 +16,9 @@ @test cv[1] == [1-im] end -@testset "RowVector conjugates" begin +@testset "RowVector conjugation" begin v = [1+im, 1-im] - rv = v' + rv = conj(v.') @test (parent(rv) isa ConjArray) @test rv' === v - - # Currently, view behavior defaults to only RowVectors. - @test isa((v').', Vector) - @test isa((v.')', Vector) end