diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index 9c79359..959ad88 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -1,2 +1,3 @@ style = "sciml" -format_markdown = true \ No newline at end of file +format_markdown = true +format_docstrings = true \ No newline at end of file diff --git a/docs/make.jl b/docs/make.jl index 6e6ac01..73ab832 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -6,13 +6,13 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true) include("pages.jl") makedocs(sitename = "MultiScaleArrays.jl", - authors = "Chris Rackauckas", - modules = [MultiScaleArrays], - clean = true, doctest = false, linkcheck = true, - warnonly = [:missing_docs], - format = Documenter.HTML(assets = ["assets/favicon.ico"], - canonical = "https://docs.sciml.ai/MultiScaleArrays/stable/"), - pages = pages) + authors = "Chris Rackauckas", + modules = [MultiScaleArrays], + clean = true, doctest = false, linkcheck = true, + warnonly = [:missing_docs], + format = Documenter.HTML(assets = ["assets/favicon.ico"], + canonical = "https://docs.sciml.ai/MultiScaleArrays/stable/"), + pages = pages) deploydocs(repo = "github.com/SciML/MultiScaleArrays.jl.git"; - push_preview = true) + push_preview = true) diff --git a/docs/pages.jl b/docs/pages.jl index be257fd..ebe65d4 100644 --- a/docs/pages.jl +++ b/docs/pages.jl @@ -2,5 +2,5 @@ pages = [ "Home" => "index.md", - "multiscalearray.md", + "multiscalearray.md" ] diff --git a/docs/src/index.md b/docs/src/index.md index eb8f98c..b677714 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -165,4 +165,4 @@ file and the [project]($link_project) file. """) -``` \ No newline at end of file +``` diff --git a/src/MultiScaleArrays.jl b/src/MultiScaleArrays.jl index 102dced..518a01d 100644 --- a/src/MultiScaleArrays.jl +++ b/src/MultiScaleArrays.jl @@ -160,7 +160,7 @@ organ3 = Organ([1.2, 2.2, 3.2], :Shoot, OrganParams(true)) organ4 = Organ([4.2, 5.2, 6.2], :Root, OrganParams(1 // 3)) plant1 = construct(Plant, (deepcopy(organ1), deepcopy(organ2)), Float64[], PlantSettings(1)) plant2 = construct(Plant, (deepcopy(organ3), deepcopy(organ4)), Float64[], - PlantSettings(1.0)) + PlantSettings(1.0)) community = construct(Community, (deepcopy(plant1), deepcopy(plant2))) scenario = construct(Scenario, (deepcopy(community),)) ``` diff --git a/src/addition_deletion.jl b/src/addition_deletion.jl index 0b116c6..2d44042 100644 --- a/src/addition_deletion.jl +++ b/src/addition_deletion.jl @@ -18,7 +18,7 @@ function __add_node!(m::AbstractMultiScaleArray, node::AbstractMultiScaleArray, end function __add_node!(m::AbstractMultiScaleArray, node::AbstractMultiScaleArray, i, - I::Int...) + I::Int...) __add_node!(m.nodes[i], node, I...) __update_lengths(m, i, length(node)) end @@ -32,7 +32,7 @@ function add_node!(m::AbstractMultiScaleArrayHead, node::AbstractMultiScaleArray end function add_node!(m::AbstractMultiScaleArrayHead, node::AbstractMultiScaleArray, i, - I::Int...) + I::Int...) __add_node!(m, node, i, I...) end diff --git a/src/diffeq.jl b/src/diffeq.jl index 1f4ecc4..7fb3f6d 100644 --- a/src/diffeq.jl +++ b/src/diffeq.jl @@ -49,40 +49,40 @@ end reshape(m::AbstractMultiScaleArray, i::Int...) = m function remove_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, idxs, - node...) + node...) remove_node_non_user_cache!(integrator, integrator.cache, node...) end function remove_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, - cache::OrdinaryDiffEq.OrdinaryDiffEqCache, idxs, - node...) + cache::OrdinaryDiffEq.OrdinaryDiffEqCache, idxs, + node...) nothing end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, idxs, - x::AbstractArray) + x::AbstractArray) add_node_non_user_cache!(integrator, integrator.cache, x) end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, idxs, - x::AbstractArray, node...) + x::AbstractArray, node...) add_node_non_user_cache!(integrator, integrator.cache, x, node...) end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, - cache::OrdinaryDiffEq.OrdinaryDiffEqCache, - x::AbstractArray) + cache::OrdinaryDiffEq.OrdinaryDiffEqCache, + x::AbstractArray) nothing end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, - cache::OrdinaryDiffEq.OrdinaryDiffEqCache, - x::AbstractArray, node...) + cache::OrdinaryDiffEq.OrdinaryDiffEqCache, + x::AbstractArray, node...) nothing end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, - cache::OrdinaryDiffEq.RosenbrockMutableCache, - x::AbstractArray) + cache::OrdinaryDiffEq.RosenbrockMutableCache, + x::AbstractArray) i = length(integrator.u) cache.J = similar(cache.J, i, i) cache.W = similar(cache.W, i, i) @@ -92,8 +92,8 @@ function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, - cache::OrdinaryDiffEq.RosenbrockMutableCache, - x::AbstractArray, node...) + cache::OrdinaryDiffEq.RosenbrockMutableCache, + x::AbstractArray, node...) i = length(integrator.u) cache.J = similar(cache.J, i, i) cache.W = similar(cache.W, i, i) @@ -103,8 +103,8 @@ function add_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, end function remove_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrator, - cache::OrdinaryDiffEq.RosenbrockMutableCache, - node...) + cache::OrdinaryDiffEq.RosenbrockMutableCache, + node...) i = length(integrator.u) cache.J = similar(cache.J, i, i) cache.W = similar(cache.W, i, i) @@ -114,32 +114,32 @@ function remove_node_non_user_cache!(integrator::DiffEqBase.AbstractODEIntegrato end function add_node_jac_config!(cache, config::SparseDiffTools.ForwardColorJacCache, i, x, - node...) + node...) @assert cache.jac_config.colorvec isa UnitRange cache.jac_config = SparseDiffTools.ForwardColorJacCache(cache.uf, cache.uprev, - config.chunksize) + config.chunksize) nothing end function add_node_jac_config!(cache, config::SparseDiffTools.ForwardColorJacCache, i, x) @assert cache.jac_config.colorvec isa UnitRange cache.jac_config = SparseDiffTools.ForwardColorJacCache(cache.uf, cache.uprev, - config.chunksize) + config.chunksize) nothing end function remove_node_jac_config!(cache, config::SparseDiffTools.ForwardColorJacCache, i, x, - node...) + node...) @assert cache.jac_config.colorvec isa UnitRange cache.jac_config = SparseDiffTools.ForwardColorJacCache(cache.uf, cache.uprev, - config.chunksize) + config.chunksize) nothing end function remove_node_jac_config!(cache, config::SparseDiffTools.ForwardColorJacCache, i, x) @assert cache.jac_config.colorvec isa UnitRange cache.jac_config = SparseDiffTools.ForwardColorJacCache(cache.uf, cache.uprev, - config.chunksize) + config.chunksize) nothing end @@ -183,40 +183,40 @@ function remove_node_grad_config!(cache, grad_config::ForwardDiff.DerivativeConf end function remove_node_grad_config!(cache, grad_config::ForwardDiff.DerivativeConfig, i, x, - I...) + I...) cache.grad_config = ForwardDiff.DerivativeConfig(cache.tf, cache.du1, cache.uf.t) nothing end function add_node_grad_config!(cache, grad_config::AbstractArray, i, x) cache.grad_config = ForwardDiff.Dual{ - typeof(ForwardDiff.Tag(cache.tf, - eltype(cache.du1))) - }.(cache.du1, cache.du1) + typeof(ForwardDiff.Tag(cache.tf, + eltype(cache.du1))) + }.(cache.du1, cache.du1) nothing end function add_node_grad_config!(cache, grad_config::AbstractArray, i, x, I...) cache.grad_config = ForwardDiff.Dual{ - typeof(ForwardDiff.Tag(cache.tf, - eltype(cache.du1))) - }.(cache.du1, cache.du1) + typeof(ForwardDiff.Tag(cache.tf, + eltype(cache.du1))) + }.(cache.du1, cache.du1) nothing end function remove_node_grad_config!(cache, grad_config::AbstractArray, i, x) cache.grad_config = ForwardDiff.Dual{ - typeof(ForwardDiff.Tag(cache.tf, - eltype(cache.du1))) - }.(cache.du1, cache.du1) + typeof(ForwardDiff.Tag(cache.tf, + eltype(cache.du1))) + }.(cache.du1, cache.du1) nothing end function remove_node_grad_config!(cache, grad_config::AbstractArray, i, x, I...) cache.grad_config = ForwardDiff.Dual{ - typeof(ForwardDiff.Tag(cache.tf, - eltype(cache.du1))) - }.(cache.du1, cache.du1) + typeof(ForwardDiff.Tag(cache.tf, + eltype(cache.du1))) + }.(cache.du1, cache.du1) nothing end @@ -242,7 +242,7 @@ function remove_node_grad_config!(cache, grad_config::FiniteDiff.GradientCache, end function add_node_non_user_cache!(integrator::DiffEqBase.AbstractSDEIntegrator, idxs, x, - node...) + node...) #addat_non_user_cache!(integrator, idxs) if DiffEqBase.is_diagonal_noise(integrator.sol.prob) add_node_noise!(integrator, idxs, x, node...) @@ -263,7 +263,7 @@ function add_node_non_user_cache!(integrator::DiffEqBase.AbstractSDEIntegrator, end function remove_node_non_user_cache!(integrator::DiffEqBase.AbstractSDEIntegrator, idxs, - node...) + node...) #deleteat_non_user_cache!(integrator, idxs) if DiffEqBase.is_diagonal_noise(integrator.sol.prob) remove_node_noise!(integrator, node...) diff --git a/src/indexing.jl b/src/indexing.jl index e398ad0..2e8847a 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -91,9 +91,9 @@ end function getindices(m::AbstractMultiScaleArray, bot_idx, top_idx, i, I::Int...) getindices(m.nodes[i], - bot_idx + ((i > 1) ? m.end_idxs[i - 1] : 0), - top_idx + m.end_idxs[i] - length(m), - I...) + bot_idx + ((i > 1) ? m.end_idxs[i - 1] : 0), + top_idx + m.end_idxs[i] - length(m), + I...) end function getindices(m::AbstractMultiScaleArrayLeaf, bot_idx, top_idx, i::Int) diff --git a/src/math.jl b/src/math.jl index fdc7dea..b30b96d 100644 --- a/src/math.jl +++ b/src/math.jl @@ -41,7 +41,7 @@ end end @inline function Base.copyto!(dest::AbstractMultiScaleArrayLeaf, - bc::Broadcast.Broadcasted{<:AMSAStyle}) + bc::Broadcast.Broadcasted{<:AMSAStyle}) copyto!(dest.values, unpack(bc, nothing)) dest end diff --git a/src/print_human_readable.jl b/src/print_human_readable.jl index eab1ca8..7c9467f 100644 --- a/src/print_human_readable.jl +++ b/src/print_human_readable.jl @@ -11,7 +11,7 @@ function take_first_char(s::Union{String, SubString{String}}, N::Int64) end function toprint_AbstractMultiScaleArray!(toprint, X::AbstractMultiScaleArray, fields, - levelmax, n_char_per_name, level = 1) + levelmax, n_char_per_name, level = 1) if length(toprint) < level push!(toprint, Vector{String}()) end @@ -20,28 +20,30 @@ function toprint_AbstractMultiScaleArray!(toprint, X::AbstractMultiScaleArray, f for x in X.nodes if fieldname(typeof(x), 1) == :nodes push!(toprint[level], - "|" * - take_first_char(split(string(typeof(x)), "{")[1], n_char_per_name)) + "|" * + take_first_char(split(string(typeof(x)), "{")[1], n_char_per_name)) first_element = add_separator!(first_element, toprint, level) toprint_AbstractMultiScaleArray!(toprint, x, fields, levelmax, - n_char_per_name, level + 1) + n_char_per_name, level + 1) else if fields == nothing push!(toprint[level], - take_first_char(split(string(typeof(x)), "{")[1], - n_char_per_name)) + take_first_char(split(string(typeof(x)), "{")[1], + n_char_per_name)) first_element = add_separator!(first_element, toprint, level) else if !(x isa AbstractMultiScaleArrayLeaf) push!(toprint[level], - take_first_char(split(string(typeof(x)), "{")[1], - n_char_per_name)) + take_first_char(split(string(typeof(x)), "{")[1], + n_char_per_name)) first_element = add_separator!(first_element, toprint, level) else push!(toprint[level], - join([take_first_char(string(field), n_char_per_name) * ": " * - string(getfield(x, Symbol(field))) - for field in collect(fields)], ", ")) + join( + [take_first_char(string(field), n_char_per_name) * ": " * + string(getfield(x, Symbol(field))) + for field in collect(fields)], + ", ")) first_element = add_separator!(first_element, toprint, level) end end @@ -80,7 +82,7 @@ print_human_readable(embryo.nodes[1].nodes[1]; fields = [:values]) ``` """ function print_human_readable(X::AbstractMultiScaleArray; n_char_per_name = 6, - fields = nothing, levelmax = Inf, n_item_max_per_levels = Inf) # fields = nothing OR [field1,field2,...] + fields = nothing, levelmax = Inf, n_item_max_per_levels = Inf) # fields = nothing OR [field1,field2,...] # if X isa AbstractMultiScaleArrayLeaf # println(X) # else @@ -119,18 +121,18 @@ function print_human_readable(X::AbstractMultiScaleArray; n_char_per_name = 6, Move = findfirst("+ ", toprint[level])[1] To = findnext(" |", toprint[level], Move[end])[1] toprint[level] = join([ - toprint[level][1:(Move - 1)], - toprint[level][(Move + 1):To], - toprint[level][Move], - toprint[level][(To + 1):end], - ]) + toprint[level][1:(Move - 1)], + toprint[level][(Move + 1):To], + toprint[level][Move], + toprint[level][(To + 1):end] + ]) for level_ in 1:(level - 1) toprint[level_] = join([ - toprint[level_][1:(Move - 1)], - toprint[level_][(To + 1):(To + To - Move)], - toprint[level_][Move:To], - toprint[level_][(To + To - Move + 1):end], - ]) + toprint[level_][1:(Move - 1)], + toprint[level_][(To + 1):(To + To - Move)], + toprint[level_][Move:To], + toprint[level_][(To + To - Move + 1):end] + ]) end end end diff --git a/src/shape_construction.jl b/src/shape_construction.jl index 11464d6..21a7f24 100644 --- a/src/shape_construction.jl +++ b/src/shape_construction.jl @@ -23,7 +23,7 @@ end (sq = Meta.quot(s); :(deepcopy(getfield(m, $sq)))) for s in fieldnames(m)[4:end]] # 1:3 is nodes,values,end_idxs :(construct(parameterless_type(m), recursive_similar(m.nodes, T), similar(m.values, T), - $(assignments...))) + $(assignments...))) end Base.zero(A::AbstractMultiScaleArray) = fill!(similar(A), 0) diff --git a/test/additional_fields_test.jl b/test/additional_fields_test.jl index 126f44f..a7db1be 100644 --- a/test/additional_fields_test.jl +++ b/test/additional_fields_test.jl @@ -13,11 +13,11 @@ struct Host{T <: AbstractMultiScaleArray, B <: Float64} <: AbstractMultiScaleArr end host = construct(Host, - [ - CellGenotype([Float64(1)], - :aSymbiontGenotype), - CellGenotype([Float64(1)], - :aSymbiontGenotype)]) + [ + CellGenotype([Float64(1)], + :aSymbiontGenotype), + CellGenotype([Float64(1)], + :aSymbiontGenotype)]) evolve = function (du, u::Host, p, t) for i in 1:length(u) @@ -43,12 +43,12 @@ struct Host2{T <: AbstractMultiScaleArray, B <: Float64} <: AbstractMultiScaleAr end host2 = construct(Host2, - [ - CellGenotype([Float64(1)], - :aSymbiontGenotype), - CellGenotype([Float64(1)], - :aSymbiontGenotype)], Float64[], - :my_cell_type) + [ + CellGenotype([Float64(1)], + :aSymbiontGenotype), + CellGenotype([Float64(1)], + :aSymbiontGenotype)], Float64[], + :my_cell_type) evolve = function (du, u::Host2, p, t) for i in 1:length(u) diff --git a/test/indexing_and_creation_tests.jl b/test/indexing_and_creation_tests.jl index 659aef6..9313d85 100644 --- a/test/indexing_and_creation_tests.jl +++ b/test/indexing_and_creation_tests.jl @@ -177,12 +177,12 @@ sol1 = solve(prob, Tsit5()) Random.seed!(100) prob = SDEProblem(f, g, em, (0.0, 1000.0)) @time sol1 = solve(prob, SRIW1(), progress = false, abstol = 1e-2, reltol = 1e-2, - save_everystep = false) + save_everystep = false) Random.seed!(100) prob = SDEProblem(f, g, em[:], (0.0, 1000.0)) @time sol2 = solve(prob, SRIW1(), progress = false, abstol = 1e-2, reltol = 1e-2, - save_everystep = false) + save_everystep = false) sol1.t == sol2.t function test_loop(a) diff --git a/test/runtests.jl b/test/runtests.jl index d23a6ea..c09c944 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,12 +1,11 @@ using MultiScaleArrays, OrdinaryDiffEq, DiffEqBase, StochasticDiffEq, SafeTestsets using Test -@time @testset "Tuple Nodes" begin include("tuple_nodes.jl") end -@time @testset "Bisect Search Tests" begin include("bisect_search_tests.jl") end -@time @testset "Indexing and Creation Tests" begin include("indexing_and_creation_tests.jl") end -@time @testset "Values Indexing" begin include("values_indexing.jl") end -@time @testset "Get Indices Tests" begin include("get_indices.jl") end -@time @testset "Additional Fields Test" begin include("additional_fields_test.jl") end -@time @testset "Dynamic DiffEq Tests" begin include("dynamic_diffeq.jl") end -@time @testset "Single Layer DiffEq Tests" begin include("single_layer_diffeq.jl") end -@time @safetestset "New Nodes Tests" begin include("new_nodes.jl") end +@time @testset "Bisect Search Tests" include("bisect_search_tests.jl") +@time @testset "Indexing and Creation Tests" include("indexing_and_creation_tests.jl") +@time @testset "Values Indexing" include("values_indexing.jl") +@time @testset "Get Indices Tests" include("get_indices.jl") +@time @testset "Additional Fields Test" include("additional_fields_test.jl") +@time @testset "Dynamic DiffEq Tests" include("dynamic_diffeq.jl") +@time @testset "Single Layer DiffEq Tests" include("single_layer_diffeq.jl") +@time @safetestset "New Nodes Tests" include("new_nodes.jl") diff --git a/test/tuple_nodes.jl b/test/tuple_nodes.jl index c7d96a1..136259c 100644 --- a/test/tuple_nodes.jl +++ b/test/tuple_nodes.jl @@ -40,7 +40,7 @@ organ3 = Organ([1.2, 2.2, 3.2], :Shoot, OrganParams(true)) organ4 = Organ([4.2, 5.2, 6.2], :Root, OrganParams(1 // 3)) plant1 = construct(Plant, (deepcopy(organ1), deepcopy(organ2)), Float64[], PlantSettings(1)) plant2 = construct(Plant, (deepcopy(organ3), deepcopy(organ4)), Float64[], - PlantSettings(1.0)) + PlantSettings(1.0)) community = construct(Community, (deepcopy(plant1), deepcopy(plant2))) scenario = construct(Scenario, (deepcopy(community),))