Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit 4a0c3c9

Browse files
committed
fix kernel flipping in NNlib.conv call
1 parent af461f6 commit 4a0c3c9

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/derivative_operators/derivative_operator_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ for MT in [2,3]
5959
setindex!(Widx,:,N)
6060
W[Widx...] = s
6161

62-
cv = DenseConvDims(_M, W, padding=pad)
62+
cv = DenseConvDims(_M, W, padding=pad,flipkernel=true)
6363
conv!(_x_temp, _M, W, cv)
6464

6565
# Now deal with boundaries

test/differentiation_dimension.jl

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,98 @@ end
204204
# Test that * agrees will mul!
205205
@test M_temp == L*M
206206
end
207+
208+
@testset "Differentiating with non-symmetric interior stencil" begin
209+
210+
# The following tests check that multiplication of an operator with a
211+
# non-symmetric interior stencil is consistent with what we expect
212+
213+
N = 1
214+
L = CenteredDifference{N}(3,4,0.1,30)
215+
M = zeros(32,32)
216+
for i in 1:32
217+
for j in 1:32
218+
M[i,j] = cos(0.1i)
219+
end
220+
end
221+
222+
M_temp = zeros(30,32)
223+
mul!(M_temp, L, M)
224+
225+
@test M_temp Array(L)*M
226+
227+
N = 2
228+
L = CenteredDifference{N}(3,4,0.1,30)
229+
M = zeros(32,32)
230+
for i in 1:32
231+
for j in 1:32
232+
M[i,j] = cos(0.1j)
233+
end
234+
end
235+
236+
M_temp = zeros(32,30)
237+
mul!(M_temp, L, M)
238+
239+
@test M_temp transpose(Array(L)*transpose(M))
240+
241+
# Three dimensions
242+
243+
N = 1
244+
L = CenteredDifference{N}(3,4,0.1,30)
245+
M = zeros(32,32,32)
246+
for i in 1:32
247+
for j in 1:32
248+
for k in 1:32
249+
M[i,j,k] = cos(0.1i)
250+
end
251+
end
252+
end
253+
254+
M_temp = zeros(30,32,32)
255+
mul!(M_temp, L, M)
256+
for i in 1:32
257+
@test M_temp[:,:,i] Array(L)*M[:,:,i]
258+
end
259+
260+
correct_row = L*M[:,1,1]
261+
262+
N = 2
263+
L = CenteredDifference{N}(3,4,0.1,30)
264+
M = zeros(32,32,32)
265+
for i in 1:32
266+
for j in 1:32
267+
for k in 1:32
268+
M[i,j,k] = cos(0.1j)
269+
end
270+
end
271+
end
272+
273+
M_temp = zeros(32,30,32)
274+
mul!(M_temp, L, M)
275+
276+
for i in 1:32
277+
for j in 1:32
278+
@test M_temp[i,:,j] correct_row
279+
end
280+
end
281+
282+
N = 3
283+
L = CenteredDifference{N}(3,4,0.1,30)
284+
M = zeros(32,32,32)
285+
for i in 1:32
286+
for j in 1:32
287+
for k in 1:32
288+
M[i,j,k] = cos(0.1k)
289+
end
290+
end
291+
end
292+
293+
M_temp = zeros(32,32,30)
294+
mul!(M_temp, L, M)
295+
296+
for i in 1:32
297+
for j in 1:32
298+
@test M_temp[i,j,:] correct_row
299+
end
300+
end
301+
end

0 commit comments

Comments
 (0)