Skip to content

Commit 2a03495

Browse files
authored
Merge pull request #47 from mweastwood/devel
fix for custom broadcast operations
2 parents d47af9e + 1deac10 commit 2a03495

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# News
22

3+
## v0.2.6
4+
5+
*unreleased*
6+
7+
* Bugfix for broadcasting operations like `.+=` and `.=`
8+
39
## v0.2.5
410

511
*2017-11-13*

src/alm.jl

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ Base.:(==)(lhs::Alm, rhs::AbstractVector) = false
288288
Base.:(==)(lhs::AbstractVector, rhs::Alm) = false
289289

290290
# Custom broadcasting
291+
Base.Broadcast.broadcast_indices(::Type{<:Alm}, alm) = indices(alm)
291292
Base.Broadcast._containertype(::Type{<:Alm}) = Alm
292293
Base.Broadcast.promote_containertype(::Type{Any}, ::Type{Alm}) = Alm
293294
Base.Broadcast.promote_containertype(::Type{Alm}, ::Type{Any}) = Alm

src/map.jl

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Base.:(==)(lhs::HealpixMap, rhs::AbstractVector) = false
303303
Base.:(==)(lhs::AbstractVector, rhs::HealpixMap) = false
304304

305305
# Custom broadcasting
306+
Base.Broadcast.broadcast_indices(::Type{<:HealpixMap}, map) = indices(map)
306307
Base.Broadcast._containertype(::Type{<:RingHealpixMap}) = RingHealpixMap
307308
Base.Broadcast._containertype(::Type{<:NestHealpixMap}) = NestHealpixMap
308309
Base.Broadcast.promote_containertype(::Type{Any}, ::Type{T}) where {T<:HealpixMap} = T

test/alm.jl

+8
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@
154154
@test f.(1, alm, alm) == Alm(lmax, mmax, f.(1, coefficients, coefficients))
155155
@test f.(alm, alm, alm) == Alm(lmax, mmax, f.(coefficients, coefficients, coefficients))
156156
@inferred broadcast(f, alm, alm, alm)
157+
158+
alm1 = Alm(Complex128, lmax, mmax)
159+
rand!(alm1.coefficients)
160+
alm2 = deepcopy(alm1)
161+
alm1 .+= 1
162+
@test alm1 == alm2 .+ 1
163+
alm1 .= sin.(alm1)
164+
@test alm1 == sin.(alm2 .+ 1)
157165
end
158166
end
159167

test/map.jl

+7
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@
167167
@test f.(1, map, map) == Map(nside, f.(1, pixels, pixels))
168168
@test f.(map, map, map) == Map(nside, f.(pixels, pixels, pixels))
169169
@inferred broadcast(f, map, map, map)
170+
171+
map1 = Map(nside, randn(npix))
172+
map2 = deepcopy(map1)
173+
map1 .+= 1
174+
@test map1 == map2 .+ 1
175+
map1 .= sin.(map1)
176+
@test map1 == sin.(map2 .+ 1)
170177
end
171178
end
172179

0 commit comments

Comments
 (0)