Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

This PR adds a missing Base.copy method for the WOperator type, which was causing MethodError when trying to copy these objects.

Problem

The WOperator type in OrdinaryDiffEqDifferentiation was missing a copy overload, leading to:

MethodError(copy, (OrdinaryDiffEqDifferentiation.WOperator{...}))

This issue was discovered during CI testing related to DataStructures v0.19 compatibility.

Solution

  • Implemented Base.copy(W::WOperator{IIP}) that properly handles the complex internal structure
  • The method reconstructs the operator using the public constructor while preserving internal computed state
  • Ensures independence between original and copied objects
  • Handles different scenarios for size inference when creating the temporary u vector

Implementation Details

The copy method:

  1. Infers the appropriate size for the u parameter needed by the constructor
  2. Creates a new WOperator using the public constructor with original fields
  3. Manually copies internal computed fields (_func_cache and _concrete_form)
  4. Returns a fully functional, independent copy

Testing

  • ✅ Basic copy functionality works correctly
  • ✅ Copied objects are independent (modifications don't affect each other)
  • ✅ Copied WOperator maintains full functionality
  • ✅ Integration tests with stiff ODE solvers (Rosenbrock23, KenCarp4) still pass
  • ✅ No regression in existing ODE solving capabilities

Test plan

  • Verify copy method works with different mass matrix types (UniformScaling, Matrix)
  • Confirm copied objects are independent
  • Test that copied WOperator can perform matrix operations
  • Verify no regression in ODE solver functionality
  • Run comprehensive tests with realistic scenarios

🤖 Generated with Claude Code

ChrisRackauckas and others added 2 commits September 2, 2025 20:36
- Implements missing Base.copy overload for WOperator type
- Handles complex internal structure by properly reconstructing the operator
- Maintains independence between original and copied objects
- Ensures copied WOperator retains all computed internal state
- Fixes MethodError when trying to copy WOperator instances

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Use internal constructor with new{...}(...) for direct field copying
- Place copy method inside struct definition to access new constructor
- Copy mutable fields (_func_cache, _concrete_form) to ensure independence
- Much cleaner and more efficient than previous approach

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit bb45545 into SciML:master Sep 3, 2025
149 of 195 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants