Skip to content

Commit

Permalink
Merge pull request #47 from mweastwood/devel
Browse files Browse the repository at this point in the history
fix for custom broadcast operations
  • Loading branch information
mweastwood authored Dec 31, 2017
2 parents d47af9e + 1deac10 commit 2a03495
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# News

## v0.2.6

*unreleased*

* Bugfix for broadcasting operations like `.+=` and `.=`

## v0.2.5

*2017-11-13*
Expand Down
1 change: 1 addition & 0 deletions src/alm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ Base.:(==)(lhs::Alm, rhs::AbstractVector) = false
Base.:(==)(lhs::AbstractVector, rhs::Alm) = false

# Custom broadcasting
Base.Broadcast.broadcast_indices(::Type{<:Alm}, alm) = indices(alm)
Base.Broadcast._containertype(::Type{<:Alm}) = Alm
Base.Broadcast.promote_containertype(::Type{Any}, ::Type{Alm}) = Alm
Base.Broadcast.promote_containertype(::Type{Alm}, ::Type{Any}) = Alm
Expand Down
1 change: 1 addition & 0 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ Base.:(==)(lhs::HealpixMap, rhs::AbstractVector) = false
Base.:(==)(lhs::AbstractVector, rhs::HealpixMap) = false

# Custom broadcasting
Base.Broadcast.broadcast_indices(::Type{<:HealpixMap}, map) = indices(map)
Base.Broadcast._containertype(::Type{<:RingHealpixMap}) = RingHealpixMap
Base.Broadcast._containertype(::Type{<:NestHealpixMap}) = NestHealpixMap
Base.Broadcast.promote_containertype(::Type{Any}, ::Type{T}) where {T<:HealpixMap} = T
Expand Down
8 changes: 8 additions & 0 deletions test/alm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@
@test f.(1, alm, alm) == Alm(lmax, mmax, f.(1, coefficients, coefficients))
@test f.(alm, alm, alm) == Alm(lmax, mmax, f.(coefficients, coefficients, coefficients))
@inferred broadcast(f, alm, alm, alm)

alm1 = Alm(Complex128, lmax, mmax)
rand!(alm1.coefficients)
alm2 = deepcopy(alm1)
alm1 .+= 1
@test alm1 == alm2 .+ 1
alm1 .= sin.(alm1)
@test alm1 == sin.(alm2 .+ 1)
end
end

7 changes: 7 additions & 0 deletions test/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@
@test f.(1, map, map) == Map(nside, f.(1, pixels, pixels))
@test f.(map, map, map) == Map(nside, f.(pixels, pixels, pixels))
@inferred broadcast(f, map, map, map)

map1 = Map(nside, randn(npix))
map2 = deepcopy(map1)
map1 .+= 1
@test map1 == map2 .+ 1
map1 .= sin.(map1)
@test map1 == sin.(map2 .+ 1)
end
end

Expand Down

0 comments on commit 2a03495

Please sign in to comment.