Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .JuliaFormatter.toml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: format-check

on:
push:
branches:
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:

jobs:
runic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fredrikekre/runic-action@v1
with:
version: '1'
40 changes: 22 additions & 18 deletions src/MATLABDiffEq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@ _is_matlab_compatible_eltype(::Type) = false
function _check_matlab_compatible(u0, tspan)
T = eltype(u0)
if !_is_matlab_compatible_eltype(T)
throw(ArgumentError(
"MATLABDiffEq.jl requires Float64-compatible element types. " *
"Got eltype(u0) = $T. MATLAB does not support arbitrary precision " *
"(BigFloat) or GPU arrays (JLArrays, CuArrays). Please convert your " *
"initial conditions to Float64: u0 = Float64.(u0)"
))
throw(
ArgumentError(
"MATLABDiffEq.jl requires Float64-compatible element types. " *
"Got eltype(u0) = $T. MATLAB does not support arbitrary precision " *
"(BigFloat) or GPU arrays (JLArrays, CuArrays). Please convert your " *
"initial conditions to Float64: u0 = Float64.(u0)"
)
)
end
tT = eltype(tspan)
if !_is_matlab_compatible_eltype(tT)
throw(ArgumentError(
"MATLABDiffEq.jl requires Float64-compatible time span types. " *
"Got eltype(tspan) = $tT. MATLAB does not support arbitrary precision " *
"(BigFloat). Please use Float64 for tspan: tspan = Float64.(tspan)"
))
throw(
ArgumentError(
"MATLABDiffEq.jl requires Float64-compatible time span types. " *
"Got eltype(tspan) = $tT. MATLAB does not support arbitrary precision " *
"(BigFloat). Please use Float64 for tspan: tspan = Float64.(tspan)"
)
)
end
# Check that the array type itself is a standard Julia array
if !(u0 isa Array || u0 isa Number)
@warn "MATLABDiffEq.jl works best with standard Julia Arrays. " *
"Got $(typeof(u0)). The array will be converted to a standard Array " *
"before being sent to MATLAB."
"Got $(typeof(u0)). The array will be converted to a standard Array " *
"before being sent to MATLAB."
end
return nothing
end
Expand Down Expand Up @@ -63,11 +67,11 @@ function DiffEqBase.__solve(
ks = [];
saveat = eltype(tupType)[],
timeseries_errors = true,
reltol = 1e-3,
abstol = 1e-6,
reltol = 1.0e-3,
abstol = 1.0e-6,
callback = nothing,
kwargs...
) where {uType, tupType, isinplace, AlgType <: MATLABAlgorithm}
) where {uType, tupType, isinplace, AlgType <: MATLABAlgorithm}
# Validate that input types are MATLAB-compatible
_check_matlab_compatible(prob.u0, prob.tspan)

Expand Down Expand Up @@ -144,7 +148,7 @@ function DiffEqBase.__solve(

stats = buildDEStats(solstats)

DiffEqBase.build_solution(
return DiffEqBase.build_solution(
prob,
alg,
ts,
Expand All @@ -170,7 +174,7 @@ function buildDEStats(solverstats::Dict{String, <:Any})::DiffEqBase.Stats
destats.nsolve = Int(get(solverstats, "nsolves", 0))
destats.njacs = Int(get(solverstats, "npds", 0))
destats.nw = Int(get(solverstats, "ndecomps", 0))
destats
return destats
end

@setup_workload begin
Expand Down
18 changes: 10 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ sol = solve(prob, MATLABDiffEq.ode45())
function lorenz(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
return du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 100.0)
prob = ODEProblem(lorenz, u0, tspan)
sol = solve(prob, MATLABDiffEq.ode45())

algs = [MATLABDiffEq.ode23
MATLABDiffEq.ode45
MATLABDiffEq.ode113
MATLABDiffEq.ode23s
MATLABDiffEq.ode23t
MATLABDiffEq.ode23tb
MATLABDiffEq.ode15s]
algs = [
MATLABDiffEq.ode23
MATLABDiffEq.ode45
MATLABDiffEq.ode113
MATLABDiffEq.ode23s
MATLABDiffEq.ode23t
MATLABDiffEq.ode23tb
MATLABDiffEq.ode15s
]

for alg in algs
sol = solve(prob, alg())
Expand Down
Loading