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.

14 changes: 10 additions & 4 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
name: "Format Check"
name: format-check

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

jobs:
format-check:
name: "Format Check"
uses: "SciML/.github/.github/workflows/format-check.yml@v1"
runic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fredrikekre/runic-action@v1
with:
version: '1'
18 changes: 12 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)

include("pages.jl")

makedocs(sitename = "RecursiveArrayTools.jl",
makedocs(
sitename = "RecursiveArrayTools.jl",
authors = "Chris Rackauckas",
modules = [RecursiveArrayTools],
clean = true, doctest = false, linkcheck = true,
warnonly = [:missing_docs],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/RecursiveArrayTools/stable/"),
pages = pages)
format = Documenter.HTML(
assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/RecursiveArrayTools/stable/"
),
pages = pages
)

deploydocs(repo = "github.com/SciML/RecursiveArrayTools.jl.git";
push_preview = true)
deploydocs(
repo = "github.com/SciML/RecursiveArrayTools.jl.git";
push_preview = true
)
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pages = [
"Home" => "index.md",
"AbstractVectorOfArrayInterface.md",
"array_types.md",
"recursive_array_functions.md"
"recursive_array_functions.md",
]
12 changes: 8 additions & 4 deletions ext/RecursiveArrayToolsFastBroadcastExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ using FastBroadcast
using StaticArraysCore

const AbstractVectorOfSArray = AbstractVectorOfArray{
T, N, <:AbstractVector{<:StaticArraysCore.SArray}} where {T, N}
T, N, <:AbstractVector{<:StaticArraysCore.SArray},
} where {T, N}

@inline function FastBroadcast.fast_materialize!(
::FastBroadcast.Static.False, ::DB, dst::AbstractVectorOfSArray,
bc::Broadcast.Broadcasted{S}) where {S, DB}
bc::Broadcast.Broadcasted{S}
) where {S, DB}
if FastBroadcast.use_fast_broadcast(S)
for i in 1:length(dst.u)
unpacked = RecursiveArrayTools.unpack_voa(bc, i)
dst.u[i] = StaticArraysCore.similar_type(dst.u[i])(unpacked[j]
for j in eachindex(unpacked))
dst.u[i] = StaticArraysCore.similar_type(dst.u[i])(
unpacked[j]
for j in eachindex(unpacked)
)
end
else
Broadcast.materialize!(dst, bc)
Expand Down
2 changes: 1 addition & 1 deletion ext/RecursiveArrayToolsForwardDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using RecursiveArrayTools
using ForwardDiff

function ForwardDiff.extract_derivative(::Type{T}, y::AbstractVectorOfArray) where {T}
ForwardDiff.extract_derivative.(T, y)
return ForwardDiff.extract_derivative.(T, y)
end

end
12 changes: 7 additions & 5 deletions ext/RecursiveArrayToolsMeasurementsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ module RecursiveArrayToolsMeasurementsExt
import RecursiveArrayTools
import Measurements

function RecursiveArrayTools.recursive_unitless_bottom_eltype(a::Type{
<:Measurements.Measurement,
})
typeof(oneunit(a))
function RecursiveArrayTools.recursive_unitless_bottom_eltype(
a::Type{
<:Measurements.Measurement,
}
)
return typeof(oneunit(a))
end

function RecursiveArrayTools.recursive_unitless_eltype(a::Type{<:Measurements.Measurement})
typeof(oneunit(a))
return typeof(oneunit(a))
end

end
20 changes: 12 additions & 8 deletions ext/RecursiveArrayToolsMonteCarloMeasurementsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ module RecursiveArrayToolsMonteCarloMeasurementsExt
import RecursiveArrayTools
import MonteCarloMeasurements

function RecursiveArrayTools.recursive_unitless_bottom_eltype(a::Type{
<:MonteCarloMeasurements.Particles,
})
typeof(one(a))
function RecursiveArrayTools.recursive_unitless_bottom_eltype(
a::Type{
<:MonteCarloMeasurements.Particles,
}
)
return typeof(one(a))
end

function RecursiveArrayTools.recursive_unitless_eltype(a::Type{
<:MonteCarloMeasurements.Particles,
})
typeof(one(a))
function RecursiveArrayTools.recursive_unitless_eltype(
a::Type{
<:MonteCarloMeasurements.Particles,
}
)
return typeof(one(a))
end

end
4 changes: 3 additions & 1 deletion ext/RecursiveArrayToolsReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function trackedarraycopyto!(dest, src)
dest.u[i] = slice
end
end
return
end

@adjoint function Array(VA::AbstractVectorOfArray{<:ReverseDiff.TrackedReal})
Expand All @@ -25,7 +26,8 @@ end
end

@adjoint function Base.view(
A::AbstractVectorOfArray{<:ReverseDiff.TrackedReal, N}, I::Colon...) where {N}
A::AbstractVectorOfArray{<:ReverseDiff.TrackedReal, N}, I::Colon...
) where {N}
view_adjoint = let A = A, I = I
function (y)
A = recursivecopy(A)
Expand Down
5 changes: 3 additions & 2 deletions ext/RecursiveArrayToolsSparseArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import SparseArrays
import RecursiveArrayTools

function Base.copyto!(
dest::SparseArrays.AbstractCompressedVector, A::RecursiveArrayTools.ArrayPartition)
dest::SparseArrays.AbstractCompressedVector, A::RecursiveArrayTools.ArrayPartition
)
@assert length(dest) == length(A)
cur = 1
@inbounds for i in 1:length(A.x)
Expand All @@ -15,7 +16,7 @@ function Base.copyto!(
end
cur += length(A.x[i])
end
dest
return dest
end

# Fix for issue #486: Define issparse for AbstractVectorOfArray
Expand Down
4 changes: 2 additions & 2 deletions ext/RecursiveArrayToolsStatisticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ using Statistics

@inline Statistics.mean(VA::AbstractVectorOfArray; kwargs...) = mean(Array(VA); kwargs...)
@inline function Statistics.median(VA::AbstractVectorOfArray; kwargs...)
median(Array(VA); kwargs...)
return median(Array(VA); kwargs...)
end
@inline Statistics.std(VA::AbstractVectorOfArray; kwargs...) = std(Array(VA); kwargs...)
@inline Statistics.var(VA::AbstractVectorOfArray; kwargs...) = var(Array(VA); kwargs...)
@inline Statistics.cov(VA::AbstractVectorOfArray; kwargs...) = cov(Array(VA); kwargs...)
@inline Statistics.cor(VA::AbstractVectorOfArray; kwargs...) = cor(Array(VA); kwargs...)

end
end
36 changes: 20 additions & 16 deletions ext/RecursiveArrayToolsStructArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,38 @@ import RecursiveArrayTools, StructArrays
RecursiveArrayTools.rewrap(::StructArrays.StructArray, u) = StructArrays.StructArray(u)

using RecursiveArrayTools: VectorOfArray, VectorOfArrayStyle, ArrayInterface, unpack_voa,
narrays, StaticArraysCore
narrays, StaticArraysCore
using StructArrays: StructArray

const VectorOfStructArray{T, N} = VectorOfArray{T, N, <:StructArray}

# Since `StructArray` lazily materializes struct entries, the general `setindex!(x, val, I)`
# operation `VA.u[I[end]][Base.front(I)...]` will only update a lazily materialized struct
# entry of `u`, but will not actually mutate `x::StructArray`. See the StructArray documentation
# Since `StructArray` lazily materializes struct entries, the general `setindex!(x, val, I)`
# operation `VA.u[I[end]][Base.front(I)...]` will only update a lazily materialized struct
# entry of `u`, but will not actually mutate `x::StructArray`. See the StructArray documentation
# for more details:
#
# https://juliaarrays.github.io/StructArrays.jl/stable/counterintuitive/#Modifying-a-field-of-a-struct-element
#
# To avoid this, we can materialize a struct entry, modify it, and then use `setindex!`
# https://juliaarrays.github.io/StructArrays.jl/stable/counterintuitive/#Modifying-a-field-of-a-struct-element
#
# To avoid this, we can materialize a struct entry, modify it, and then use `setindex!`
# with the modified struct entry.
#
function Base.setindex!(VA::VectorOfStructArray{T, N}, v,
I::Int...) where {T, N}
#
function Base.setindex!(
VA::VectorOfStructArray{T, N}, v,
I::Int...
) where {T, N}
u_I = VA.u[I[end]]
u_I[Base.front(I)...] = v
return VA.u[I[end]] = u_I
end

for (type, N_expr) in [
(Broadcast.Broadcasted{<:VectorOfArrayStyle}, :(narrays(bc))),
(Broadcast.Broadcasted{<:Broadcast.DefaultArrayStyle}, :(length(dest.u)))
]
@eval @inline function Base.copyto!(dest::VectorOfStructArray,
bc::$type)
(Broadcast.Broadcasted{<:VectorOfArrayStyle}, :(narrays(bc))),
(Broadcast.Broadcasted{<:Broadcast.DefaultArrayStyle}, :(length(dest.u))),
]
@eval @inline function Base.copyto!(
dest::VectorOfStructArray,
bc::$type
)
bc = Broadcast.flatten(bc)
N = $N_expr
@inbounds for i in 1:N
Expand All @@ -55,7 +59,7 @@ for (type, N_expr) in [
end
dest[:, i] = dest_i
end
dest
return dest
end
end

Expand Down
30 changes: 18 additions & 12 deletions ext/RecursiveArrayToolsTablesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ function Tables.rows(A::AbstractDiffEqArray)
N = length(A.u[1])
names = [
:timestamp,
(isempty(variable_symbols(A)) ?
(Symbol("value", i) for i in 1:N) :
Symbol.(variable_symbols(A)))...
(
isempty(variable_symbols(A)) ?
(Symbol("value", i) for i in 1:N) :
Symbol.(variable_symbols(A))
)...,
]
types = Type[eltype(A.t), (eltype(A.u[1]) for _ in 1:N)...]
else
names = [
:timestamp,
(isempty(variable_symbols(A)) ? :value : Symbol(variable_symbols(A)[1]))
(isempty(variable_symbols(A)) ? :value : Symbol(variable_symbols(A)[1])),
]
types = Type[eltype(A.t), VT]
end
Expand All @@ -41,16 +43,20 @@ struct AbstractDiffEqArrayRows{T, U}
u::U
end
function AbstractDiffEqArrayRows(names, types, t, u)
AbstractDiffEqArrayRows(Symbol.(names), types,
Dict(Symbol(nm) => i for (i, nm) in enumerate(names)), t, u)
return AbstractDiffEqArrayRows(
Symbol.(names), types,
Dict(Symbol(nm) => i for (i, nm) in enumerate(names)), t, u
)
end

Base.length(x::AbstractDiffEqArrayRows) = length(x.u)
function Base.eltype(::Type{AbstractDiffEqArrayRows{T, U}}) where {T, U}
AbstractDiffEqArrayRow{eltype(T), eltype(U)}
return AbstractDiffEqArrayRow{eltype(T), eltype(U)}
end
function Base.iterate(x::AbstractDiffEqArrayRows,
(t_state, u_state) = (iterate(x.t), iterate(x.u)))
function Base.iterate(
x::AbstractDiffEqArrayRows,
(t_state, u_state) = (iterate(x.t), iterate(x.u))
)
t_state === nothing && return nothing
u_state === nothing && return nothing
t, _t_state = t_state
Expand All @@ -74,17 +80,17 @@ end

Tables.columnnames(x::AbstractDiffEqArrayRow) = getfield(x, :names)
function Tables.getcolumn(x::AbstractDiffEqArrayRow, i::Int)
i == 1 ? getfield(x, :t) : getfield(x, :u)[i - 1]
return i == 1 ? getfield(x, :t) : getfield(x, :u)[i - 1]
end
function Tables.getcolumn(x::AbstractDiffEqArrayRow, nm::Symbol)
nm === :timestamp ? getfield(x, :t) : getfield(x, :u)[getfield(x, :lookup)[nm] - 1]
return nm === :timestamp ? getfield(x, :t) : getfield(x, :u)[getfield(x, :lookup)[nm] - 1]
end

# Iterator interface for QueryVerse
# (see also https://tables.juliadata.org/stable/#Tables.datavaluerows)
IteratorInterfaceExtensions.isiterable(::AbstractDiffEqArray) = true
function IteratorInterfaceExtensions.getiterator(A::AbstractDiffEqArray)
Tables.datavaluerows(Tables.rows(A))
return Tables.datavaluerows(Tables.rows(A))
end

end
11 changes: 7 additions & 4 deletions ext/RecursiveArrayToolsTrackerExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module RecursiveArrayToolsTrackerExt
import RecursiveArrayTools
import Tracker

function RecursiveArrayTools.recursivecopy!(b::AbstractArray{T, N},
a::AbstractArray{T2, N}) where {
function RecursiveArrayTools.recursivecopy!(
b::AbstractArray{T, N},
a::AbstractArray{T2, N}
) where {
T <:
Tracker.TrackedArray,
T2 <:
Tracker.TrackedArray,
N}
@inbounds for i in eachindex(a)
N,
}
return @inbounds for i in eachindex(a)
b[i] = copy(a[i])
end
end
Expand Down
Loading
Loading