-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
start fixing ambiguities #437
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #437 +/- ##
==========================================
- Coverage 66.50% 65.44% -1.06%
==========================================
Files 27 27
Lines 2039 2072 +33
==========================================
Hits 1356 1356
- Misses 683 716 +33 ☔ View full report in Codecov by Sentry. |
src/factorization.jl
Outdated
end | ||
|
||
function init_cacheval(::FastQRFactorization{Val{true}}, A, b, u, Pl, Pr, | ||
function init_cacheval(::FastQRFactorization{Val{true}}, A::AbstractMatrix, b, u, Pl, Pr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the operator dispatches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still catch them:
LinearSolve.jl/src/factorization.jl
Lines 1458 to 1466 in d80fade
for alg in InteractiveUtils.subtypes(AbstractFactorization) | |
@eval function init_cacheval(alg::$alg, A::MatrixOperator, b, u, Pl, Pr, | |
maxiters::Int, abstol, reltol, verbose::Bool, | |
assumptions::OperatorAssumptions) | |
init_cacheval(alg, A.A, b, u, Pl, Pr, | |
maxiters::Int, abstol, reltol, verbose::Bool, | |
assumptions::OperatorAssumptions) | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's only for matrix operator. What about other abstract scimloperators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is none for that,
but note that this is currently not working anyway:
using LinearSolve
using SciMLOperators
N = 4
f = (u, p, t) -> u .* u
M = MatrixOperator(rand(N, N))
D = DiagonalOperator(rand(N))
F = FunctionOperator(f, zeros(N), zeros(N))
b = rand(4)
solve(LinearProblem(rand(N, N), b),FastQRFactorization()) # works
solve(LinearProblem(M, b),FastQRFactorization()) # fails
solve(LinearProblem(D, b),FastQRFactorization()) # fails
solve(LinearProblem(F, b),FastQRFactorization()) # fails
julia> solve(LinearProblem(M, b),FastQRFactorization())
ERROR: MethodError: init_cacheval(::FastQRFactorization{LinearAlgebra.NoPivot}, ::MatrixOperator{Float64, Matrix{Float64}, SciMLOperators.FilterKwargs{typeof(SciMLOperators.DEFAULT_UPDATE_FUNC), Tuple{}}, SciMLOperators.FilterKwargs{typeof(SciMLOperators.DEFAULT_UPDATE_FUNC), Tuple{}}}, ::Vector{Float64}, ::Vector{Float64}, ::IdentityOperator, ::IdentityOperator, ::Int64, ::Float64, ::Float64, ::Bool, ::OperatorAssumptions{Bool}) is ambiguous.
Candidates:
init_cacheval(alg::FastQRFactorization, A::MatrixOperator, b, u, Pl, Pr, maxiters::Int64, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
@ LinearSolve C:\Users\arno.julia\packages\LinearSolve\8EgR1\src\factorization.jl:1180
init_cacheval(alg::FastQRFactorization{LinearAlgebra.NoPivot}, A, b, u, Pl, Pr, maxiters::Int64, abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
@ LinearSolve C:\Users\arno.julia\packages\LinearSolve\8EgR1\src\factorization.jl:1066
Possible fix, define
init_cacheval(::FastQRFactorization{LinearAlgebra.NoPivot}, ::MatrixOperator, ::Any, ::Any, ::Any, ::Any, ::Int64, ::Any, ::Any, ::Bool, ::OperatorAssumptions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that was working before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For it to ever have worked for FunctionOperators it needed to have this defined
WorkspaceAndFactors(ws, ArrayInterface.qr_instance(A))
Anyway, the solution for DiagonalOperators seems straightforward to me. Just add the same block of code as for MatrixOperators. But how do you want to handle FunctionOperators?
Resolve the conflicts? |
@avik-pal can you review this one? |
When can |
Oh I see it is to disambiguate between no assumption provided from the user. This PR seems fine in that case |
Fixes many of the method ambiguities in this package.
Things I'm still unsure about:
First, for
defaultalg
there is dispatch forAbstractSciMLOperator
as well as dispatch forOperatorAssumptions{Nothing}
.AbstractSciMLOperator
dispatches based onA.A
.OperatorAssumptions{Nothing}
dispatches based onissquare(A)
.If both occur together, I don't know which order to apply them.
Currently, it first gets rid of the
Nothing
, but this meansissquare
has to be defined forOperators
.Second, there are remaining ambiguities regarding:
e.g. with:
I'm not sure how to resolve these, I'm assuming we want as little
do_factorization
as possible?Third, for some special matrix types, such as diagonal, there is dispatch to always use the same method, no matter the algorithm. But there are also fallback methods for most algorithms to work for general
A
. This design choice leads to tons of additional function definitions to resolve ambiguities between the two.