From 8ace8fefa4f14f78fa9dd9e43393809f27d0bf8e Mon Sep 17 00:00:00 2001 From: Jesse Chan <1156048+jlchan@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:24:06 -0600 Subject: [PATCH] Bump Julia and RecursiveArrayTools compat, remove NamedArrayPartition (#159) * remove NamedArrayPartition files d * bump compat * add sparsearrays compat entry tests seem to be failing on CI without it? * bump Julia compat * bump julia CI version * set lower compat bound for SummationByPartsOperators * bump doc Julia version * reexporting NamedArrayPartition --- .github/workflows/ci.yml | 2 +- .github/workflows/documentation.yml | 2 +- Project.toml | 7 +- src/StartUpDG.jl | 5 +- src/named_array_partition.jl | 117 ---------------------------- test/Project.toml | 2 +- test/named_array_partition_tests.jl | 34 -------- test/runtests.jl | 5 +- 8 files changed, 10 insertions(+), 164 deletions(-) delete mode 100644 src/named_array_partition.jl delete mode 100644 test/named_array_partition_tests.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4690dd6e..0ce96dc6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: version: - - '1.7' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'. + - '1.10' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'. - '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia. - 'nightly' os: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 8f552204..56242b26 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: - version: '1.7' + version: '1.10' - name: Install dependencies run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' - name: Build and deploy diff --git a/Project.toml b/Project.toml index 8030717b..37412a69 100644 --- a/Project.toml +++ b/Project.toml @@ -37,16 +37,17 @@ Kronecker = "0.5" NodesAndModes = "1" PathIntersections = "0.1" RecipesBase = "1" -RecursiveArrayTools = "2" +RecursiveArrayTools = "3.4" Reexport = "1" Requires = "1" Setfield = "1" SimpleUnPack = "1" +SparseArrays = "1" StaticArrays = "1" -SummationByPartsOperators = "0.5" +SummationByPartsOperators = "0.5.52" Triangulate = "2" WriteVTK = "1" -julia = "1.7" +julia = "1.10" [extras] SummationByPartsOperators = "9f78cca6-572e-554e-b819-917d2f1cf240" diff --git a/src/StartUpDG.jl b/src/StartUpDG.jl index 41b098f0..817755e3 100644 --- a/src/StartUpDG.jl +++ b/src/StartUpDG.jl @@ -14,6 +14,7 @@ using PathIntersections: PathIntersections @reexport using PathIntersections: PresetGeometries using Printf: @sprintf using RecipesBase: RecipesBase +@reexport using RecursiveArrayTools: NamedArrayPartition using StaticArrays: SVector, SMatrix using Setfield: setproperties, @set # for "modifying" structs (setproperties) @reexport using SimpleUnPack: @unpack @@ -55,10 +56,6 @@ export make_periodic include("boundary_utils.jl") export boundary_face_centroids, tag_boundary_faces, tag_boundary_nodes -# helper array type for cut cell and hybrid meshes -include("named_array_partition.jl") -export NamedArrayPartition - include("hybrid_meshes.jl") export num_faces, num_vertices, HybridMeshExample diff --git a/src/named_array_partition.jl b/src/named_array_partition.jl deleted file mode 100644 index 32e4d947..00000000 --- a/src/named_array_partition.jl +++ /dev/null @@ -1,117 +0,0 @@ - -using RecursiveArrayTools: RecursiveArrayTools, ArrayPartition, npartitions, unpack - -""" - NamedArrayPartition(; kwargs...) - NamedArrayPartition(x::NamedTuple) - -Similar to an `ArrayPartition` but the individual arrays can be accessed via the -constructor-specified names. However, unlike `ArrayPartition`, each individual array -must have the same element type. -""" -struct NamedArrayPartition{T, A<:ArrayPartition{T}, NT<:NamedTuple} <: AbstractVector{T} - array_partition::A - names_to_indices::NT -end -NamedArrayPartition(; kwargs...) = NamedArrayPartition(NamedTuple(kwargs)) -function NamedArrayPartition(x::NamedTuple) - names_to_indices = NamedTuple(Pair(symbol, index) for (index, symbol) in enumerate(keys(x))) - - # enforce homogeneity of eltypes - @assert all(eltype.(values(x)) .== eltype(first(x))) - T = eltype(first(x)) - S = typeof(values(x)) - return NamedArrayPartition(ArrayPartition{T, S}(values(x)), names_to_indices) -end - -# note that overloading `getproperty` means we cannot access `NamedArrayPartition` -# fields except through `getfield` and accessor functions. -ArrayPartition(x::NamedArrayPartition) = getfield(x, :array_partition) - -Base.Array(x::NamedArrayPartition) = Array(ArrayPartition(x)) - -Base.zero(x::NamedArrayPartition{T, S, TN}) where {T, S, TN} = - NamedArrayPartition{T, S, TN}(zero(ArrayPartition(x)), getfield(x, :names_to_indices)) -Base.zero(A::NamedArrayPartition, dims::NTuple{N, Int}) where {N} = zero(A) # ignore dims since named array partitions are vectors - - -Base.propertynames(x::NamedArrayPartition) = propertynames(getfield(x, :names_to_indices)) -Base.getproperty(x::NamedArrayPartition, s::Symbol) = - getindex(ArrayPartition(x).x, getproperty(getfield(x, :names_to_indices), s)) - -# this enables x.s = some_array. -@inline function Base.setproperty!(x::NamedArrayPartition, s::Symbol, v) - index = getproperty(getfield(x, :names_to_indices), s) - ArrayPartition(x).x[index] .= v -end - -# print out NamedArrayPartition as a NamedTuple -Base.summary(x::NamedArrayPartition) = string(typeof(x), " with arrays:") -Base.show(io::IO, m::MIME"text/plain", x::NamedArrayPartition) = - show(io, m, NamedTuple(Pair.(keys(getfield(x, :names_to_indices)), ArrayPartition(x).x))) - -Base.size(x::NamedArrayPartition) = size(ArrayPartition(x)) -Base.length(x::NamedArrayPartition) = length(ArrayPartition(x)) -Base.getindex(x::NamedArrayPartition, args...) = getindex(ArrayPartition(x), args...) - -Base.setindex!(x::NamedArrayPartition, args...) = setindex!(ArrayPartition(x), args...) -Base.map(f, x::NamedArrayPartition) = NamedArrayPartition(map(f, ArrayPartition(x)), getfield(x, :names_to_indices)) -Base.mapreduce(f, op, x::NamedArrayPartition) = mapreduce(f, op, ArrayPartition(x)) -# Base.filter(f, x::NamedArrayPartition) = filter(f, ArrayPartition(x)) - -Base.similar(x::NamedArrayPartition{T, S, NT}) where {T, S, NT} = - NamedArrayPartition{T, S, NT}(similar(ArrayPartition(x)), getfield(x, :names_to_indices)) - -# broadcasting -Base.BroadcastStyle(::Type{<:NamedArrayPartition}) = Broadcast.ArrayStyle{NamedArrayPartition}() -function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}}, - ::Type{ElType}) where {ElType} - x = find_NamedArrayPartition(bc) - return NamedArrayPartition(similar(ArrayPartition(x)), getfield(x, :names_to_indices)) -end - -# when broadcasting with ArrayPartition + another array type, the output is the other array tupe -Base.BroadcastStyle(::Broadcast.ArrayStyle{NamedArrayPartition}, ::Broadcast.DefaultArrayStyle{1}) = - Broadcast.DefaultArrayStyle{1}() - -# hook into ArrayPartition broadcasting routines -@inline RecursiveArrayTools.npartitions(x::NamedArrayPartition) = npartitions(ArrayPartition(x)) -@inline RecursiveArrayTools.unpack(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}}, i) = - Broadcast.Broadcasted(bc.f, RecursiveArrayTools.unpack_args(i, bc.args)) -@inline RecursiveArrayTools.unpack(x::NamedArrayPartition, i) = unpack(ArrayPartition(x), i) - -Base.copy(A::NamedArrayPartition{T,S,NT}) where {T,S,NT} = - NamedArrayPartition{T,S,NT}(copy(ArrayPartition(A)), getfield(A, :names_to_indices)) - -@inline NamedArrayPartition(f::F, N, names_to_indices) where F<:Function = - NamedArrayPartition(ArrayPartition(ntuple(f, Val(N))), names_to_indices) - -@inline function Base.copy(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}}) - N = npartitions(bc) - @inline function f(i) - copy(unpack(bc, i)) - end - x = find_NamedArrayPartition(bc) - NamedArrayPartition(f, N, getfield(x, :names_to_indices)) -end - -@inline function Base.copyto!(dest::NamedArrayPartition, - bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}}) - N = npartitions(dest, bc) - @inline function f(i) - copyto!(ArrayPartition(dest).x[i], unpack(bc, i)) - end - ntuple(f, Val(N)) - return dest -end - -# `x = find_NamedArrayPartition(x)` returns the first `NamedArrayPartition` among broadcast arguments. -find_NamedArrayPartition(bc::Base.Broadcast.Broadcasted) = find_NamedArrayPartition(bc.args) -find_NamedArrayPartition(args::Tuple) = - find_NamedArrayPartition(find_NamedArrayPartition(args[1]), Base.tail(args)) -find_NamedArrayPartition(x) = x -find_NamedArrayPartition(::Tuple{}) = nothing -find_NamedArrayPartition(x::NamedArrayPartition, rest) = x -find_NamedArrayPartition(::Any, rest) = find_NamedArrayPartition(rest) - - diff --git a/test/Project.toml b/test/Project.toml index b65cc55d..45d66fa4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -13,5 +13,5 @@ HOHQMesh = "0.2" Plots = "1" StaticArrays = "1" StructArrays = "0.6" -SummationByPartsOperators = "0.5" +SummationByPartsOperators = "0.5.52" Suppressor = "0.2" diff --git a/test/named_array_partition_tests.jl b/test/named_array_partition_tests.jl deleted file mode 100644 index 79f3fe85..00000000 --- a/test/named_array_partition_tests.jl +++ /dev/null @@ -1,34 +0,0 @@ -@testset "NamedArrayPartition tests" begin - x = NamedArrayPartition(a = ones(10), b = rand(20)) - @test typeof(@. sin(x * x^2 / x - 1)) <: NamedArrayPartition - @test typeof(x.^2) <: NamedArrayPartition - @test x.a ≈ ones(10) - @test typeof(x .+ x[1:end]) <: Vector # test broadcast precedence - @test all(x .== x[1:end]) - y = copy(x) - @test zero(x, (10, 20)) == zero(x) # test that ignoring dims works - @test typeof(zero(x)) <: NamedArrayPartition - @test (y .*= 2).a[1] ≈ 2 # test in-place bcast - - @test length(Array(x))==30 - @test typeof(Array(x)) <: Array - @test propertynames(x) == (:a, :b) - - x = NamedArrayPartition(a = ones(1), b = 2*ones(1)) - @test Base.summary(x) == string(typeof(x), " with arrays:") - @test (@capture_out Base.show(stdout, MIME"text/plain"(), x)) == "(a = [1.0], b = [2.0])" - - using StructArrays - using StaticArrays: SVector - x = NamedArrayPartition(a = StructArray{SVector{2, Float64}}((ones(5), 2*ones(5))), - b = StructArray{SVector{2, Float64}}((3 * ones(2,2), 4*ones(2,2)))) - @test typeof(x.a) <: StructVector{<:SVector{2}} - @test typeof(x.b) <: StructArray{<:SVector{2}, 2} - @test typeof((x->x[1]).(x)) <: NamedArrayPartition - @test typeof(map(x->x[1], x)) <: NamedArrayPartition -end - -# x = NamedArrayPartition(a = ones(10), b = rand(20)) -# x_ap = ArrayPartition(x) -# @btime @. x_ap * x_ap; # 498.836 ns (5 allocations: 2.77 KiB) -# @btime @. x * x; # 2.032 μs (5 allocations: 2.84 KiB) - 5x slower than ArrayPartition diff --git a/test/runtests.jl b/test/runtests.jl index 60303f2c..91d32de4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,9 +8,8 @@ using SummationByPartsOperators using StartUpDG -include("write_vtk_tests.jl") -include("named_array_partition_tests.jl") -include("triangulate_tests.jl") +include("write_vtk_tests.jl") +include("triangulate_tests.jl") include("reference_elem_tests.jl") include("multidim_sbp_tests.jl") include("SummationByPartsOperatorsExt_tests.jl")