Skip to content

Commit

Permalink
Fix #224 (#225)
Browse files Browse the repository at this point in the history
* fix #224

* bump version
  • Loading branch information
putianyi889 authored Mar 22, 2023
1 parent 46a44e1 commit dc8aa6e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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.13.9"
version = "0.13.10"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
8 changes: 6 additions & 2 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,14 @@ for TYPE in (:Array, :AbstractRange)
-(a::AbstractFill, b::$TYPE) = a + (-b)
end
end
+(a::AbstractFill, b::AbstractFill) = fill_add(a, b)
+(a::AbstractFill, b::AbstractFill) = Fill(getindex_value(a) + getindex_value(b), promote_shape(a,b))
-(a::AbstractFill, b::AbstractFill) = a + (-b)

@inline function fill_add(a, b::AbstractFill)
@inline function fill_add(a::AbstractArray, b::AbstractFill)
promote_shape(a, b)
a .+ [getindex_value(b)]
end
@inline function fill_add(a::AbstractArray{<:Number}, b::AbstractFill)
promote_shape(a, b)
a .+ getindex_value(b)
end
Expand Down
9 changes: 7 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ as_array(x::AbstractArray) = Array(x)
as_array(x::UniformScaling) = x
function test_addition_and_subtraction(As, Bs, Tout::Type)
for A in As, B in Bs
@testset "$A ± $B" begin
@testset "$(typeof(A)) ± $(typeof(B))" begin
@test A + B isa Tout{promote_type(eltype(A), eltype(B))}
@test as_array(A + B) == as_array(A) + as_array(B)

Expand All @@ -326,7 +326,7 @@ end

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

# Issue #224
A_matmat, B_matmat = Fill(rand(3,3),5), [rand(3,3) for n=1:5]
test_addition_and_subtraction((A_matmat,), (A_matmat,), Fill)
test_addition_and_subtraction((B_matmat,), (A_matmat,), Vector)

# Optimizations for Zeros and RectOrDiagonal{<:Any, <:AbstractFill}
As_special_square = (
Zeros(3, 3), Zeros{Int}(4, 4),
Expand Down

2 comments on commit dc8aa6e

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/80123

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.10 -m "<description of version>" dc8aa6e449773e9640979f4d4e4b3d95ee5e4eb9
git push origin v0.13.10

Please sign in to comment.