Skip to content

Commit d322dbe

Browse files
Andy Ferrisandyferris
Andy Ferris
authored andcommitted
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 9fadcfe commit d322dbe

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,11 +21,12 @@ 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 :
2726
error("Element type mismatch. Tried to create a `RowVector{$T1}` from an `AbstractVector{$T2}`")
2827

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

@@ -147,6 +148,11 @@ end
147148

148149
# Multiplication #
149150

151+
# inner product -> dot product specializations
152+
@inline *{T<:Real}(rowvec::RowVector{T}, vec::AbstractVector{T}) = dot(parent(rowvec), vec)
153+
@inline *(rowvec::ConjRowVector, vec::AbstractVector) = dot(rowvec', vec)
154+
155+
# Generic behavior
150156
@inline function *(rowvec::RowVector, vec::AbstractVector)
151157
if length(rowvec) != length(vec)
152158
throw(DimensionMismatch("A has dimensions $(size(rowvec)) but B has dimensions $(size(vec))"))

0 commit comments

Comments
 (0)