Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit d63a253

Browse files
Merge pull request #481 from avik-pal/ap/vecjac
VecJacOperator
2 parents 98ff24f + b8fac52 commit d63a253

10 files changed

Lines changed: 464 additions & 183 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
continue-on-error: ${{ matrix.group == 'MOLFiniteDifference' }}
1213
strategy:
1314
matrix:
1415
group:

Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
1616
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1717
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
1818
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
19+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1920
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
2021
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2122
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
23+
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
2224
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2325
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
2426
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
@@ -37,6 +39,7 @@ NNlib = "0.6, 0.7"
3739
NonlinearSolve = "0.3.7"
3840
RuntimeGeneratedFunctions = "0.4, 0.5"
3941
SciMLBase = "1.11"
42+
SparseDiffTools = "1.17"
4043
StaticArrays = "0.10, 0.11, 0.12, 1.0"
4144
SymbolicUtils = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17"
4245
julia = "1"
@@ -49,6 +52,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4952
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
5053
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
5154
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
55+
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
5256

5357
[targets]
54-
test = ["FillArrays", "OrdinaryDiffEq", "Parameters", "Random", "SafeTestsets", "SpecialFunctions", "Test"]
58+
test = ["FillArrays", "OrdinaryDiffEq", "Parameters", "Random", "SafeTestsets", "SpecialFunctions", "Test", "Zygote"]

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ makedocs(
2222
"operators/operator_overview.md",
2323
"operators/derivative_operators.md",
2424
"operators/vector_calculus_operators.md",
25+
"operators/vector_jacobian_product.md",
2526
"operators/jacobian_vector_product.md",
2627
"operators/matrix_free_operators.md"
2728
],
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Vector-Jacobian Product Operators
2+
3+
```julia
4+
VecJacOperator{T}(f,u::AbstractArray,p=nothing,t::Union{Nothing,Number}=nothing;autodiff=true,ishermitian=false,opnorm=true)
5+
```
6+
7+
The `VecJacOperator` is a linear operator `J'*v` where `J` acts like `df/du`
8+
for some function `f(u,p,t)`. For in-place operations `mul!(w,J,v)`, `f`
9+
is an in-place function `f(du,u,p,t)`.
10+
11+
!!! note
12+
This operator is available when `Zygote` is imported.

src/DiffEqOperators.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import LinearAlgebra: mul!, ldiv!, lmul!, rmul!, axpy!, opnorm, factorize, I
77
import DiffEqBase: update_coefficients!, isconstant
88
using SciMLBase: AbstractDiffEqLinearOperator, AbstractDiffEqCompositeOperator, DiffEqScaledOperator
99
import SciMLBase: getops
10+
using SparseDiffTools
1011
using SparseArrays, ForwardDiff, BandedMatrices, NNlib, LazyArrays, BlockBandedMatrices, LoopVectorization
1112
using LazyBandedMatrices, ModelingToolkit
1213
using RuntimeGeneratedFunctions
14+
using Requires
1315
RuntimeGeneratedFunctions.init(@__MODULE__)
1416

1517
abstract type AbstractDiffEqAffineOperator{T} end
@@ -63,6 +65,14 @@ for T in [DiffEqScaledOperator, DiffEqOperatorCombination, DiffEqOperatorComposi
6365
(L::T)(du,u,p,t) = (update_coefficients!(L,u,p,t); mul!(du,L,u))
6466
end
6567

68+
function __init__()
69+
@require Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" begin
70+
export VecJacOperator
71+
72+
include("vecjac_operators.jl")
73+
end
74+
end
75+
6676
export MatrixFreeOperator
6777
export AnalyticalJacVecOperator, JacVecOperator, getops
6878
export AbstractDerivativeOperator, DerivativeOperator,

0 commit comments

Comments
 (0)