Skip to content

Commit 47ec78a

Browse files
kshyattdlfivefifty
authored andcommitted
Add some specializations (#74)
* Add some specializations * Add a test for different input eltypes
1 parent ae94797 commit 47ec78a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/fillalgebra.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,27 @@ end
9999
*(a::Diagonal, b::Zeros{<:Any,1}) = mult_zeros(a, b)
100100
*(a::Diagonal, b::Zeros{<:Any,2}) = mult_zeros(a, b)
101101

102+
*(a::Adjoint{T, <:StridedMatrix{T}}, b::Fill{T, 1}) where T = reshape(sum(conj.(parent(a)); dims=1) .* b.value, size(parent(a), 2))
103+
*(a::Transpose{T, <:StridedMatrix{T}}, b::Fill{T, 1}) where T = reshape(sum(parent(a); dims=1) .* b.value, size(parent(a), 2))
104+
*(a::StridedMatrix{T}, b::Fill{T, 1}) where T = reshape(sum(a; dims=2) .* b.value, size(a, 1))
102105

106+
function *(a::Adjoint{T, <:StridedMatrix{T}}, b::Fill{T, 2}) where T
107+
fB = similar(parent(a), size(b, 1), size(b, 2))
108+
fill!(fB, b.value)
109+
return a*fB
110+
end
111+
112+
function *(a::Transpose{T, <:StridedMatrix{T}}, b::Fill{T, 2}) where T
113+
fB = similar(parent(a), size(b, 1), size(b, 2))
114+
fill!(fB, b.value)
115+
return a*fB
116+
end
117+
118+
function *(a::StridedMatrix{T}, b::Fill{T, 2}) where T
119+
fB = similar(a, size(b, 1), size(b, 2))
120+
fill!(fB, b.value)
121+
return a*fB
122+
end
103123
function *(a::Adjoint{T, <:AbstractVector{T}}, b::Zeros{S, 1}) where {T, S}
104124
la, lb = length(a), length(b)
105125
if la lb

test/runtests.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,23 @@ end
846846
p in (-Inf, 0, 0.1, 1, 2, 3, Inf)
847847
@test norm(a,p) norm(Array(a),p)
848848
end
849-
end
849+
end
850+
851+
@testset "multiplication" begin
852+
for T in (Float64, ComplexF64)
853+
fv = T == Float64 ? Float64(1.6) : ComplexF64(1.6, 1.3)
854+
n = 10
855+
k = 12
856+
m = 15
857+
fillvec = Fill(fv, k)
858+
fillmat = Fill(fv, k, m)
859+
A = rand(ComplexF64, n, k)
860+
@test A*fillvec A*Array(fillvec)
861+
@test A*fillmat A*Array(fillmat)
862+
A = rand(ComplexF64, k, n)
863+
@test transpose(A)*fillvec transpose(A)*Array(fillvec)
864+
@test transpose(A)*fillmat transpose(A)*Array(fillmat)
865+
@test adjoint(A)*fillvec adjoint(A)*Array(fillvec)
866+
@test adjoint(A)*fillmat adjoint(A)*Array(fillmat)
867+
end
868+
end

0 commit comments

Comments
 (0)