Skip to content

Commit 85be5d9

Browse files
author
Felix Cremer
authored
Implement map for multiple pyramids (#81)
* Implement map for multiple pyramids * Fix map test
1 parent a59c572 commit 85be5d9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ end
140140
end
141141
end
142142

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

144159

145160
#=

0 commit comments

Comments
 (0)