Skip to content

Commit 6b5a55e

Browse files
chore: replace convert with ArrayInterface restructure
1 parent 311597a commit 6b5a55e

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/SciMLStructures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module SciMLStructures
22

3-
using ArrayInterface: has_trivial_array_constructor
3+
using ArrayInterface: has_trivial_array_constructor, restructure
44

55
include("interface.jl")
66
include("array.jl")

src/array.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ hasportion(::Constants, ::AbstractArray) = false
33
hasportion(::Caches, ::AbstractArray) = false
44
hasportion(::Discrete, ::AbstractArray) = false
55

6-
struct ArrayRepack{T, Ty}
7-
sz::T
8-
type::Ty
6+
struct ArrayRepack{T}
7+
x::T
98
end
109
function (f::ArrayRepack)(A)
11-
@assert length(A) == prod(f.sz)
12-
A_ = if has_trivial_array_constructor(f.type, A)
13-
convert(f.type, A)
10+
@assert length(A) == prod(size(f.x))
11+
if has_trivial_array_constructor(f.type, A)
12+
restructure(f.x, A)
1413
else
15-
error("The original type $(typeof(f.type)) does not support the SciMLStructures interface via the AbstractArray `repack` rules. No method exists to take in a regular array and construct the parent type back. Please define the SciMLStructures interface for this type.")
14+
error("The original type $(typeof(f.x)) does not support the SciMLStructures interface via the AbstractArray `repack` rules. No method exists to take in a regular array and construct the parent type back. Please define the SciMLStructures interface for this type.")
1615
end
17-
reshape(A_, f.sz)
1816
end
1917

20-
canonicalize(::Tunable, p::AbstractArray) = vec(p), ArrayRepack(size(p), typeof(p)), true
18+
canonicalize(::Tunable, p::AbstractArray) = vec(p), ArrayRepack(p), true
2119
canonicalize(::Constants, p::AbstractArray) = nothing, nothing, nothing
2220
canonicalize(::Caches, p::AbstractArray) = nothing, nothing, nothing
2321
canonicalize(::Discrete, p::AbstractArray) = nothing, nothing, nothing

0 commit comments

Comments
 (0)