Skip to content

Commit 581255a

Browse files
authored
let diffusion_matrix(::CoupledSDEs) export a matrix (#221)
* let diffusion_matrix export a matrix * increase path number
1 parent 8cc1b54 commit 581255a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystemsBase"
22
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
4-
version = "3.11.0"
4+
version = "3.11.1"
55

66
[deps]
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

ext/src/CoupledSDEs.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,11 @@ If this is not the case, returns `nothing`.
195195
Note: The diffusion matrix ``Σ`` is the square root of the noise covariance matrix ``Q`` (see
196196
[`covariance_matrix`](@ref)), defined via the Cholesky decomposition ``Q = Σ Σ^\\top``.
197197
"""
198-
function diffusion_matrix(ds::CoupledSDEs{IIP,D}) where {IIP,D}
198+
function diffusion_matrix(ds::CoupledSDEs{IIP,D})::AbstractMatrix where {IIP,D}
199199
if ds.noise_type[:invertible]
200200
diffusion = diffusion_function(ds)
201201
A = diffusion(zeros(D), current_parameters(ds), 0.0)
202+
A = A isa AbstractMatrix ? A : Diagonal(A)
202203
else
203204
@warn """
204205
The diffusion function of the `CoupledSDEs` cannot be expressed as a constant
@@ -218,7 +219,7 @@ If this is not the case, returns `nothing`.
218219
219220
See also [`diffusion_matrix`](@ref).
220221
"""
221-
function covariance_matrix(ds::CoupledSDEs)
222+
function covariance_matrix(ds::CoupledSDEs)::AbstractMatrix
222223
A = diffusion_matrix(ds)
223224
(A == nothing) ? nothing : A * A'
224225
end
@@ -241,10 +242,10 @@ Returns `g, noise_prototype`.
241242
"""
242243
function construct_diffusion_function(
243244
g, covariance, noise_prototype, noise_strength, D, IIP
244-
)
245+
)
245246
if isnothing(g) # diagonal additive noise
246247
cov = isnothing(covariance) ? LinearAlgebra.I(D) : covariance
247-
size(cov) != (D,D) &&
248+
size(cov) != (D, D) &&
248249
throw(ArgumentError("Covariance matrix must be of size $((D, D))"))
249250
A = sqrt(cov)
250251
if IIP
@@ -269,4 +270,4 @@ function construct_diffusion_function(
269270
end
270271
end
271272
return g, noise_prototype
272-
end
273+
end

test/stochastic.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ end
127127
A = sqrt(Γ)
128128
lorenz_oop = CoupledSDEs(lorenz_rule, u0, p0, covariance = Γ, diffeq=diffeq_cov)
129129
@test A diffusion_matrix(lorenz_oop)
130+
@test A isa AbstractMatrix
130131
@test Γ A * A'
131132
end
132133

@@ -153,4 +154,4 @@ end
153154
@test approx Γ atol=1e-1 broken = true
154155
# I think I understand something wromg here
155156
end
156-
end
157+
end

0 commit comments

Comments
 (0)