Skip to content

Commit 6ee3863

Browse files
add direct usage example
1 parent be38750 commit 6ee3863

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,31 @@ In a differential equation, optimization, etc., the default chunk size is comput
4545
from the state vector `u`, and thus if one creates the `dualcache` via
4646
`dualcache(u)` it will match the default chunking of the solver libraries.
4747

48-
### Example
48+
### dualcache Example 1: Direct Usage
49+
50+
```julia
51+
randmat = rand(10, 2)
52+
sto = similar(randmat)
53+
stod = dualcache(sto)
54+
55+
function claytonsample!(sto, τ; randmat=randmat)
56+
sto = get_tmp(sto, τ)
57+
sto .= randmat
58+
τ == 0 && return sto
59+
60+
n = size(sto, 1)
61+
for i in 1:n
62+
v = sto[i, 2]
63+
u = sto[i, 1]
64+
sto[i, 2] = (1 - u^(-τ) + u^(-τ)*v^(-/(1 + τ))))^(-1/τ)
65+
end
66+
return sto
67+
end
68+
69+
ForwardDiff.derivative-> claytonsample!(stod, τ), 0.3)
70+
```
71+
72+
### dualcache Example 2: ODEs
4973

5074
```julia
5175
using LinearAlgebra, OrdinaryDiffEq

0 commit comments

Comments
 (0)