diff test/ext/sparse_arrays_test.jl @ 1699:3e9c3986930d feature/lazy_tensors/sparse_conversions

Add extensions for SparseArrays and SparseArrayKit that allow conversion of a LazyTensor
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 02 Sep 2024 15:35:54 +0200
parents
children 1dd64b46ca2a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/ext/sparse_arrays_test.jl	Mon Sep 02 15:35:54 2024 +0200
@@ -0,0 +1,35 @@
+using Test
+
+using Sbplib
+using Sbplib.Grids
+using Sbplib.SbpOperators
+using Sbplib.RegionIndices
+
+using SparseArrays
+using Tokens
+
+
+@testset "SparseArray" begin
+    g = equidistant_grid((0,0),(1,2), 20,30)
+    stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
+
+
+    @testset let Δ = laplace(g, stencil_set), M = sparse(Δ)
+        @test ndims(M) == 2
+        @test size(M) == (20*30,20*30)
+
+        v = rand(size(g)...)
+
+        Mv = M*reshape(v,:)
+        @test Mv ≈ reshape(Δ*v,:)
+    end
+
+    @testset let dₙ = normal_derivative(g, stencil_set,CartesianBoundary{1,Lower}()), M = sparse(dₙ)
+        @test ndims(M) == 2
+        @test size(M) == (30,20*30)
+
+        v = rand(size(g)...)
+        Mv = M*reshape(v,:)
+        @test Mv ≈ reshape(dₙ*v,:)
+    end
+end