diff --git a/NEWS.md b/NEWS.md index 199b7396ca354..b110f754775dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -214,7 +214,7 @@ Library improvements * Introduced a wrapper type for lazy complex conjugation of arrays, `ConjArray`. Currently, it is used by default for the new `RowVector` type only, and - enforces that both `transpose(vec)` and `ctranspose(vec)` are views not copies. + enforces that both `transpose(vec)` and `ctranspose(vec)` are views not copies ([#20047]). Compiler/Runtime improvements ----------------------------- diff --git a/base/linalg/conjarray.jl b/base/linalg/conjarray.jl index 436ffbf22ee84..a74ec8ad35bce 100644 --- a/base/linalg/conjarray.jl +++ b/base/linalg/conjarray.jl @@ -37,16 +37,12 @@ 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 +@inline similar{T,N}(a::ConjArray, ::Type{T}, dims::Dims{N}) = similar(parent(a), T, dims) # Currently, this is default behavior for RowVector only -""" - conj(rowvector) - -Returns a `ConjArray` lazy view of the input, where each element is conjugated. -""" @inline conj(a::ConjArray) = parent(a) +# Helper functions, currently used by RowVector @inline _conj(a::AbstractArray) = ConjArray(a) @inline _conj{T<:Real}(a::AbstractArray{T}) = a @inline _conj(a::ConjArray) = parent(a) diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index 75f80ec8b0592..1c463c9521ebb 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -48,10 +48,12 @@ typealias ConjRowVector{T, CV <: ConjVector} RowVector{T, CV} convert{T,V<:AbstractVector}(::Type{RowVector{T,V}}, rowvec::RowVector) = RowVector{T,V}(convert(V,rowvec.vec)) -# similar() -@inline similar(rowvec::RowVector) = RowVector(similar(rowvec.vec)) -@inline similar{T}(rowvec::RowVector, ::Type{T}) = RowVector(similar(rowvec.vec, transpose_type(T))) -# There is no resizing similar() because it would be ambiguous if the result were a Matrix or a RowVector +# similar tries to maintain the RowVector wrapper and the parent type +@inline similar(rowvec::RowVector) = RowVector(similar(parent(rowvec))) +@inline similar{T}(rowvec::RowVector, ::Type{T}) = RowVector(similar(parent(rowvec), transpose_type(T))) + +# Resizing similar currently looses its RowVector property. +@inline similar{T,N}(rowvec::RowVector, ::Type{T}, dims::Dims{N}) = similar(parent(rowvec), T, dims) # Basic methods """ @@ -84,8 +86,11 @@ julia> transpose(v) parent(rowvec::RowVector) = rowvec.vec -# Strictly, these are unnecessary but will make things stabler if we introduce -# a "view" for conj(::AbstractArray) +""" + conj(rowvector) + +Returns a `ConjArray` lazy view of the input, where each element is conjugated. +""" @inline conj(rowvec::RowVector) = RowVector(_conj(rowvec.vec)) @inline conj{T<:Real}(rowvec::RowVector{T}) = rowvec