Skip to content

Commit

Permalink
Added similar and other code review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andyferris committed Jan 23, 2017
1 parent 25be2f3 commit 3de51ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------------
Expand Down
8 changes: 2 additions & 6 deletions base/linalg/conjarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3de51ef

Please sign in to comment.