SciML / SciMLOperators.jl

SciMLOperators.jl: Matrix-Free Operators for the SciML Scientific Machine Learning Common Interface in Julia
https://docs.sciml.ai/SciMLOperators/stable
MIT License
44 stars 10 forks source link

get determinant of operator array #62

Open vpuri3 opened 2 years ago

vpuri3 commented 2 years ago
using SciMLOperators, LinearAlgebra
D = DiagonalOperator(rand(4))
A = SciMLOperators.AbstractSciMLOperator[D D; D D]
det(A)
ERROR: MethodError: no method matching SciMLOperators.AbstractSciMLOperator(::ScalarOperator{Bool, typeof(SciMLOperators.DEFAULT_UPDATE_FUNC)})
Stacktrace:
 [1] oneunit(#unused#::Type{SciMLOperators.AbstractSciMLOperator})
   @ Base ./number.jl:358
 [2] lutype(T::Type)
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lu.jl:204
 [3] lu(A::Matrix{SciMLOperators.AbstractSciMLOperator}, pivot::RowMaximum; check::Bool)
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lu.jl:279
 [4] det(A::Matrix{SciMLOperators.AbstractSciMLOperator})
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/generic.jl:1549
 [5] top-level scope
   @ REPL[1]:1
vpuri3 commented 2 years ago

after overloading Base.oneunit

Base.oneunit(L::AbstractSciMLOperator) = one(L)
Base.oneunit(LType::Type{<:AbstractSciMLOperator}) = one(LType)

error

julia> det(A)
ERROR: MethodError: no method matching abs(::MatrixOperator{Float64, Diagonal{Float64, Vector{Float64}}, typeof(SciMLOperators.DEFAULT_UPDATE_FUNC)})
Closest candidates are:
  abs(::Unsigned) at int.jl:183
  abs(::Signed) at int.jl:184
  abs(::Union{Float16, Float32, Float64}) at float.jl:486
  ...
Stacktrace:
 [1] generic_lufact!(A::Matrix{Any}, pivot::RowMaximum; check::Bool)
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lu.jl:151
 [2] #lu!#177
   @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lu.jl:135 [inlined]
 [3] #lu#179
   @ /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/lu.jl:279 [inlined]
 [4] det(A::Matrix{MatrixOperator{Float64, Diagonal{Float64, Vector{Float64}}, typeof(SciMLOperators.DEFAULT_UPDATE_FUNC)}})
   @ LinearAlgebra /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/LinearAlgebra/src/generic.jl:1549
 [5] top-level scope
   @ REPL[10]:1