Skip to content

Commit 204f2ab

Browse files
Merge pull request #472 from SciML/format-code-with-juliaformatter
Format code with JuliaFormatter v2.1.5
2 parents eea2b50 + 26c043d commit 204f2ab

9 files changed

+37
-27
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ pB = ArrayPartition(b)
4545
pA .* pB # Now all standard array stuff works!
4646

4747
# or do:
48-
x0 = rand(3,3)
49-
v0 = rand(3,3)
50-
a0 = rand(3,3)
48+
x0 = rand(3, 3)
49+
v0 = rand(3, 3)
50+
a0 = rand(3, 3)
5151
u0 = ArrayPartition(x0, v0, a0)
5252
u0.x[1] == x0 # true
5353

ext/RecursiveArrayToolsKernelAbstractionsExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module RecursiveArrayToolsKernelAbstractionsExt
33
import RecursiveArrayTools: VectorOfArray
44
import KernelAbstractions
55

6-
76
function KernelAbstractions.get_backend(x::VectorOfArray)
87
u = parent(x)
98
if length(u) == 0

ext/RecursiveArrayToolsZygoteExt.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ using RecursiveArrayTools
55
using Zygote
66
using Zygote: FillArrays, ChainRulesCore, literal_getproperty, @adjoint
77

8-
98
# Define a new species of projection operator for this type:
109
# ChainRulesCore.ProjectTo(x::VectorOfArray) = ChainRulesCore.ProjectTo{VectorOfArray}()
1110

@@ -216,10 +215,12 @@ z̄ -> (nothing, conj.(z̄))
216215
@adjoint Broadcast.broadcasted(::typeof(real), x::AbstractVectorOfArray) = real.(x),
217216
-> (nothing, real.(z̄))
218217

219-
@adjoint Broadcast.broadcasted(::typeof(imag), x::AbstractVectorOfArray) = imag.(x),
218+
@adjoint Broadcast.broadcasted(
219+
::typeof(imag), x::AbstractVectorOfArray) = imag.(x),
220220
-> (nothing, im .* real.(z̄))
221221

222-
@adjoint Broadcast.broadcasted(::typeof(abs2), x::AbstractVectorOfArray) = abs2.(x),
222+
@adjoint Broadcast.broadcasted(::typeof(abs2),
223+
x::AbstractVectorOfArray) = abs2.(x),
223224
-> (nothing, 2 .* real.(z̄) .* x)
224225

225226
@adjoint function Broadcast.broadcasted(
@@ -260,7 +261,9 @@ end
260261
end
261262
end
262263

263-
@adjoint Broadcast.broadcasted(::Type{T}, x::AbstractVectorOfArray) where {T <: Number} = T.(x),
264+
@adjoint Broadcast.broadcasted(::Type{T},
265+
x::AbstractVectorOfArray) where {T <:
266+
Number} = T.(x),
264267
ȳ -> (nothing, Zygote._project(x, ȳ))
265268

266269
function Zygote.unbroadcast(x::AbstractVectorOfArray, x̄)
@@ -273,11 +276,16 @@ function Zygote.unbroadcast(x::AbstractVectorOfArray, x̄)
273276
end
274277
end
275278

276-
@adjoint Broadcast.broadcasted(::Broadcast.AbstractArrayStyle, f::F, a::AbstractVectorOfArray, b) where {F} = _broadcast_generic(
279+
@adjoint Broadcast.broadcasted(
280+
::Broadcast.AbstractArrayStyle, f::F, a::AbstractVectorOfArray,
281+
b) where {F} = _broadcast_generic(
277282
__context__, f, a, b)
278-
@adjoint Broadcast.broadcasted(::Broadcast.AbstractArrayStyle, f::F, a, b::AbstractVectorOfArray) where {F} = _broadcast_generic(
283+
@adjoint Broadcast.broadcasted(::Broadcast.AbstractArrayStyle, f::F, a,
284+
b::AbstractVectorOfArray) where {F} = _broadcast_generic(
279285
__context__, f, a, b)
280-
@adjoint Broadcast.broadcasted(::Broadcast.AbstractArrayStyle, f::F, a::AbstractVectorOfArray, b::AbstractVectorOfArray) where {F} = _broadcast_generic(
286+
@adjoint Broadcast.broadcasted(
287+
::Broadcast.AbstractArrayStyle, f::F, a::AbstractVectorOfArray,
288+
b::AbstractVectorOfArray) where {F} = _broadcast_generic(
281289
__context__, f, a, b)
282290

283291
@inline function _broadcast_generic(__context__, f::F, args...) where {F}

src/RecursiveArrayTools.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,15 @@ An AbstractVectorOfArray subtype should match the following behaviors.
2828
2929
!!! note
3030
31-
In 2023 the linear indexing `A[i]`` was deprecated. It previously had the behavior that
32-
`A[i] = A.u[i]`. However, this is incompatible with standard `AbstractArray` interfaces,
33-
Since if `A = VectorOfArray([[1,2],[3,4]])` and `A` is supposed to act like `[1 3; 2 4]`,
34-
then there is a difference `A[1] = [1,2]` for the VectorOfArray while `A[1] = 1` for the
35-
matrix. This causes many issues if `AbstractVectorOfArray <: AbstractArray`. Thus we
36-
plan in 2026 to complete the deprecation and thus have a breaking update where `A[i]`
37-
matches the linear indexing of an `AbstractArray`, and then making
38-
`AbstractVectorOfArray <: AbstractArray`. Until then, `AbstractVectorOfArray` due to
31+
In 2023 the linear indexing `A[i]`` was deprecated. It previously had the behavior that `A[i] = A.u[i]`. However, this is incompatible with standard `AbstractArray`interfaces, Since if`A = VectorOfArray([[1,2],[3,4]])`and`A`is supposed to act like`[1 3; 2 4]`, then there is a difference `A[1] = [1,2]`for the VectorOfArray while`A[1] = 1`for the matrix. This causes many issues if`AbstractVectorOfArray <: AbstractArray`. Thus we plan in 2026 to complete the deprecation and thus have a breaking update where `A[i]`matches the linear indexing of an`AbstractArray`, and then making `AbstractVectorOfArray <: AbstractArray`. Until then, `AbstractVectorOfArray` due to
3932
this interface break but manually implements an AbstractArray-like interface for
4033
future compatibility.
4134
4235
## Fields
4336
4437
An AbstractVectorOfArray has the following fields:
4538
46-
* `u` which holds the Vector of values at each timestep
39+
- `u` which holds the Vector of values at each timestep
4740
4841
## Array Interface
4942
@@ -125,7 +118,7 @@ additional properties:
125118
126119
An AbstractDiffEqArray adds the following fields:
127120
128-
* `t` which holds the times of each timestep.
121+
- `t` which holds the times of each timestep.
129122
"""
130123
abstract type AbstractDiffEqArray{T, N, A} <: AbstractVectorOfArray{T, N, A} end
131124

src/named_array_partition.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ end
115115

116116
# hook into ArrayPartition broadcasting routines
117117
@inline RecursiveArrayTools.npartitions(x::NamedArrayPartition) = npartitions(ArrayPartition(x))
118-
@inline RecursiveArrayTools.unpack(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}}, i) = Broadcast.Broadcasted(
118+
@inline RecursiveArrayTools.unpack(
119+
bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}},
120+
i) = Broadcast.Broadcasted(
119121
bc.f, RecursiveArrayTools.unpack_args(i, bc.args))
120122
@inline RecursiveArrayTools.unpack(x::NamedArrayPartition, i) = unpack(ArrayPartition(x), i)
121123

122124
function Base.copy(A::NamedArrayPartition{T, S, NT}) where {T, S, NT}
123125
NamedArrayPartition{T, S, NT}(copy(ArrayPartition(A)), getfield(A, :names_to_indices))
124126
end
125127

126-
@inline NamedArrayPartition(f::F, N, names_to_indices) where {F <: Function} = NamedArrayPartition(
128+
@inline NamedArrayPartition(f::F,
129+
N,
130+
names_to_indices) where {F <:
131+
Function} = NamedArrayPartition(
127132
ArrayPartition(ntuple(f, Val(N))), names_to_indices)
128133

129134
@inline function Base.copy(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{NamedArrayPartition}})

src/utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ function recursivefill!(bs::AbstractVectorOfArray{T, N},
110110
a::T2) where {T <: StaticArraysCore.StaticArray,
111111
T2 <: StaticArraysCore.StaticArray, N}
112112
@inbounds for b in bs, i in eachindex(b)
113+
113114
b[i] = copy(a)
114115
end
115116
end
@@ -126,6 +127,7 @@ function recursivefill!(bs::AbstractVectorOfArray{T, N},
126127
a::T2) where {T <: StaticArraysCore.SArray,
127128
T2 <: Union{Number, Bool}, N}
128129
@inbounds for b in bs, i in eachindex(b)
130+
129131
b[i] = fill(a, typeof(b[i]))
130132
end
131133
end

test/adjoints.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function loss3(x)
1313
y = VectorOfArray([x .* i for i in 1:5])
1414
tmp = 0.0
1515
for i in 1:5, j in 1:5
16+
1617
tmp += y[i, j]
1718
end
1819
tmp
@@ -22,6 +23,7 @@ function loss4(x)
2223
y = DiffEqArray([x .* i for i in 1:5], 1:5)
2324
tmp = 0.0
2425
for i in 1:5, j in 1:5
26+
2527
tmp += y[i, j]
2628
end
2729
tmp

test/gpu/vectorofarray_gpu.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ va_cu = convert(AbstractArray, va)
4343
@test size(va_cu) == size(x)
4444

4545
a = VectorOfArray([ones(2) for i in 1:3])
46-
_a = Adapt.adapt(CuArray,a)
46+
_a = Adapt.adapt(CuArray, a)
4747
@test _a isa VectorOfArray
4848
@test _a.u isa Vector{<:CuArray}
4949

50-
b = DiffEqArray([ones(2) for i in 1:3],ones(2))
51-
_b = Adapt.adapt(CuArray,b)
50+
b = DiffEqArray([ones(2) for i in 1:3], ones(2))
51+
_b = Adapt.adapt(CuArray, b)
5252
@test _b isa DiffEqArray
5353
@test _b.u isa Vector{<:CuArray}
5454
@test _b.t isa CuArray

test/partitions_test.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ end
286286
@testset "Copy and zero with type changing array" begin
287287
# Motivating use case for this is ArrayPartitions of Arrow arrays which are mmap:ed and change type when copied
288288
struct TypeChangingArray{T, N} <: AbstractArray{T, N} end
289-
Base.copy(::TypeChangingArray{T, N}) where {T, N} = Array{T, N}(undef,
289+
Base.copy(::TypeChangingArray{
290+
T, N}) where {T, N} = Array{T, N}(undef,
290291
ntuple(_ -> 0, N))
291292
Base.zero(::TypeChangingArray{T, N}) where {T, N} = zeros(T, ntuple(_ -> 0, N))
292293

0 commit comments

Comments
 (0)