Skip to content

Instantly share code, notes, and snippets.

@briochemc
Created February 28, 2019 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briochemc/d5d82f8eb3d4f4b79a235baa7fadfc60 to your computer and use it in GitHub Desktop.
Save briochemc/d5d82f8eb3d4f4b79a235baa7fadfc60 to your computer and use it in GitHub Desktop.
using DualNumbers, LinearAlgebra, SparseArrays, SuiteSparse
n = 10
A = randn(n, n) # a real-valued matrix
B = randn(n, n) # another real-valued matrix
# Create a dual-valued matrix
M = A + ε * B
# And a sparse version of it
spM = sparse(M)
# Create the DualFactors type
struct DualFactors
Af # the factors of the real part
B # the ε part
end
# Overload the factorize
function LinearAlgebra.factorize(M::AbstractArray{Dual128,2})
return DualFactors(factorize(realpart.(M)), dualpart.(M))
end
# And break things
spMf = factorize(spM)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment