Skip to content

Commit

Permalink
Refinements to ConjArray behavior
Browse files Browse the repository at this point in the history
* Avoid creating ConjVector by `(v.')'` or `(v').'`. One side effect is
  to remove a regression so that it dispatches to BLAS/LAPACK under `*`, etc.
  • Loading branch information
Andy Ferris committed Jan 20, 2017
1 parent 03eb3e3 commit bf7ebdb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions base/linalg/conjarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ end
@inline ConjArray{T,N}(a::AbstractArray{T,N}) = ConjArray{conj_type(T), N, typeof(a)}(a)

typealias ConjVector{T, V <: AbstractVector} ConjArray{T, 1, V}
@inline ConjVector{T}(v::AbstractVector{T}) = ConjArray{conj_type(T), 1, typeof(v)}(v)

typealias ConjMatrix{T, M <: AbstractMatrix} ConjArray{T, 2, M}
@inline ConjMatrix{T}(m::AbstractMatrix{T}) = ConjArray{conj_type(T), 2, typeof(m)}(m)

# This type can cause the element type to change under conjugation - e.g. an array of complex arrays.
@inline conj_type(x) = conj_type(typeof(x))
Expand All @@ -34,6 +37,8 @@ linearindexing{CA <: ConjArray}(::Type{CA}) = linearindexing(parent_type(CA))
@propagate_inbounds setindex!{T,N}(a::ConjArray{T,N}, v, i::Int) = setindex!(a.parent, conj(v), i)
@propagate_inbounds setindex!{T,N}(a::ConjArray{T,N}, v, i::Vararg{Int,N}) = setindex!(a.parent, conj(v), i...)

# TODO similar

# Currently, this is default behavior for RowVector only
"""
conj(rowvector)
Expand Down
3 changes: 2 additions & 1 deletion base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ julia> transpose(v)
@inline ctranspose{T<:Real}(vec::AbstractVector{T}) = RowVector(vec)

@inline transpose(rowvec::RowVector) = rowvec.vec
@inline ctranspose{T}(rowvec::RowVector{T}) = _conj(rowvec.vec)
@inline transpose(rowvec::ConjRowVector) = copy(rowvec.vec) # remove the ConjArray wrapper from any raw vector
@inline ctranspose{T}(rowvec::RowVector{T}) = conj(rowvec.vec)
@inline ctranspose{T<:Real}(rowvec::RowVector{T}) = rowvec.vec

parent(rowvec::RowVector) = rowvec.vec
Expand Down
4 changes: 4 additions & 0 deletions test/linalg/conjarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ end
rv = 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

end
2 changes: 1 addition & 1 deletion test/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@test (rv.')::Vector == [1, 2, 3]
@test (rv')::Vector == [1, 2, 3]
@test (tz.')::Vector == [1+im, 2, 3]
@test (tz')::ConjVector == [1-im, 2, 3]
@test (tz')::Vector == [1-im, 2, 3]

@test conj(rv) === rv
@test conj(tz) == [1-im 2 3]
Expand Down

0 comments on commit bf7ebdb

Please sign in to comment.