Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/codecov/codecov-…
Browse files Browse the repository at this point in the history
…action-4
  • Loading branch information
ChrisRackauckas authored Mar 1, 2024
2 parents 7a83f4d + 0cdfd8a commit d86305d
Show file tree
Hide file tree
Showing 22 changed files with 195 additions and 171 deletions.
3 changes: 2 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
style = "sciml"
format_markdown = true
format_markdown = true
format_docstrings = true
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ updates:
interval: "weekly"
ignore:
- dependency-name: "crate-ci/typos"
update-types: ["version-update:semver-patch"]
update-types: ["version-update:semver-patch", "version-update:semver-minor"]
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
- Core
version:
- '1'
- '1.6'
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
GROUP: ${{ matrix.package.group }}
strategy:
matrix:
julia-version: [1, 1.6]
julia-version: [1]
os: [ubuntu-latest]
package:
- {user: SciML, repo: SciMLBase.jl, group: InterfaceII}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/SpellCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- name: Checkout Actions Repository
uses: actions/checkout@v4
- name: Check spelling
uses: crate-ci/typos@v1.17.0
uses: crate-ci/typos@v1.18.1
12 changes: 5 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
name = "SciMLOperators"
uuid = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
authors = ["Vedant Puri <[email protected]>"]
version = "0.3.7"
version = "0.3.8"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"

[compat]
ArrayInterface = "7"
DocStringExtensions = "0.8, 0.9"
Lazy = "0.15"
LinearAlgebra = "1.6"
MacroTools = "0.5"
Setfield = "0.8, 1"
StaticArraysCore = "1"
SparseArrays = "1.6"
Tricks = "0.1.6"
julia = "1.6"
StaticArraysCore = "1"
julia = "1.10"
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pages = [
# "tutorials/nonlin.md",
# "tutorials/ode.md",
# "tutorials/lux.md",
],
]
]
55 changes: 23 additions & 32 deletions docs/src/tutorials/fftw.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ n = 256
L = 2π
dx = L / n
x = range(start=-L/2, stop=L/2-dx, length=n) |> Array
u = @. sin(5x)cos(7x);
x = range(start = -L / 2, stop = L / 2 - dx, length = n) |> Array
u = @. sin(5x)cos(7x);
du = @. 5cos(5x)cos(7x) - 7sin(5x)sin(7x);
k = rfftfreq(n, 2π*n/L) |> Array
k = rfftfreq(n, 2π * n / L) |> Array
m = length(k)
P = plan_rfft(x)
Expand All @@ -29,23 +29,19 @@ bwd(u, p, t) = P \ u
fwd(du, u, p, t) = mul!(du, P, u)
bwd(du, u, p, t) = ldiv!(du, P, u)
F = FunctionOperator(fwd, x, im*k;
T=ComplexF64,
op_adjoint = bwd,
op_inverse = bwd,
op_adjoint_inverse = fwd,
islinear=true,
)
F = FunctionOperator(fwd, x, im * k;
T = ComplexF64, op_adjoint = bwd,
op_inverse = bwd,
op_adjoint_inverse = fwd, islinear = true
)
ik = im * DiagonalOperator(k)
Dx = F \ ik * F
Dx = cache_operator(Dx, x)
@show ≈(Dx * u, du; atol=1e-8)
@show ≈(mul!(copy(u), Dx, u), du; atol=1e-8)
@show ≈(Dx * u, du; atol = 1e-8)
@show ≈(mul!(copy(u), Dx, u), du; atol = 1e-8)
```

## Explanation
Expand All @@ -60,14 +56,13 @@ FFT wrapper.
using SciMLOperators
using LinearAlgebra, FFTW
L = 2π
n = 256
L = 2π
n = 256
dx = L / n
x = range(start=-L/2, stop=L/2-dx, length=n) |> Array
x = range(start = -L / 2, stop = L / 2 - dx, length = n) |> Array
u = @. sin(5x)cos(7x);
u = @. sin(5x)cos(7x);
du = @. 5cos(5x)cos(7x) - 7sin(5x)sin(7x);
```

Now, we define the Fourier transform. Since our input is purely Real, we use the real
Expand All @@ -77,8 +72,8 @@ and `LinearAlgebra.mul!(xhat, transform, x)`. We also get `k`, the frequency mo
our finite grid, via the function `rfftfreq`.

```@example fft_explanation
k = rfftfreq(n, 2π*n/L) |> Array
m = length(k)
k = rfftfreq(n, 2π * n / L) |> Array
m = length(k)
P = plan_rfft(x)
```

Expand All @@ -93,15 +88,11 @@ bwd(u, p, t) = P \ u
fwd(du, u, p, t) = mul!(du, P, u)
bwd(du, u, p, t) = ldiv!(du, P, u)
F = FunctionOperator(fwd, x, im*k;
T=ComplexF64,
op_adjoint = bwd,
op_inverse = bwd,
op_adjoint_inverse = fwd,
islinear=true,
)
F = FunctionOperator(fwd, x, im * k;
T = ComplexF64, op_adjoint = bwd,
op_inverse = bwd,
op_adjoint_inverse = fwd, islinear = true
)
```

After wrapping the FFT with `FunctionOperator`, we are ready to compose it with other
Expand All @@ -115,6 +106,6 @@ Dx = F \ ik * F
Dx = cache_operator(Dx, x)
@show ≈(Dx * u, du; atol=1e-8)
@show ≈(mul!(copy(u), Dx, u), du; atol=1e-8)
@show ≈(Dx * u, du; atol = 1e-8)
@show ≈(mul!(copy(u), Dx, u), du; atol = 1e-8)
```
49 changes: 24 additions & 25 deletions src/SciMLOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ using LinearAlgebra
import SparseArrays
import StaticArraysCore
import ArrayInterface
import Tricks: static_hasmethod
import Lazy: @forward
import MacroTools: @forward
import Setfield: @set!

# overload
Expand Down Expand Up @@ -78,30 +77,30 @@ include("func.jl")
include("tensor.jl")

export
IdentityOperator,
NullOperator,
ScalarOperator,
MatrixOperator,
DiagonalOperator,
InvertibleOperator,
AffineOperator,
AddVector,
FunctionOperator,
TensorProductOperator
IdentityOperator,
NullOperator,
ScalarOperator,
MatrixOperator,
DiagonalOperator,
InvertibleOperator,
AffineOperator,
AddVector,
FunctionOperator,
TensorProductOperator

export update_coefficients!,
update_coefficients, isconstant,
iscached,
cache_operator, issquare,
islinear,
concretize,
isconvertible, has_adjoint,
has_expmv,
has_expmv!,
has_exp,
has_mul,
has_mul!,
has_ldiv,
has_ldiv!
update_coefficients, isconstant,
iscached,
cache_operator, issquare,
islinear,
concretize,
isconvertible, has_adjoint,
has_expmv,
has_expmv!,
has_exp,
has_mul,
has_mul!,
has_ldiv,
has_ldiv!

end # module
18 changes: 11 additions & 7 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ $TYPEDEF
"""
struct ScaledOperator{T,
λType,
LType,
LType
} <: AbstractSciMLOperator{T}
λ::λType
L::LType
Expand All @@ -194,7 +194,8 @@ end

# constructors
for T in SCALINGNUMBERTYPES[2:end]
@eval ScaledOperator::$T, L::AbstractSciMLOperator) = ScaledOperator(ScalarOperator(λ),
@eval ScaledOperator::$T, L::AbstractSciMLOperator) = ScaledOperator(
ScalarOperator(λ),
L)
end

Expand Down Expand Up @@ -312,7 +313,7 @@ Lazy operator addition
(A1 + A2 + A3...)u = A1*u + A2*u + A3*u ....
"""
struct AddedOperator{T,
O <: Tuple{Vararg{AbstractSciMLOperator}},
O <: Tuple{Vararg{AbstractSciMLOperator}}
} <: AbstractSciMLOperator{T}
ops::O

Expand Down Expand Up @@ -491,9 +492,11 @@ end
# constructors
for op in (:*, :)
@eval Base.$op(ops::AbstractSciMLOperator...) = reduce($op, ops)
@eval Base.$op(A::AbstractSciMLOperator, B::AbstractSciMLOperator) = ComposedOperator(A,
@eval Base.$op(A::AbstractSciMLOperator, B::AbstractSciMLOperator) = ComposedOperator(
A,
B)
@eval Base.$op(A::ComposedOperator, B::AbstractSciMLOperator) = ComposedOperator(A.ops...,
@eval Base.$op(A::ComposedOperator, B::AbstractSciMLOperator) = ComposedOperator(
A.ops...,
B)
@eval Base.$op(A::AbstractSciMLOperator, B::ComposedOperator) = ComposedOperator(A,
B.ops...)
Expand Down Expand Up @@ -553,7 +556,7 @@ Base.size(L::ComposedOperator) = (size(first(L.ops), 1), size(last(L.ops), 2))
for op in (:adjoint,
:transpose)
@eval Base.$op(L::ComposedOperator) = ComposedOperator($op.(reverse(L.ops))...;
cache = iscached(L) ? reverse(L.cache) : nothing,)
cache = iscached(L) ? reverse(L.cache) : nothing)
end
Base.conj(L::ComposedOperator) = ComposedOperator(conj.(L.ops); cache = L.cache)
function Base.resize!(L::ComposedOperator, n::Integer)
Expand Down Expand Up @@ -596,7 +599,8 @@ for fact in (:lu, :lu!,
:bunchkaufman, :bunchkaufman!,
:lq, :lq!,
:svd, :svd!)
@eval LinearAlgebra.$fact(L::ComposedOperator, args...) = prod(op -> $fact(op, args...),
@eval LinearAlgebra.$fact(L::ComposedOperator, args...) = prod(
op -> $fact(op, args...),
reverse(L.ops))
end

Expand Down
4 changes: 2 additions & 2 deletions src/batch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct BatchedDiagonalOperator{T, D, F, F!} <: AbstractSciMLOperator{T}
eltype(diag),
typeof(diag),
typeof(update_func),
typeof(update_func!),
typeof(update_func!)
}(diag,
update_func,
update_func!)
Expand Down Expand Up @@ -63,7 +63,7 @@ function Base.conj(L::BatchedDiagonalOperator) # TODO - test this thoroughly
DiagonalOperator(conj(L.diag);
update_func = update_func,
update_func! = update_func!,
accepted_kwargs = NoKwargFilter(),)
accepted_kwargs = NoKwargFilter())
end

function Base.convert(::Type{AbstractMatrix}, L::BatchedDiagonalOperator)
Expand Down
Loading

0 comments on commit d86305d

Please sign in to comment.