-
-
Notifications
You must be signed in to change notification settings - Fork 72
feat: Implement recursivecopy
for structs
#468
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
base: master
Are you sure you want to change the base?
Conversation
Only supports mutable structs, and has to have extra logic to dispatch on basic types...
I tried to swap this into here but that currently fails... |
- Test recursivecopy with ODE solutions and ArrayPartition integration - Verify struct-based parameter copying in differential equations - Ensure deep independence of copied solution objects 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Include Function in the list of basic Julia types - Add RecursiveArrayTools dependency to downstream tests - Include struct copy tests in main test suite - Add ODE solution copy tests to downstream test suite 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add type equality check for copied solution - Simplify independence test to focus on solution data - Update comments to clarify test objectives - Remove overly complex parameter independence tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
What's the failure? |
# Tuple, etc.) are technically structs but should use copy() or return as-is. | ||
if Base.isstructtype(T) && !_is_basic_julia_type(T) | ||
if Base.ismutabletype(T) | ||
error("recursivecopy for mutable structs is not currently implemented. Use deepcopy instead.") |
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's the issue there?
I think at this point it should probably just be a library. I can't think of a good name, mediumcopy? 😅 specializedcopy? |
I'm also becoming increasingly less certain that it's sensible to try to write a version that works for arbitrary struct compositions. Perhaps it would make more sense to specialize on a few types that we know may shows up in sciml solution structs. |
What are you running into? What we really need is SciMLProblem and SciMLSolutions to be supported. |
What about EDIT: Yes seems to be about 4x slower. using LinearSolve, Serialization, BenchmarkTools
prob = LinearProblem(rand(1000, 1000), rand(1000))
cache = init(prob, LinearSolve.GenericLUFactorization())
mycopy(s) = let buf = IOBuffer()
serialize(buf, s)
seekstart(buf)
deserialize(buf)
end
@btime mycopy(cache) # 1.4ms
@btime deepcopy(cache) # 360μs Also, it doesn't seem to |
Only supports mutable structs, and has to have extra logic to dispatch on basic types...
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
This problem came up as part of SciML/LinearSolve.jl#648 and it a first draft of solving the issue. However, the current handling of the Julia special types is perhaps not perfect yet. Also the code path for normal types is now a bit more difficult to follow, and we explicitly don't allow copying mutable structs. Was that allowed before? In that case we can also just call
deepcopy
if it is mutable.