Skip to content

Commit a9c91a2

Browse files
Merge pull request #245 from longemen3000/patch-1
migrate to Accessors, move StaticArraysCore to ext
2 parents 42b58b7 + 1fed735 commit a9c91a2

File tree

9 files changed

+52
-41
lines changed

9 files changed

+52
-41
lines changed

Project.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
88
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
11-
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
12-
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
11+
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
1312

1413
[weakdeps]
1514
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
15+
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
16+
17+
[extensions]
18+
SciMLOperatorsSparseArraysExt = "SparseArrays"
19+
SciMLOperatorsStaticArraysCoreExt = "StaticArraysCore"
1620

1721
[compat]
22+
Accessors = "0.1"
1823
ArrayInterface = "7"
1924
DocStringExtensions = "0.8, 0.9"
2025
LinearAlgebra = "1.6"
2126
MacroTools = "0.5"
22-
Setfield = "0.8, 1"
2327
SparseArrays = "1.6"
2428
StaticArraysCore = "1"
2529
julia = "1.10"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module SciMLOperatorsStaticArraysCoreExt
2+
3+
import SciMLOperators
4+
import StaticArraysCore
5+
6+
function Base.copyto!(L::SciMLOperators.MatrixOperator,
7+
rhs::Base.Broadcast.Broadcasted{<:StaticArraysCore.StaticArrayStyle})
8+
(copyto!(L.A, rhs); L)
9+
end
10+
11+
end #module

src/SciMLOperators.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ using DocStringExtensions
77

88
using LinearAlgebra
99

10-
import StaticArraysCore
1110
import ArrayInterface
1211
import MacroTools: @forward
13-
import Setfield: @set!
12+
import Accessors: @reset
1413

1514
# overload
1615
import Base: show

src/basic.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ Base.resize!(L::ScaledOperator, n::Integer) = (resize!(L.L, n); L)
240240
LinearAlgebra.opnorm(L::ScaledOperator, p::Real = 2) = abs(L.λ) * opnorm(L.L, p)
241241

242242
function update_coefficients(L::ScaledOperator, u, p, t)
243-
@set! L.L = update_coefficients(L.L, u, p, t)
244-
@set! L.λ = update_coefficients(L.λ, u, p, t)
243+
@reset L.L = update_coefficients(L.L, u, p, t)
244+
@reset L.λ = update_coefficients(L.λ, u, p, t)
245245

246246
L
247247
end
@@ -256,8 +256,8 @@ has_ldiv(L::ScaledOperator) = has_ldiv(L.L) & !iszero(L.λ)
256256
has_ldiv!(L::ScaledOperator) = has_ldiv!(L.L) & !iszero(L.λ)
257257

258258
function cache_internals(L::ScaledOperator, u::AbstractVecOrMat)
259-
@set! L.L = cache_operator(L.L, u)
260-
@set! L.λ = cache_operator(L.λ, u)
259+
@reset L.L = cache_operator(L.L, u)
260+
@reset L.λ = cache_operator(L.λ, u)
261261
L
262262
end
263263

@@ -411,7 +411,7 @@ function update_coefficients(L::AddedOperator, u, p, t)
411411
ops = (ops..., update_coefficients(op, u, p, t))
412412
end
413413

414-
@set! L.ops = ops
414+
@reset L.ops = ops
415415
end
416416

417417
getops(L::AddedOperator) = L.ops
@@ -421,7 +421,7 @@ has_adjoint(L::AddedOperator) = all(has_adjoint, L.ops)
421421

422422
function cache_internals(L::AddedOperator, u::AbstractVecOrMat)
423423
for i in 1:length(L.ops)
424-
@set! L.ops[i] = cache_operator(L.ops[i], u)
424+
@reset L.ops[i] = cache_operator(L.ops[i], u)
425425
end
426426
L
427427
end
@@ -576,7 +576,7 @@ function update_coefficients(L::ComposedOperator, u, p, t)
576576
ops = (ops..., update_coefficients(op, u, p, t))
577577
end
578578

579-
@set! L.ops = ops
579+
@reset L.ops = ops
580580
end
581581

582582
getops(L::ComposedOperator) = L.ops
@@ -646,7 +646,7 @@ function cache_self(L::ComposedOperator, u::AbstractVecOrMat)
646646
cache = (similar(u, T, sz), cache...)
647647
end
648648

649-
@set! L.cache = cache
649+
@reset L.cache = cache
650650
L
651651
end
652652

@@ -660,7 +660,7 @@ function cache_internals(L::ComposedOperator, u::AbstractVecOrMat)
660660
ops = (cache_operator(L.ops[i], L.cache[i]), ops...)
661661
end
662662

663-
@set! L.ops = ops
663+
@reset L.ops = ops
664664
end
665665

666666
function LinearAlgebra.mul!(v::AbstractVecOrMat, L::ComposedOperator, u::AbstractVecOrMat)
@@ -757,7 +757,7 @@ function Base.resize!(L::InvertedOperator, n::Integer)
757757
end
758758

759759
function update_coefficients(L::InvertedOperator, u, p, t)
760-
@set! L.L = update_coefficients(L.L, u, p, t)
760+
@reset L.L = update_coefficients(L.L, u, p, t)
761761

762762
L
763763
end
@@ -787,12 +787,12 @@ Base.:\(L::InvertedOperator, u::AbstractVecOrMat) = L.L * u
787787

788788
function cache_self(L::InvertedOperator, u::AbstractVecOrMat)
789789
cache = zero(u)
790-
@set! L.cache = cache
790+
@reset L.cache = cache
791791
L
792792
end
793793

794794
function cache_internals(L::InvertedOperator, u::AbstractVecOrMat)
795-
@set! L.L = cache_operator(L.L, u)
795+
@reset L.L = cache_operator(L.L, u)
796796
L
797797
end
798798

src/batch.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ end
8383
LinearAlgebra.isposdef(L::BatchedDiagonalOperator) = isposdef(Diagonal(vec(L.diag)))
8484

8585
function update_coefficients(L::BatchedDiagonalOperator, u, p, t; kwargs...)
86-
@set! L.diag = L.update_func(L.diag, u, p, t; kwargs...)
86+
@reset L.diag = L.update_func(L.diag, u, p, t; kwargs...)
8787
end
8888

8989
function update_coefficients!(L::BatchedDiagonalOperator, u, p, t; kwargs...)

src/left.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ for (op, LType, VType) in ((:adjoint, :AdjointOperator, :AbstractAdjointVecOrMat
121121
has_ldiv!)
122122

123123
@eval function cache_internals(L::$LType, u::AbstractVecOrMat)
124-
@set! L.L = cache_operator(L.L, reshape(u, size(L, 1)))
124+
@reset L.L = cache_operator(L.L, reshape(u, size(L, 1)))
125125
L
126126
end
127127

src/matrix.jl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function isconstant(L::MatrixOperator)
156156
end
157157

158158
function update_coefficients(L::MatrixOperator, u, p, t; kwargs...)
159-
@set! L.A = L.update_func(L.A, u, p, t; kwargs...)
159+
@reset L.A = L.update_func(L.A, u, p, t; kwargs...)
160160
end
161161

162162
function update_coefficients!(L::MatrixOperator, u, p, t; kwargs...)
@@ -181,10 +181,7 @@ function Base.IndexStyle(::Type{<:MatrixOperator{T, AType}}) where {T, AType}
181181
Base.IndexStyle(AType)
182182
end
183183
Base.copyto!(L::MatrixOperator, rhs) = (copyto!(L.A, rhs); L)
184-
function Base.copyto!(L::MatrixOperator,
185-
rhs::Base.Broadcast.Broadcasted{<:StaticArraysCore.StaticArrayStyle})
186-
(copyto!(L.A, rhs); L)
187-
end
184+
188185
Base.Broadcast.broadcastable(L::MatrixOperator) = L
189186
Base.ndims(::Type{<:MatrixOperator{T, AType}}) where {T, AType} = ndims(AType)
190187
ArrayInterface.issingular(L::MatrixOperator) = ArrayInterface.issingular(L.A)
@@ -337,8 +334,8 @@ LinearAlgebra.opnorm(L::InvertibleOperator{T}, p = 2) where {T} = one(T) / opnor
337334
LinearAlgebra.issuccess(L::InvertibleOperator) = issuccess(L.F)
338335

339336
function update_coefficients(L::InvertibleOperator, u, p, t)
340-
@set! L.L = update_coefficients(L.L, u, p, t)
341-
@set! L.F = update_coefficients(L.F, u, p, t)
337+
@reset L.L = update_coefficients(L.L, u, p, t)
338+
@reset L.F = update_coefficients(L.F, u, p, t)
342339
L
343340
end
344341

@@ -362,8 +359,8 @@ has_ldiv(L::InvertibleOperator) = has_mul(L.F)
362359
has_ldiv!(L::InvertibleOperator) = has_ldiv!(L.F)
363360

364361
function cache_internals(L::InvertibleOperator, u::AbstractVecOrMat)
365-
@set! L.L = cache_operator(L.L, u)
366-
@set! L.F = cache_operator(L.F, u)
362+
@reset L.L = cache_operator(L.L, u)
363+
@reset L.F = cache_operator(L.F, u)
367364

368365
L
369366
end
@@ -515,9 +512,9 @@ function AddVector(B, b::AbstractVecOrMat;
515512
end
516513

517514
function update_coefficients(L::AffineOperator, u, p, t; kwargs...)
518-
@set! L.A = update_coefficients(L.A, u, p, t; kwargs...)
519-
@set! L.B = update_coefficients(L.B, u, p, t; kwargs...)
520-
@set! L.b = L.update_func(L.b, u, p, t; kwargs...)
515+
@reset L.A = update_coefficients(L.A, u, p, t; kwargs...)
516+
@reset L.B = update_coefficients(L.B, u, p, t; kwargs...)
517+
@reset L.b = L.update_func(L.b, u, p, t; kwargs...)
521518
end
522519

523520
function update_coefficients!(L::AffineOperator, u, p, t; kwargs...)
@@ -577,8 +574,8 @@ has_ldiv(L::AffineOperator) = has_ldiv(L.A)
577574
has_ldiv!(L::AffineOperator) = has_ldiv!(L.A)
578575

579576
function cache_internals(L::AffineOperator, u::AbstractVecOrMat)
580-
@set! L.A = cache_operator(L.A, u)
581-
@set! L.B = cache_operator(L.B, L.b)
577+
@reset L.A = cache_operator(L.A, u)
578+
@reset L.B = cache_operator(L.B, L.b)
582579
L
583580
end
584581

src/scalar.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function update_coefficients!(L::ScalarOperator, u, p, t; kwargs...)
194194
end
195195

196196
function update_coefficients(L::ScalarOperator, u, p, t; kwargs...)
197-
@set! L.val = L.update_func(L.val, u, p, t; kwargs...)
197+
@reset L.val = L.update_func(L.val, u, p, t; kwargs...)
198198
end
199199

200200
"""
@@ -262,7 +262,7 @@ function update_coefficients(L::AddedScalarOperator, u, p, t)
262262
ops = (ops..., update_coefficients(op, u, p, t))
263263
end
264264

265-
@set! L.ops = ops
265+
@reset L.ops = ops
266266
end
267267

268268
getops::AddedScalarOperator) = α.ops
@@ -336,7 +336,7 @@ function update_coefficients(L::ComposedScalarOperator, u, p, t)
336336
ops = (ops..., update_coefficients(op, u, p, t))
337337
end
338338

339-
@set! L.ops = ops
339+
@reset L.ops = ops
340340
end
341341

342342
getops::ComposedScalarOperator) = α.ops
@@ -393,7 +393,7 @@ end
393393
Base.conj(L::InvertedScalarOperator) = InvertedScalarOperator(conj(L.λ))
394394

395395
function update_coefficients(L::InvertedScalarOperator, u, p, t)
396-
@set! L.λ = update_coefficients(L.λ, u, p, t)
396+
@reset L.λ = update_coefficients(L.λ, u, p, t)
397397
L
398398
end
399399

src/tensor.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function update_coefficients(L::TensorProductOperator, u, p, t)
110110
ops = (ops..., update_coefficients(op, u, p, t))
111111
end
112112

113-
@set! L.ops = ops
113+
@reset L.ops = ops
114114
end
115115

116116
getops(L::TensorProductOperator) = L.ops
@@ -182,7 +182,7 @@ function cache_self(L::TensorProductOperator, u::AbstractVecOrMat)
182182
c7 = lmul!(false, similar(u, (no, ni * k))) # c7 = outer \ c6
183183
end
184184

185-
@set! L.cache = (c1, c2, c3, c4, c5, c6, c7)
185+
@reset L.cache = (c1, c2, c3, c4, c5, c6, c7)
186186
L
187187
end
188188

@@ -200,8 +200,8 @@ function cache_internals(L::TensorProductOperator, u::AbstractVecOrMat)
200200
uinner = reshape(u, (ni, no * k))
201201
uouter = reshape(L.cache[2], (no, mi * k))
202202

203-
@set! L.ops[2] = cache_operator(inner, uinner)
204-
@set! L.ops[1] = cache_operator(outer, uouter)
203+
@reset L.ops[2] = cache_operator(inner, uinner)
204+
@reset L.ops[1] = cache_operator(outer, uouter)
205205
L
206206
end
207207

0 commit comments

Comments
 (0)