Skip to content

Commit bf7ebdb

Browse files
author
Andy Ferris
committed
Refinements to ConjArray behavior
* Avoid creating ConjVector by `(v.')'` or `(v').'`. One side effect is to remove a regression so that it dispatches to BLAS/LAPACK under `*`, etc.
1 parent 03eb3e3 commit bf7ebdb

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

base/linalg/conjarray.jl

+5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ end
1515
@inline ConjArray{T,N}(a::AbstractArray{T,N}) = ConjArray{conj_type(T), N, typeof(a)}(a)
1616

1717
typealias ConjVector{T, V <: AbstractVector} ConjArray{T, 1, V}
18+
@inline ConjVector{T}(v::AbstractVector{T}) = ConjArray{conj_type(T), 1, typeof(v)}(v)
19+
1820
typealias ConjMatrix{T, M <: AbstractMatrix} ConjArray{T, 2, M}
21+
@inline ConjMatrix{T}(m::AbstractMatrix{T}) = ConjArray{conj_type(T), 2, typeof(m)}(m)
1922

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

40+
# TODO similar
41+
3742
# Currently, this is default behavior for RowVector only
3843
"""
3944
conj(rowvector)

base/linalg/rowvector.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ julia> transpose(v)
7272
@inline ctranspose{T<:Real}(vec::AbstractVector{T}) = RowVector(vec)
7373

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

7879
parent(rowvec::RowVector) = rowvec.vec

test/linalg/conjarray.jl

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ end
1818
rv = v'
1919
@test (parent(rv) isa ConjArray)
2020
@test rv' === v
21+
22+
# Currently, view behavior defaults to only RowVectors.
23+
@test isa((v').', Vector)
24+
@test isa((v.')', Vector)
2125
end
2226

2327
end

test/linalg/rowvector.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@test (rv.')::Vector == [1, 2, 3]
2626
@test (rv')::Vector == [1, 2, 3]
2727
@test (tz.')::Vector == [1+im, 2, 3]
28-
@test (tz')::ConjVector == [1-im, 2, 3]
28+
@test (tz')::Vector == [1-im, 2, 3]
2929

3030
@test conj(rv) === rv
3131
@test conj(tz) == [1-im 2 3]

0 commit comments

Comments
 (0)