Skip to content

Commit

Permalink
Add Doctests (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrhill authored Apr 3, 2024
1 parent 045274a commit 719b019
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ CurrentModule = SparseConnectivityTracer

Documentation for [SparseConnectivityTracer](https://github.com/adrhill/SparseConnectivityTracer.jl).

## API reference
```@index
```

## API reference
### Interface
```@docs
connectivity
Expand Down
4 changes: 2 additions & 2 deletions src/connectivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Enumerates input indices and constructs [`Tracer`](@ref)s.
## Example
```julia-repl
```jldoctest
julia> x = rand(3);
julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
Expand Down Expand Up @@ -39,7 +39,7 @@ Enumerates inputs `x` and primal outputs `y=f(x)` and returns sparse connectivit
where `C[i, j]` is true if the compute graph connects the `i`-th entry in `y` to the `j`-th entry in `x`.
## Example
```julia-repl
```jldoctest
julia> x = rand(3);
julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
Expand Down
14 changes: 7 additions & 7 deletions src/tracer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For a higher-level interface, refer to [`connectivity`](@ref).
## Examples
By enumerating inputs with tracers, we can keep track of input connectivities:
```julia-repl
```jldoctest
julia> xt = [tracer(1), tracer(2), tracer(3)]
3-element Vector{Tracer}:
Tracer(1,)
Expand All @@ -20,13 +20,13 @@ julia> f(x) = [x[1]^2, 2 * x[1] * x[2]^2, sin(x[3])];
julia> yt = f(xt)
3-element Vector{Tracer}:
Tracer(1,)
Tracer(1, 2)
Tracer(1, 2)
Tracer(3,)
```
This works via operator-overloading, which either keep input connectivities constant,
This works by overloading operators to either keep input connectivities constant,
compute unions or set connectivities to zero:
```julia-repl
```jldoctest Tracer
julia> x = tracer(1, 2, 3)
Tracer(1, 2, 3)
Expand All @@ -53,7 +53,7 @@ Tracer(1, 2, 3, 5)
```
[`Tracer`](@ref) also supports random number generation and pre-allocations:
```
```jldoctest Tracer
julia> M = rand(Tracer, 3, 2)
3×2 Matrix{Tracer}:
Tracer() Tracer()
Expand Down Expand Up @@ -106,7 +106,7 @@ Return raw `UInt64` input indices of a [`Tracer`](@ref).
See also [`sortedinputs`](@ref).
## Example
```julia-repl
```jldoctest
julia> t = tracer(1, 2, 4)
Tracer(1, 2, 4)
Expand All @@ -127,7 +127,7 @@ Return sorted input indices of a [`Tracer`](@ref).
See also [`inputs`](@ref).
## Example
```julia
```jldoctest
julia> t = tracer(1, 2, 4)
Tracer(1, 2, 4)
Expand Down
86 changes: 85 additions & 1 deletion test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "a8456878fc5708d860b66d8359b4004e700f22aa"
project_hash = "4486f686024f7421deb8134dae1d86752576d670"

[[deps.ADTypes]]
git-tree-sha1 = "016833eb52ba2d6bea9fcb50ca295980e728ee24"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
version = "0.2.7"

[[deps.ANSIColoredPrinters]]
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
version = "0.0.1"

[[deps.AbstractTrees]]
git-tree-sha1 = "2d9c9a55f9c93e8887ad391fbae72f8ef55e1177"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -131,6 +136,12 @@ git-tree-sha1 = "c0216e792f518b39b22212127d4a84dc31e4e386"
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
version = "1.3.5"

[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "59939d8a997469ee05c4b4944560a820f9ba0d73"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.4"

[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "eb7f0f8307f71fac7c606984ea5fb2817275d6e4"
Expand Down Expand Up @@ -294,6 +305,12 @@ git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"

[[deps.Documenter]]
deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "CodecZlib", "Dates", "DocStringExtensions", "Downloads", "Git", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "MarkdownAST", "Pkg", "PrecompileTools", "REPL", "RegistryInstances", "SHA", "TOML", "Test", "Unicode"]
git-tree-sha1 = "4a40af50e8b24333b9ec6892546d9ca5724228eb"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "1.3.0"

[[deps.DomainSets]]
deps = ["CompositeTypes", "IntervalSets", "LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "9fd332fb3b276a080e3ebccf0dcd98f4a10bf6a6"
Expand Down Expand Up @@ -322,6 +339,12 @@ git-tree-sha1 = "bdb1942cd4c45e3c678fd11569d5cccd80976237"
uuid = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
version = "1.0.4"

[[deps.Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "4558ab818dcceaab612d1bb8c19cee87eda2b83c"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.5.0+0"

[[deps.ExprTools]]
git-tree-sha1 = "27415f162e6028e81c72b82ef756bf321213b6ec"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Expand Down Expand Up @@ -390,6 +413,18 @@ git-tree-sha1 = "ec632f177c0d990e64d955ccc1b8c04c485a0950"
uuid = "46192b85-c4d5-4398-a991-12ede77f4527"
version = "0.1.6"

[[deps.Git]]
deps = ["Git_jll"]
git-tree-sha1 = "04eff47b1354d702c3a85e8ab23d539bb7d5957e"
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
version = "1.3.1"

[[deps.Git_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "LibCURL_jll", "Libdl", "Libiconv_jll", "OpenSSL_jll", "PCRE2_jll", "Zlib_jll"]
git-tree-sha1 = "12945451c5d0e2d0dca0724c3a8d6448b46bbdf9"
uuid = "f8c6e375-362e-5223-8a59-34ff63f689eb"
version = "2.44.0+1"

[[deps.Glob]]
git-tree-sha1 = "97285bbd5230dd766e9ef6749b80fc617126d496"
uuid = "c27321d9-0574-5035-807b-f59d2c89b15c"
Expand All @@ -401,6 +436,12 @@ git-tree-sha1 = "f218fe3736ddf977e0e772bc9a586b2383da2685"
uuid = "34004b35-14d8-5ef3-9330-4cdb6864b03a"
version = "0.3.23"

[[deps.IOCapture]]
deps = ["Logging", "Random"]
git-tree-sha1 = "8b72179abc660bfab5e28472e019392b97d0985c"
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
version = "0.2.4"

[[deps.IfElse]]
git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1"
uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Expand Down Expand Up @@ -543,6 +584,11 @@ version = "0.16.2"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"

[[deps.LazilyInitializedFields]]
git-tree-sha1 = "8f7f3cabab0fd1800699663533b6d5cb3fc0e612"
uuid = "0e77f7df-68c5-4e49-93ce-4cd80f5598bf"
version = "1.2.2"

[[deps.LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Expand Down Expand Up @@ -579,6 +625,12 @@ version = "1.11.0+1"
[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[deps.Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "f9557a255370125b405568f9767d6d195822a175"
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
version = "1.17.0+0"

[[deps.LinearAlgebra]]
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -623,6 +675,12 @@ version = "0.4.2"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MarkdownAST]]
deps = ["AbstractTrees", "Markdown"]
git-tree-sha1 = "465a70f0fc7d443a00dcdc3267a497397b8a3899"
uuid = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
version = "0.1.2"

[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
Expand Down Expand Up @@ -706,6 +764,12 @@ deps = ["Artifacts", "Libdl"]
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"
version = "0.8.1+2"

[[deps.OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "3da7367955dcc5c54c1ba4d402ccdc09a1a3e046"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "3.0.13+1"

[[deps.OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1"
Expand All @@ -717,6 +781,11 @@ git-tree-sha1 = "dfdf5519f235516220579f949664f1bf44e741c5"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.6.3"

[[deps.PCRE2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "efcefdf7-47ab-520b-bdef-62a2eaa19f15"
version = "10.42.0+1"

[[deps.PDMats]]
deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"]
git-tree-sha1 = "949347156c25054de2db3b166c52ac4728cbad65"
Expand Down Expand Up @@ -823,6 +892,12 @@ git-tree-sha1 = "ce6661add3d5a76c6e2e2c56f14b41a50577276c"
uuid = "324d217c-45ce-50fc-942e-d289b448e8cf"
version = "0.10.4"

[[deps.RegistryInstances]]
deps = ["LazilyInitializedFields", "Pkg", "TOML", "Tar"]
git-tree-sha1 = "ffd19052caf598b8653b99404058fce14828be51"
uuid = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
version = "0.1.0"

[[deps.Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
Expand Down Expand Up @@ -1064,6 +1139,15 @@ git-tree-sha1 = "5b5a892ba7704c0977013bd0f9c30f5d962181e0"
uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624"
version = "0.5.28"

[[deps.TranscodingStreams]]
git-tree-sha1 = "71509f04d045ec714c4748c785a59045c3736349"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.7"
weakdeps = ["Random", "Test"]

[deps.TranscodingStreams.extensions]
TestExt = ["Test", "Random"]

[[deps.URIs]]
git-tree-sha1 = "67db6cc7b3821e19ebe75791a9dd19c9b1188f2b"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 1 addition & 1 deletion test/brusselator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ function brusselator_2d_loop(du, u, p, t)
A*u[i,j,1] - u[i,j,1]^2*u[i,j,2]
end
end
#! format: one
#! format: on
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ using ReferenceTests
using JuliaFormatter
using Aqua
using JET
using Documenter

using LinearAlgebra
using Random
using Symbolics: Symbolics
using NNlib

DocMeta.setdocmeta!(
SparseConnectivityTracer,
:DocTestSetup,
:(using SparseConnectivityTracer);
recursive=true,
)

@testset verbose = true "SparseConnectivityTracer.jl" begin
@testset "Code formatting" begin
@test JuliaFormatter.format(
Expand Down Expand Up @@ -81,4 +89,7 @@ using NNlib
@test C == C_ref
end
end
@testset "Doctests" begin
Documenter.doctest(SparseConnectivityTracer)
end
end

0 comments on commit 719b019

Please sign in to comment.