Code Example
This is an example of adding a code example compiled with Literate.jl in the docs.
First we want to load our package with using
using CellularSheaves
using LinearAlgebraUsing the Package
Here is a simple example of creating a sheaf using the @cellular_sheaf macro.
A = [1.0 0.0 1.0 0.0]
B = [1.0 0.0 0.0 1.0]
C = [1.0 0.0 0.0 0.0]
sheaf = @cellular_sheaf A, B, C begin
x::Stalk{4}, y::Stalk{4}, z::Stalk{4}
A(x) == B(y)
A(x) == C(z)
B(y) == C(z)
endA network sheaf with 3 vertex stalks and 3 edge stalks.
Let's compute a global section of this sheaf. We start with a random 0-cochain:
x0 = rand(sum(vertex_stalks(sheaf)))12-element Vector{Float64}:
0.7821314973723056
0.039485372628759285
0.21363989632016633
0.3695763272169056
0.24971446370614858
0.28225303763984655
0.2393441621662179
0.5631213469737266
0.5025958776169936
0.3347573625738054
0.44857527268125164
0.548624124453838We use the deterministic direct LDLt backend to guarantee a result.
global_section = nearest_global_section(sheaf, x0; method=:ldl)3-blocked 12-element BlockVector{Float64}:
0.6359706704768614
0.039485372628759285
0.06747906942472215
0.3695763272169056
────────────────────
0.19502142831700275
0.28225303763984655
0.2393441621662179
0.5084283115845808
────────────────────
0.7034497399015837
0.3347573625738054
0.44857527268125164
0.548624124453838 Now we can check that this is indeed a global section by verifying that the coboundary map applied to it is zero.
d = coboundary_map(sheaf)
norm(d * global_section)1.5700924586837752e-16