Skip to content

Commit

Permalink
Handle changed copy_oftype (#172)
Browse files Browse the repository at this point in the history
* Handle changed `copy_oftype`

* Update ci.yml

* Set version to 0.14.0

* Use `copy_oftype` again

* Put tests back

* Switch to map

* Add `_copy_oftype`
  • Loading branch information
rikhuijzer committed Mar 8, 2022
1 parent 9d3d1cc commit 09835a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: CI
on:
- push
- pull_request
push:
branches:
- master
pull_request:
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand All @@ -12,7 +14,7 @@ jobs:
version:
- '1.6'
- '1'
- '^1.7.0-0'
- '^1.8.0-0'
os:
- ubuntu-latest
- macOS-latest
Expand Down
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.0"
version = "0.13.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
11 changes: 8 additions & 3 deletions src/fillbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,26 @@ function broadcasted(::DefaultArrayStyle{1}, ::typeof(*), a::AbstractRange{V}, b
return _range_convert(AbstractVector{promote_type(T,V)}, a)
end

_copy_oftype(A::AbstractArray{T,N}, ::Type{T}) where {T,N} = copy(A)
_copy_oftype(A::AbstractArray{T,N}, ::Type{S}) where {T,N,S} = convert(AbstractArray{S,N}, A)
_copy_oftype(A::AbstractRange{T}, ::Type{T}) where T = copy(A)
_copy_oftype(A::AbstractRange{T}, ::Type{S}) where {T,S} = map(S, A)

for op in (:+, -)
@eval begin
function broadcasted(::DefaultArrayStyle{1}, ::typeof($op), a::AbstractVector{T}, b::Zeros{V,1}) where {T,V}
broadcast_shape(axes(a), axes(b)) == axes(a) || throw(ArgumentError("Cannot broadcast $a and $b. Convert $b to a Vector first."))
LinearAlgebra.copy_oftype(a, promote_type(T,V))
_copy_oftype(a, promote_type(T,V))
end

broadcasted(::DefaultArrayStyle{1}, ::typeof($op), a::AbstractFill{T,1}, b::Zeros{V,1}) where {T,V} =
broadcasted(::DefaultArrayStyle{1}, ::typeof($op), a::AbstractFill{T,1}, b::Zeros{V,1}) where {T,V} =
Base.invoke(broadcasted, Tuple{DefaultArrayStyle, typeof($op), AbstractFill, AbstractFill}, DefaultArrayStyle{1}(), $op, a, b)
end
end

function broadcasted(::DefaultArrayStyle{1}, ::typeof(+), a::Zeros{T,1}, b::AbstractVector{V}) where {T,V}
broadcast_shape(axes(a), axes(b))
LinearAlgebra.copy_oftype(b, promote_type(T,V))
_copy_oftype(b, promote_type(T,V))
end

broadcasted(::DefaultArrayStyle{1}, ::typeof(+), a::Zeros{V,1}, b::AbstractFill{T,1}) where {T,V} =
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ end

@test copy(m) m
@test copy(D) D
@test LinearAlgebra.copy_oftype(m, Int) Eye{Int}(10)
@test LinearAlgebra.copy_oftype(D, Float64) Diagonal(Fill(2.0,10))
@test FillArrays._copy_oftype(m, Int) Eye{Int}(10)
@test FillArrays._copy_oftype(D, Float64) Diagonal(Fill(2.0,10))
end

@testset "Issue #31" begin
Expand Down

2 comments on commit 09835a1

@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/56224

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.1 -m "<description of version>" 09835a15000604409cba363ed1481302bc1a120c
git push origin v0.13.1

Please sign in to comment.