Skip to content

Use copy instead of similar to respect sparsity structure? #544

Closed as not planned
@gdalle

Description

@gdalle

In these two spots, I use similar to preallocate a structured Jacobian / Hessian.

https://github.com/gdalle/DifferentiationInterface.jl/blob/88c48c1a66709bd1af84a378de06091092fbafd5/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl#L176

https://github.com/gdalle/DifferentiationInterface.jl/blob/88c48c1a66709bd1af84a378de06091092fbafd5/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/hessian.jl#L125

Pros:

  • No need to fill the values
  • Allows specifying the eltype
  • Guarantees that we get a mutable object

Cons:

I think it's still worth using similar because of the mutability argument. If the semantics of similar are broken for e.g. banded matrices, that's where they should be fixed.


Related:

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