Skip to content

Commit 8a95ac5

Browse files
committed
Implement map for multiple pyramids
1 parent ed984b9 commit 8a95ac5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/PyramidScheme.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ end
124124
Pyramid(newbase, newlevels, DD.metadata(A))
125125
end
126126

127-
function Base.map(f, A::Pyramid)
128-
newbase = map(f, parent(A))
129-
newlevels = [map(f, levels(A,i)) for i in 1:nlevels(A)]
130-
Pyramid(newbase, newlevels, DD.metadata(A)) # This should handle metadata better.
127+
function Base.map(f, A1::Pyramid, As::Pyramid...)
128+
newbase = map(f, parent(A1), parent.(As)...)
129+
newlevels = [map(f, levels(A1,i), levels.(As, i)...) for i in 1:nlevels(A1)]
130+
Pyramid(newbase, newlevels, DD.metadata(A1)) # This should handle metadata better.
131131
end
132132

133133
function DD.show_after(io::IO, mime, A::Pyramid)

test/runtests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ end
140140
end
141141
end
142142

143+
@testitem "Map of pyramids" begin
144+
pyr1 = Pyramid(fill(1,X(1:128),Y(1:128)), tilesize=16)
145+
pyr2 = Pyramid(fill(1, X(1:128),Y(1:128)), tilesize=16, resampling_method=sum)
146+
pyr1_neg = map(x-> x-1, pyr1)
147+
@test all(all.(iszero, pyr1_neg.levels))
148+
@test iszero(pyr1_neg.base)
149+
pyr2_neg = map(x-> x-1, pyr2)
150+
@test pyr2_neg.levels[1][1,1] == 3
151+
152+
pyrsum = map((x,y) -> x + y, pyr1, pyr2)
153+
@test pyrsum[100,30] == 2
154+
@test pyrsum.levels[1][10,10] == 5
155+
@test pyrsum.levels[2][10,10] == 17
156+
end
143157

144158

145159
#=

0 commit comments

Comments
 (0)