Skip to content

Commit 03eb3e3

Browse files
author
Andy Ferris
committed
Specialized * methods for dot
* Now certain forms of rowvector*vector multiplications are forwarded to `dot`, so that BLAS can be used. * `ConjArray` is defined before `RowVector`. In theory, this could be moved outside of `LinAlg` and directly into `Base`, but the operation is mostly a linear algebra related concept (as opposed to `conj.(array)` which is an elementwise concept).
1 parent 731dc5e commit 03eb3e3

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

base/linalg/conjarray.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ linearindexing{CA <: ConjArray}(::Type{CA}) = linearindexing(parent_type(CA))
4040
4141
Returns a `ConjArray` lazy view of the input, where each element is conjugated.
4242
"""
43-
@inline conj(rv::RowVector) = RowVector(_conj(parent(rv)))
4443
@inline conj(a::ConjArray) = parent(a)
4544

4645
@inline _conj(a::AbstractArray) = ConjArray(a)

base/linalg/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ end
240240
copy_oftype{T,N}(A::AbstractArray{T,N}, ::Type{T}) = copy(A)
241241
copy_oftype{T,N,S}(A::AbstractArray{T,N}, ::Type{S}) = convert(AbstractArray{S,N}, A)
242242

243+
include("conjarray.jl")
243244
include("transpose.jl")
244245
include("rowvector.jl")
245-
include("conjarray.jl")
246246

247247
include("exceptions.jl")
248248
include("generic.jl")

base/linalg/rowvector.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ immutable RowVector{T,V<:AbstractVector} <: AbstractMatrix{T}
2121
end
2222
end
2323

24-
2524
@inline check_types{T1,T2}(::Type{T1},::AbstractVector{T2}) = check_types(T1, T2)
2625
@pure check_types{T1,T2}(::Type{T1},::Type{T2}) = T1 === transpose_type(T2) ? nothing : error("Element type mismatch. Tried to create a `RowVector{$T1}` from an `AbstractVector{$T2}`")
2726

27+
typealias ConjRowVector{T, CV <: ConjVector} RowVector{T, CV}
28+
2829
# The element type may be transformed as transpose is recursive
2930
@inline transpose_type{T}(::Type{T}) = promote_op(transpose, T)
3031

@@ -138,6 +139,11 @@ end
138139

139140
# Multiplication #
140141

142+
# inner product -> dot product specializations
143+
@inline *{T<:Real}(rowvec::RowVector{T}, vec::AbstractVector{T}) = dot(parent(rowvec), vec)
144+
@inline *(rowvec::ConjRowVector, vec::AbstractVector) = dot(rowvec', vec)
145+
146+
# Generic behavior
141147
@inline function *(rowvec::RowVector, vec::AbstractVector)
142148
if length(rowvec) != length(vec)
143149
throw(DimensionMismatch("A has dimensions $(size(rowvec)) but B has dimensions $(size(vec))"))

0 commit comments

Comments
 (0)