Skip to content

Commit

Permalink
Compare with Symbolics (#4)
Browse files Browse the repository at this point in the history
* Support mutating functions

* Compare test outputs against Symbolics.jl
  • Loading branch information
gdalle authored Apr 1, 2024
1 parent 35810e3 commit 045274a
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 11 deletions.
13 changes: 13 additions & 0 deletions src/connectivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ function connectivity(f::Function, x)
return _connectivity(xt, yt)
end

"""
connectivity(f!, y, x)
Enumerates inputs `x` and primal outputs `y` after `f!(y, x)` and returns sparse connectivity matrix `C` of size `(m, n)`
where `C[i, j]` is true if the compute graph connects the `i`-th entry in `y` to the `j`-th entry in `x`.
"""
function connectivity(f!::Function, y, x)
xt = trace_input(x)
yt = similar(y, Tracer)
f!(yt, xt)
return _connectivity(xt, yt)
end

_connectivity(xt::Tracer, yt::Number) = _connectivity([xt], [yt])
_connectivity(xt::Tracer, yt::AbstractArray{Number}) = _connectivity([xt], yt)
_connectivity(xt::AbstractArray{Tracer}, yt::Number) = _connectivity(xt, [yt])
Expand Down
Loading

0 comments on commit 045274a

Please sign in to comment.