Skip to content

Commit 29b6452

Browse files
committed
Specialize scaling by a number
1 parent 721dbf2 commit 29b6452

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/fillalgebra.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ mult_zeros(a::AbstractArray{<:Number}, b::AbstractArray{<:Number}) = mult_zeros(
7878
mult_zeros(a, b) = mult_fill(a, b, mult_axes(a, b))
7979
mult_ones(a, b) = mult_ones(a, b, mult_axes(a, b))
8080

81+
# scaling
82+
*(a::AbstractFill, b::Number) = Fill(getindex_value(a) * b, axes(a))
83+
*(a::Number, b::AbstractFill) = Fill(a * getindex_value(b), axes(b))
84+
*(a::AbstractZeros, b::Number) = Zeros(typeof(getindex_value(a) * b), axes(a))
85+
*(a::Number, b::AbstractZeros) = Zeros(typeof(a * getindex_value(b)), axes(b))
86+
87+
# matmul
8188
*(a::AbstractFillMatrix, b::AbstractFillMatrix) = mult_fill(a,b)
8289
*(a::AbstractFillMatrix, b::AbstractFillVector) = mult_fill(a,b)
8390

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,11 @@ end
11671167

11681168
@testset "0d" begin
11691169
@test real.(Fill(2)) == real.(fill(2))
1170+
@test (@. 2 * Fill(2) * 2) == (@. 2 * fill(2) * 2)
1171+
for (F, A) in ((Fill(2), fill(2)), (Zeros(), zeros()), (Ones(), ones()))
1172+
@test F * 2 == A * 2
1173+
@test 2 * F == 2 * A
1174+
end
11701175
end
11711176

11721177
@testset "preserve 0d" begin

0 commit comments

Comments
 (0)