Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.11.3"
version = "0.11.4"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 1 addition & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Base: size, getindex, setindex!, IndexStyle, checkbounds, convert,
show, view, in

import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, adjoint, fill!,
norm2, norm1, normInf, normMinusInf, normp, lmul!, rmul!, diagzero, AbstractTriangular, AdjointAbsVec
dot, norm2, norm1, normInf, normMinusInf, normp, lmul!, rmul!, diagzero, AbstractTriangular, AdjointAbsVec

import Base.Broadcast: broadcasted, DefaultArrayStyle, broadcast_shape

Expand Down
17 changes: 17 additions & 0 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ function *(a::Transpose{T, <:AbstractVector{T}}, b::Zeros{T, 1}) where T<:Real
end
*(a::Transpose{T, <:AbstractMatrix{T}}, b::Zeros{T, 1}) where T<:Real = mult_zeros(a, b)

function dot(u::AbstractVector, E::Eye, v::AbstractVector)
length(u) == size(E,1) && length(v) == size(E,2) ||
throw(DimensionMismatch("dot product arguments have dimensions $(length(u))×$(size(E))×$(length(v))"))
dot(u, v)
end

function dot(u::AbstractVector, D::Diagonal{<:Any,<:Fill}, v::AbstractVector)
length(u) == size(D,1) && length(v) == size(D,2) ||
throw(DimensionMismatch("dot product arguments have dimensions $(length(u))×$(size(D))×$(length(v))"))
D.diag.value*dot(u, v)
end

function dot(u::AbstractVector{T}, D::Diagonal{U,<:Zeros}, v::AbstractVector{V}) where {T,U,V}
length(u) == size(D,1) && length(v) == size(D,2) ||
throw(DimensionMismatch("dot product arguments have dimensions $(length(u))×$(size(D))×$(length(v))"))
zero(promote_type(T,U,V))
end

+(a::Zeros) = a
-(a::Zeros) = a
Expand Down
29 changes: 27 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ end
@test Z[:,1] ≡ Z[1:5,1] ≡ Zeros(5)
@test Z[1,:] ≡ Z[1,1:6] ≡ Zeros(6)
@test Z[:,:] ≡ Z[1:5,1:6] ≡ Z[1:5,:] ≡ Z[:,1:6] ≡ Z

A = Fill(2.0,5,6,7)
Z = Zeros(5,6,7)
@test A[:,1,1] ≡ A[1:5,1,1] ≡ Fill(2.0,5)
Expand Down Expand Up @@ -1098,6 +1098,31 @@ end
end
end

@testset "dot products" begin
n = 15
o = Ones(1:n)
z = Zeros(1:n)
D = Diagonal(o)
Z = Diagonal(z)

Random.seed!(5)
u = rand(n)
v = rand(n)

@test dot(u, D, v) == dot(u, v)
@test dot(u, 2D, v) == 2dot(u, v)
@test dot(u, Z, v) == 0

@test_throws DimensionMismatch dot(u[1:end-1], D, v)
@test_throws DimensionMismatch dot(u[1:end-1], D, v[1:end-1])

@test_throws DimensionMismatch dot(u, 2D, v[1:end-1])
@test_throws DimensionMismatch dot(u, 2D, v[1:end-1])

@test_throws DimensionMismatch dot(u, Z, v[1:end-1])
@test_throws DimensionMismatch dot(u, Z, v[1:end-1])
end

if VERSION ≥ v"1.5"
@testset "print" begin
@test stringmime("text/plain", Zeros(3)) == "3-element Zeros{Float64}"
Expand Down Expand Up @@ -1203,4 +1228,4 @@ end
@test FillArrays.getindex_value(transpose(a)) == FillArrays.unique_value(transpose(a)) == 2.0
@test convert(Fill, transpose(a)) ≡ Fill(2.0,1,5)
end
end
end