Skip to content

Improve inferrability#383

Merged
amontoison merged 1 commit into
JuliaSmoothOptimizers:mainfrom
timholy:teh/inferrability
Feb 11, 2026
Merged

Improve inferrability#383
amontoison merged 1 commit into
JuliaSmoothOptimizers:mainfrom
timholy:teh/inferrability

Conversation

@timholy

@timholy timholy commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

There is no way to make the S keyword argument of LinearOperator{T}
inferrable.

This moves S to the second position, so anyone who wishes to write
inferrable code can use LinearOperator{T, Vector{T}}(args...).

This appears to be non-breaking. A search of the JuliaSmoothOptimizers org for code with LinearOperator{ reveals only one source-code usage with more than one parameter: https://github.com/JuliaSmoothOptimizers/RipQP.jl/blob/6d3c074e72b4e94846a165bed5cc2b78bfdb3623/src/iterations/preconditioners/LDL.jl#L48
While the names there will be misleading, there appears to be no functional consequence.

@timholy

timholy commented Nov 19, 2025

Copy link
Copy Markdown
Contributor Author

Bump

@timholy

timholy commented Dec 8, 2025

Copy link
Copy Markdown
Contributor Author

Any chance someone can take a look at this? Or at least approve the workflow so that the tests can run? (EDIT: now I'm a bit confused about whether this repo actually uses the CI workflow.)

@timholy

timholy commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

Bump

@amontoison

amontoison commented Jan 23, 2026

Copy link
Copy Markdown
Member

@timholy I just discovered your PR.
I will fix the CI now or tomorrow.

@amontoison

Copy link
Copy Markdown
Member

@timholy Can you rebase your branch?
I should have fixed CI and breakage workflows.

There is no way to make the `S` keyword argument of `LinearOperator{T}`
inferrable.

This moves `S` to the second position, so anyone who wishes to write
inferrable code can use `LinearOperator{T, Vector{T}}(args...)`.

More inferrability & performance work
Copilot AI review requested due to automatic review settings February 11, 2026 20:42
@timholy

timholy commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

Sorry to be "out" for a bit. Rebased.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the LinearOperator type to improve type inferrability by moving the storage type parameter S from a keyword argument to the second type parameter position. This allows users to write LinearOperator{T, Vector{T}}(args...) for fully inferrable code, while maintaining backward compatibility through wrapper functions.

Changes:

  • Reordered type parameters in LinearOperator struct from {T, I, F, Ft, Fct, S} to {T, S, I, F, Ft, Fct}
  • Updated all constructor call sites to use positional type parameters instead of keyword arguments
  • Added backward compatibility wrappers for the old keyword argument syntax
  • Changed CompositeLinearOperator to accept S as a positional Type parameter

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/abstract.jl Core type definition changes - reordered type parameters and added backward compatibility wrappers for both LinearOperator and CompositeLinearOperator
src/special-operators.jl Updated all operator constructors (opEye, opOnes, opZeros, opDiagonal, opRestriction) to use new positional S parameter; includes unrelated view() optimization
src/operations.jl Updated CompositeLinearOperator calls in operator multiplication and addition
src/linalg.jl Updated constructors for opInverse, opCholesky, opHouseholder, and opHermitian to use new syntax
src/kron.jl Updated kron operator constructor to use new syntax
src/constructors.jl Updated LinearOperator constructor wrapper with explicit ::Type annotation for S parameter
src/cat.jl Updated hcat and vcat to pass S as positional argument to CompositeLinearOperator
ext/LinearOperatorsLDLFactorizationsExt.jl Updated opLDL constructors in extension to use new syntax

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/special-operators.jl

function mulRestrict!(res, I, v, α, β)
res .= v[I]
res .= view(v, I)

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change from v[I] to view(v, I) appears to be unrelated to the type parameter reordering that is the main focus of this PR. While using view may be a performance improvement to avoid allocating a copy, this change should either be removed from this PR (to keep the PR focused on type parameter reordering) or explicitly mentioned in the PR description. If this change is intentional, it should be verified that the behavioral semantics are preserved - view creates a reference to the original array rather than a copy, which could have implications if the result is modified.

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Feb 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.44%. Comparing base (32dbc5e) to head (b2fe73e).
⚠️ Report is 65 commits behind head on main.

Files with missing lines Patch % Lines
src/abstract.jl 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #383      +/-   ##
==========================================
+ Coverage   95.00%   95.44%   +0.44%     
==========================================
  Files          17       21       +4     
  Lines        1100     1186      +86     
==========================================
+ Hits         1045     1132      +87     
+ Misses         55       54       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amontoison amontoison merged commit 06be7db into JuliaSmoothOptimizers:main Feb 11, 2026
59 of 63 checks passed
@amontoison

Copy link
Copy Markdown
Member

Thanks @timholy !

@timholy timholy deleted the teh/inferrability branch February 12, 2026 14:57
timholy added a commit to timholy/LinearOperators.jl that referenced this pull request Feb 22, 2026
Add documentation for JuliaSmoothOptimizers#383

Also cleans up an unnecessarily large number of `LinearOperator(M)`
methods, preferring to consolidate them by supplying `M`-specific
defaults for the `symmetric` and `hermitian` keyword arguments.
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.

3 participants