GraphMatFun.jl

GraphMatFun.jl is a Julia package for working with computational graphs representing functions of matrices.

Installation

The package is registered with the Julia central registry and can be installed with the command

julia> ]
(v1.7) pkg> add GraphMatFun

When installed, the package can be loaded into the current session by writing

julia> using GraphMatFun

Building a first graph

Consider the following polynomial,

\[p(x) = (1+2x+x^2)^2.\]

A graph representing $p(x)$ can be manually constructed by defining the operations.

julia> graph = Compgraph(Float64);
julia> add_mult!(graph,:A2,:A,:A);
julia> add_lincomb!(graph,:P1,1.0,:I,2.0,:A);
julia> add_lincomb!(graph,:P2,1.0,:A2,1.0,:P1);
julia> add_mult!(graph,:P,:P2,:P2);
julia> add_output!(graph,:P);

The graph can be evaluated in both scalars, vectors, and matrices. For vectors the evaluation is elementwise.

julia> x = [1, 2, 3.5];
julia> eval_graph(graph, x)
3-element Vector{Float64}:
  16.0
  81.0
 410.0625
julia> (1 .+ 2*x + x.^2).^2
3-element Vector{Float64}:
  16.0
  81.0
 410.0625
julia> A = [1 3; 7 2.0];
julia> eval_graph(graph, A)
2×2 Matrix{Float64}:
 1150.0   825.0
 1925.0  1425.0
julia> (I + 2*A + A^2)^2
2×2 Matrix{Float64}:
 1150.0   825.0
 1925.0  1425.0

Since the graph is a polynomial the coefficients can be directly extracted.

julia> get_polynomial_coefficients(graph)
5-element Vector{Float64}:
 1.0
 4.0
 6.0
 4.0
 1.0

How do I cite it?

We are finalizing a software paper for this work. If you find this software useful please cite it by using this citation data:

@Misc{,
  author = {E. Jarlebring and M. Fasi and E. Ringh},
  title  = {Computational graphs for matrix functions},
  year   = {2021},
  eprint = {arXiv:2107.12198},
  note   = {https://github.com/matrixfunctions/GraphMatFun.jl},
}