Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Ferris committed Aug 29, 2017
1 parent bd378c0 commit aef7238
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
27 changes: 12 additions & 15 deletions base/linalg/conjarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

"""
Expand All @@ -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))
Expand Down
10 changes: 3 additions & 7 deletions test/linalg/conjarray.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit aef7238

Please sign in to comment.