This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 26
convert to immutable for CUDA tests #151
Closed
Closed
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
865a0f8
convert to immutable for CUDA tests
m-bossart a791d82
fix dispatch
m-bossart 5afefcd
dispatch on Union{NonlinearProble, ImmutableNonlinearProblem}
m-bossart 783479a
fix formatting
m-bossart 2bb415f
convert in solve
m-bossart c4f5b38
Update test/gpu/cuda_tests.jl
ChrisRackauckas a0dc59b
changes from SciML
m-bossart 4cfd152
Merge branch 'main' of github.com:m-bossart/SimpleNonlinearSolve.jl
m-bossart 79cf885
address comments
m-bossart e8196a2
another union
m-bossart dc37c14
another union
m-bossart d7a1dec
StaticArraysCore compat
m-bossart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
struct ImmutableNonlinearProblem{uType, isinplace, P, F, K, PT} <: | ||
AbstractNonlinearProblem{uType, isinplace} | ||
f::F | ||
u0::uType | ||
p::P | ||
problem_type::PT | ||
kwargs::K | ||
@add_kwonly function ImmutableNonlinearProblem{iip}(f::AbstractNonlinearFunction{iip}, u0, | ||
p = NullParameters(), | ||
problem_type = StandardNonlinearProblem(); | ||
kwargs...) where {iip} | ||
if haskey(kwargs, :p) | ||
error("`p` specified as a keyword argument `p = $(kwargs[:p])` to `NonlinearProblem`. This is not supported.") | ||
end | ||
warn_paramtype(p) | ||
new{typeof(u0), iip, typeof(p), typeof(f), | ||
typeof(kwargs), typeof(problem_type)}(f, | ||
u0, | ||
p, | ||
problem_type, | ||
kwargs) | ||
end | ||
|
||
""" | ||
|
||
Define a steady state problem using the given function. | ||
`isinplace` optionally sets whether the function is inplace or not. | ||
This is determined automatically, but not inferred. | ||
""" | ||
function ImmutableNonlinearProblem{iip}(f, u0, p = NullParameters(); kwargs...) where {iip} | ||
ImmutableNonlinearProblem{iip}(NonlinearFunction{iip}(f), u0, p; kwargs...) | ||
end | ||
end | ||
|
||
""" | ||
|
||
Define a nonlinear problem using an instance of | ||
[`AbstractNonlinearFunction`](@ref AbstractNonlinearFunction). | ||
""" | ||
function ImmutableNonlinearProblem(f::AbstractNonlinearFunction, u0, p = NullParameters(); kwargs...) | ||
ImmutableNonlinearProblem{isinplace(f)}(f, u0, p; kwargs...) | ||
end | ||
|
||
function ImmutableNonlinearProblem(f, u0, p = NullParameters(); kwargs...) | ||
ImmutableNonlinearProblem(NonlinearFunction(f), u0, p; kwargs...) | ||
end | ||
|
||
""" | ||
|
||
Define a ImmutableNonlinearProblem problem from SteadyStateProblem | ||
""" | ||
function ImmutableNonlinearProblem(prob::AbstractNonlinearProblem) | ||
ImmutableNonlinearProblem{isinplace(prob)}(prob.f, prob.u0, prob.p) | ||
end | ||
|
||
staticarray_itize(x) = x | ||
staticarray_itize(x::Vector) = SVector{length(x)}(x) | ||
staticarray_itize(x::SizedVector) = SVector{length(x)}(x) | ||
staticarray_itize(x::Matrix) = SMatrix{size(x)...}(x) | ||
staticarray_itize(x::SizedMatrix) = SMatrix{size(x)...}(x) | ||
|
||
function Base.convert(::Type{ImmutableNonlinearProblem}, prob::T) where {T <: NonlinearProblem} | ||
ImmutableNonlinearProblem{isinplace(prob)}(prob.f, | ||
staticarray_itize(prob.u0), | ||
staticarray_itize(prob.p), | ||
prob.problem_type; | ||
prob.kwargs...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ end | |
|
||
__get_linesearch(::SimpleBroyden{LS}) where {LS} = Val(LS) | ||
|
||
function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleBroyden, args...; | ||
function SciMLBase.__solve(prob::Union{NonlinearProblem, ImmutableNonlinearProblem}, alg::SimpleBroyden, args...; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of these unions should be required. If done correctly, the top level should change to an ImmutableNonlinearProblem, and then they should all be that. |
||
abstol = nothing, reltol = nothing, maxiters = 1000, | ||
alias_u0 = false, termination_condition = nothing, kwargs...) | ||
x = __maybe_unaliased(prob.u0, alias_u0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 isn't going to be type stable, we shouldn't copy this part. Don't automatically make things static array, just immutable the problem.