Skip to content

Sparse matrices support #83

Description

@jarlebring

Consider

julia> using LinearAlgebra, SparseArrays;
julia> (g,_)=graph_sastre_exp(3);
julia> n=500; A=spdiagm(-1 => 1:n, 1 => 1:n);

Problem 1: eval_graph does not work:

julia> eval_graph(g,A)
ERROR: UndefVarError: `SparseMatrixCSC` not defined
Stacktrace:
 [1] init_vals_eval_graph!(graph::Compgraph{Float64}, x::SparseMatrixCSC{Int64, Int64}, vals::Nothing, input::Symbol)
   @ GraphMatFun ~/.julia/packages/GraphMatFun/3g8TS/src/eval.jl:114
 [2] eval_graph(graph::Compgraph{Float64}, x::SparseMatrixCSC{Int64, Int64}; vals::Nothing, input::Symbol, output::Int64, comporder::Nothing)
   @ GraphMatFun ~/.julia/packages/GraphMatFun/3g8TS/src/eval.jl:49
 [3] eval_graph(graph::Compgraph{Float64}, x::SparseMatrixCSC{Int64, Int64})
   @ GraphMatFun ~/.julia/packages/GraphMatFun/3g8TS/src/eval.jl:41
 [4] top-level scope
   @ REPL[26]:1

Problem 2: Generated code does not work efficiently.

julia> gen_code("myfun.jl",g);
julia> include("myfun.jl");
julia> @btime dummy(A)
  328.665 ms (70 allocations: 1.40 MiB)
julia> @btime A*A*A*A;
  50.880 μs (19 allocations: 182.45 KiB)

Since g has three multiplications they should be essentially the same CPU-time. It's because of memory allocation. Not sure we can think of recycling memory slots as the current generated code is doing since the sparsity pattern will change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions