From 754ac5daf490f0311c45c749936725626e5f250f Mon Sep 17 00:00:00 2001
From: Stephan Hilb <stephan@ecshi.net>
Date: Sat, 10 Sep 2022 21:48:58 +0200
Subject: [PATCH] fix divergence kernel function for matrix valued arrays

---
 src/common.jl    | 4 ++--
 test/runtests.jl | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/common.jl b/src/common.jl
index 8144a3d..e5fe030 100644
--- a/src/common.jl
+++ b/src/common.jl
@@ -98,8 +98,8 @@ function divergence end
     end
 end
 
-@generated function divergence(w::StaticKernels.Window{S,N}) where {S<:SArray,N}
-    T = eltype(S)
+@generated function divergence(w::StaticKernels.Window{S,N}) where {M,N,S<:SMatrix{M,N}}
+    T = SVector{M,eltype(S)}
     sz = size(S)
     sz[end] == N || throw(ArgumentError("last eltype dimension does not match array dimensionality"))
 
diff --git a/test/runtests.jl b/test/runtests.jl
index ffd5184..46d7c7b 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -98,3 +98,9 @@ end
     end
     @test fetch_u(st) ≈ fetch_u(stref)
 end
+
+@testset "divergence on extended arrays" begin
+    k = Kernel{(-1:1,-1:1)}(DualTVDD.divergence)
+    a = rand(SMatrix{2, 2, Float64}, 3, 3)
+    map(k, extend(a, StaticKernels.ExtensionNothing()))
+end
-- 
GitLab