Skip to content

Commit 00492dd

Browse files
authored
Ensure correct eltype in 3-term dot involving Eye (#370)
* Ensure correct eltype in 3-term dot involving Eye * Convert to the type of the product
1 parent 550d534 commit 00492dd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/fillalgebra.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ dot(a::AbstractVector, b::AbstractFillVector) = _fill_dot_rev(a, b)
407407
function dot(u::AbstractVector, E::Eye, v::AbstractVector)
408408
length(u) == size(E,1) && length(v) == size(E,2) ||
409409
throw(DimensionMismatch("dot product arguments have dimensions $(length(u))×$(size(E))×$(length(v))"))
410-
dot(u, v)
410+
d = dot(u,v)
411+
T = typeof(one(eltype(E)) * d)
412+
convert(T, d)
411413
end
412414

413415
function dot(u::AbstractVector, D::Diagonal{<:Any,<:Fill}, v::AbstractVector)

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,8 @@ end
19431943
@test dot(Fill(2,N),1:N) == dot(Fill(2,N),1:N) == dot(1:N,Fill(2,N)) == 2*sum(1:N)
19441944
end
19451945

1946+
@test dot(1:4, Eye(4), 1:4) === dot(1:4, oneunit(eltype(Eye(4))) * I(4), 1:4)
1947+
19461948
@test_throws DimensionMismatch dot(u[1:end-1], D, v)
19471949
@test_throws DimensionMismatch dot(u[1:end-1], D, v[1:end-1])
19481950

0 commit comments

Comments
 (0)