Skip to content

Commit dc8aa6e

Browse files
authored
Fix #224 (#225)
* fix #224 * bump version
1 parent 46a44e1 commit dc8aa6e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "0.13.9"
3+
version = "0.13.10"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/fillalgebra.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,14 @@ for TYPE in (:Array, :AbstractRange)
247247
-(a::AbstractFill, b::$TYPE) = a + (-b)
248248
end
249249
end
250-
+(a::AbstractFill, b::AbstractFill) = fill_add(a, b)
250+
+(a::AbstractFill, b::AbstractFill) = Fill(getindex_value(a) + getindex_value(b), promote_shape(a,b))
251251
-(a::AbstractFill, b::AbstractFill) = a + (-b)
252252

253-
@inline function fill_add(a, b::AbstractFill)
253+
@inline function fill_add(a::AbstractArray, b::AbstractFill)
254+
promote_shape(a, b)
255+
a .+ [getindex_value(b)]
256+
end
257+
@inline function fill_add(a::AbstractArray{<:Number}, b::AbstractFill)
254258
promote_shape(a, b)
255259
a .+ getindex_value(b)
256260
end

test/runtests.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ as_array(x::AbstractArray) = Array(x)
308308
as_array(x::UniformScaling) = x
309309
function test_addition_and_subtraction(As, Bs, Tout::Type)
310310
for A in As, B in Bs
311-
@testset "$A ± $B" begin
311+
@testset "$(typeof(A)) ± $(typeof(B))" begin
312312
@test A + B isa Tout{promote_type(eltype(A), eltype(B))}
313313
@test as_array(A + B) == as_array(A) + as_array(B)
314314

@@ -326,7 +326,7 @@ end
326326

327327
# Check that all permutations of + / - throw a `DimensionMismatch` exception.
328328
function test_addition_and_subtraction_dim_mismatch(a, b)
329-
@testset "$a ± $b" begin
329+
@testset "$(typeof(a)) ± $(typeof(b))" begin
330330
@test_throws DimensionMismatch a + b
331331
@test_throws DimensionMismatch a - b
332332
@test_throws DimensionMismatch b + a
@@ -376,6 +376,11 @@ end
376376
A_svec, B_svec = SVector{5}(rand(5)), SVector(1, 2, 3, 4, 5)
377377
test_addition_and_subtraction((A_fill, B_fill, Zeros(5)), (A_svec, B_svec), SVector{5})
378378

379+
# Issue #224
380+
A_matmat, B_matmat = Fill(rand(3,3),5), [rand(3,3) for n=1:5]
381+
test_addition_and_subtraction((A_matmat,), (A_matmat,), Fill)
382+
test_addition_and_subtraction((B_matmat,), (A_matmat,), Vector)
383+
379384
# Optimizations for Zeros and RectOrDiagonal{<:Any, <:AbstractFill}
380385
As_special_square = (
381386
Zeros(3, 3), Zeros{Int}(4, 4),

0 commit comments

Comments
 (0)