diff --git a/.github/workflows/Downgrade.yml b/.github/workflows/Downgrade.yml index d6d5a4e4..3eef5129 100644 --- a/.github/workflows/Downgrade.yml +++ b/.github/workflows/Downgrade.yml @@ -15,18 +15,22 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - version: ['1'] group: - Core - - Downstream + downgrade_mode: ['alldeps'] + julia-version: ['1.10'] steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: - version: ${{ matrix.version }} - - uses: julia-actions/julia-downgrade-compat@v1 + version: ${{ matrix.julia-version }} + - uses: julia-actions/julia-downgrade-compat@v2 # if: ${{ matrix.version == '1.6' }} with: skip: Pkg,TOML - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 + with: + ALLOW_RERESOLVE: false + env: + GROUP: ${{ matrix.group }} diff --git a/Project.toml b/Project.toml index c8e5752b..df58f1e3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RecursiveArrayTools" uuid = "731186ca-8d62-57ce-b412-fbd966d074cd" authors = ["Chris Rackauckas "] -version = "3.35.0" +version = "3.36.0" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -43,7 +43,7 @@ RecursiveArrayToolsZygoteExt = "Zygote" [compat] Adapt = "3.4, 4" Aqua = "0.8" -ArrayInterface = "7.6" +ArrayInterface = "7.10" DocStringExtensions = "0.9" FastBroadcast = "0.2.8, 0.3" ForwardDiff = "0.10.19, 1" @@ -65,7 +65,7 @@ StaticArrays = "1.6" StaticArraysCore = "1.4" Statistics = "1.10, 1.11" StructArrays = "0.6.11, 0.7" -SymbolicIndexingInterface = "0.3.25" +SymbolicIndexingInterface = "0.3.30" Tables = "1.11" Test = "1" Tracker = "0.2.15" diff --git a/README.md b/README.md index af34685c..bf041dfc 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ the documentation, which contains the unreleased features. ## Example +### VectorOfArray + ```julia using RecursiveArrayTools a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] @@ -30,11 +32,30 @@ vA = VectorOfArray(a) vB = VectorOfArray(b) vA .* vB # Now all standard array stuff works! +``` +### ArrayPartition + +```julia a = (rand(5), rand(5)) b = (rand(5), rand(5)) pA = ArrayPartition(a) pB = ArrayPartition(b) pA .* pB # Now all standard array stuff works! + +# or do: +x0 = rand(3,3) +v0 = rand(3,3) +a0 = rand(3,3) +u0 = ArrayPartition(x0, v0, a0) +u0.x[1] == x0 # true + +u0 .+= 1 +u0.x[2] == v0 # still true + +# do some calculations creating a new partitioned array +unew = u0 * 10 +# easily access the individual components without having to rely on complicated indexing +xnew, vnew, anew = unew.x ``` diff --git a/src/array_partition.jl b/src/array_partition.jl index b0325fe0..89261f4b 100644 --- a/src/array_partition.jl +++ b/src/array_partition.jl @@ -365,14 +365,20 @@ end end @inline function Base.copyto!(dest::ArrayPartition, - bc::Broadcast.Broadcasted{ArrayPartitionStyle{Style}}) where { - Style, -} + bc::Broadcast.Broadcasted{ArrayPartitionStyle{Style}}) where {Style} N = npartitions(dest, bc) - @inline function f(i) - copyto!(dest.x[i], unpack(bc, i)) + # If dest is all the same underlying array type, use for-loop + if all(x isa typeof(first(dest.x)) for x in dest.x) + @inbounds for i in 1:N + copyto!(dest.x[i], unpack(bc, i)) + end + else + # Fall back to original implementation for complex broadcasts + @inline function f(i) + copyto!(dest.x[i], unpack(bc, i)) + end + ntuple(f, Val(N)) end - ntuple(f, Val(N)) dest end @@ -411,8 +417,8 @@ end i) where {Style <: Broadcast.DefaultArrayStyle} Broadcast.Broadcasted{Style}(bc.f, unpack_args(i, bc.args)) end -unpack(x, ::Any) = x -unpack(x::ArrayPartition, i) = x.x[i] +@inline unpack(x, ::Any) = x +@inline unpack(x::ArrayPartition, i) = x.x[i] @inline function unpack_args(i, args::Tuple) (unpack(args[1], i), unpack_args(i, Base.tail(args))...) diff --git a/src/named_array_partition.jl b/src/named_array_partition.jl index de8fa91a..1db2b981 100644 --- a/src/named_array_partition.jl +++ b/src/named_array_partition.jl @@ -138,10 +138,9 @@ 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)) + @inbounds for i in 1:N + copyto!(getfield(dest, :array_partition).x[i], unpack(bc, i)) end - ntuple(f, Val(N)) return dest end