Open Vaibhavdixit02 opened 6 months ago
Looking at the code it seemed doable since the indices are collected before the sparse matrix is assembled
Indeed, connectivity
is just a thin abstraction layer for book-keeping that iterates over the output and writes input indices into a data structure (currently a sparse matrix).
Do you have a problem in mind in which you expect the Jacobian to have a specific structure? It would be easy to add more wrappers like connectivity
.
We could also define a bring-your-own-buffer version of connectivity
and dispatch on the provided data structure.
I have an idea for a second-order Tracer for sparsity detection in Hessians, which will return a sparse symmetric matrix.
Do you have a problem in mind in which you expect the Jacobian to have a specific structure? It would be easy to add more wrappers like connectivity.
Control problems sometimes have pretty nice banded structures - I am starting a class project where I plan to leverage it I will follow up with more concrete details once I start putting together code for that 😅
It might also be useful to select whether a sparse CSC or CSR matrix should be returned. CC @gdalle
Indeed, and it would really make sense and simplify my job a lot if I could assume that the sparsity pattern and the jacobian have the same structure and type, sparse or otherwise. Typically I wanna do
jac = similar(sparsity, eltype(x))
and I don't want e.g. one to be tridiagonal and the other one sparse, even if they represent the same pattern
I am not 100% sure this would make sense, thinking out loud here - in some scenarios, for example 10*10 hessian, instead of always returning the sparse form of the pattern having a more structured like diagonal, banded, triangular etc etc matrix would lend itself to nice uses downstream like one could check for such a structure and utilize it in algorithms. Looking at the code it seemed doable since the indices are collected before the sparse matrix is assembled