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.69409996154618
0.9840756958533826
0.7176294059540133
0.16639286962869604
0.5179366841326856
0.4478268691593501
0.5881355711002596
0.4047067850401903
0.7100517951156654
0.7992347891131538
0.9019572877814998
0.5938009515950424We 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.4575448311591334
0.9840756958533826
0.48107427556696664
0.16639286962869604
───────────────────
0.5259245029092976
0.4478268691593501
0.5881355711002596
0.41269460381680234
───────────────────
0.9386191067261
0.7992347891131538
0.9019572877814998
0.5938009515950424 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