Skip to content

Commit 70d177a

Browse files
Merge pull request #36 from JuliaDiffEq/aos
general function for AoS -> SoA
2 parents 072c037 + a3e129e commit 70d177a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "2.3.1"
3+
version = "2.4.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and exported in a future Base Julia there will be no issues with the upgrade.
1616
A trait function for whether `x` is a mutable or immutable array. Used for
1717
dispatching to in-place and out-of-place versions of functions.
1818

19+
## aos_to_soa(x)
20+
21+
Converts an array of structs formulation to a struct of arrays.
22+
1923
## isstructured(x)
2024

2125
A trait function for whether a matrix `x` is a sparse structured matrix.
@@ -84,7 +88,7 @@ development.
8488

8589
## Breaking Release Notes
8690

87-
2.0: Changed the default of `ismutable(array::AbstractArray) = true`. We previously defaulted to
91+
2.0: Changed the default of `ismutable(array::AbstractArray) = true`. We previously defaulted to
8892
`Base.@pure ismutable(array::AbstractArray) = typeof(array).mutable`, but there are a lot of cases
8993
where this tends to not work out in a way one would expect. For example, if you put a normal array
9094
into an immutable struct that adds more information to it, this is considered immutable, even if

src/ArrayInterface.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ can_setindex(x) = true
4444
can_setindex(x::AbstractArray) = can_setindex(typeof(x))
4545
can_setindex(::Type{<:AbstractRange}) = false
4646

47+
"""
48+
aos_to_soa(x)
49+
50+
Converts an array of structs formulation to a struct of array
51+
"""
52+
aos_to_soa(x) = x
53+
4754
"""
4855
fast_scalar_indexing(x)
4956
@@ -389,6 +396,7 @@ function __init__()
389396
ismutable(::Type{<:Tracker.TrackedArray}) = false
390397
can_setindex(::Type{<:Tracker.TrackedArray}) = false
391398
fast_scalar_indexing(::Type{<:Tracker.TrackedArray}) = false
399+
aos_to_soa(x::AbstractArray{<:Tracker.TrackedArray,N}) where N = Tracker.collect(x)
392400
end
393401

394402
@require CuArrays="3a865a2d-5b23-5a0f-bc46-62713ec82fae" begin

0 commit comments

Comments
 (0)