From 471f812022c990df6e5dfc2044494a6d21947fd1 Mon Sep 17 00:00:00 2001 From: adrhill Date: Thu, 5 Sep 2024 17:19:07 +0200 Subject: [PATCH] Add to doctests --- src/adtypes_interface.jl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/adtypes_interface.jl b/src/adtypes_interface.jl index b373477..3e8618b 100644 --- a/src/adtypes_interface.jl +++ b/src/adtypes_interface.jl @@ -19,7 +19,10 @@ For local sparsity patterns at a specific input point, use [`TracerLocalSparsity ```jldoctest julia> using SparseConnectivityTracer -julia> jacobian_sparsity(diff, rand(4), TracerSparsityDetector()) +julia> detector = TracerSparsityDetector() +TracerSparsityDetector() + +julia> jacobian_sparsity(diff, rand(4), detector) 3×4 SparseArrays.SparseMatrixCSC{Bool, Int64} with 6 stored entries: 1 1 ⋅ ⋅ ⋅ 1 1 ⋅ @@ -29,7 +32,7 @@ julia> jacobian_sparsity(diff, rand(4), TracerSparsityDetector()) ```jldoctest julia> f(x) = x[1] + x[2]*x[3] + 1/x[4]; -julia> hessian_sparsity(f, rand(4), TracerSparsityDetector()) +julia> hessian_sparsity(f, rand(4), detector) 4×4 SparseArrays.SparseMatrixCSC{Bool, Int64} with 3 stored entries: ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅ @@ -78,23 +81,24 @@ Local sparsity patterns are less convervative than global patterns and need to b ```jldoctest julia> using SparseConnectivityTracer -julia> method = TracerLocalSparsityDetector(); +julia> detector = TracerLocalSparsityDetector() +TracerLocalSparsityDetector() julia> f(x) = x[1] * x[2]; # J_f = [x[2], x[1]] -julia> jacobian_sparsity(f, [1, 0], method) +julia> jacobian_sparsity(f, [1, 0], detector) 1×2 SparseArrays.SparseMatrixCSC{Bool, Int64} with 1 stored entry: ⋅ 1 -julia> jacobian_sparsity(f, [0, 1], method) +julia> jacobian_sparsity(f, [0, 1], detector) 1×2 SparseArrays.SparseMatrixCSC{Bool, Int64} with 1 stored entry: 1 ⋅ -julia> jacobian_sparsity(f, [0, 0], method) +julia> jacobian_sparsity(f, [0, 0], detector) 1×2 SparseArrays.SparseMatrixCSC{Bool, Int64} with 0 stored entries: ⋅ ⋅ -julia> jacobian_sparsity(f, [1, 1], method) +julia> jacobian_sparsity(f, [1, 1], detector) 1×2 SparseArrays.SparseMatrixCSC{Bool, Int64} with 2 stored entries: 1 1 ```