|
1 |
| -hasportion(::Tunable, ::Array) = true |
2 |
| -hasportion(::Constants, ::Array) = false |
3 |
| -hasportion(::Caches, ::Array) = false |
4 |
| -hasportion(::Discrete, ::Array) = false |
| 1 | +hasportion(::Tunable, ::AbstractArray) = true |
| 2 | +hasportion(::Constants, ::AbstractArray) = false |
| 3 | +hasportion(::Caches, ::AbstractArray) = false |
| 4 | +hasportion(::Discrete, ::AbstractArray) = false |
5 | 5 |
|
6 |
| -struct ArrayRepack{T} |
| 6 | +struct ArrayRepack{T, Ty} |
7 | 7 | sz::T
|
| 8 | + type::Ty |
8 | 9 | end
|
9 | 10 | function (f::ArrayRepack)(A)
|
10 | 11 | @assert length(A) == prod(f.sz)
|
11 |
| - reshape(A, f.sz) |
| 12 | + A_ = if has_trivial_array_constructor(f.type, A) |
| 13 | + convert(f.type, A) |
| 14 | + 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.") |
| 16 | + end |
| 17 | + reshape(A_, f.sz) |
12 | 18 | end
|
13 | 19 |
|
14 |
| -canonicalize(::Tunable, p::Array) = vec(p), ArrayRepack(size(p)), true |
15 |
| -canonicalize(::Constants, p::Array) = nothing, nothing, nothing |
16 |
| -canonicalize(::Caches, p::Array) = nothing, nothing, nothing |
17 |
| -canonicalize(::Discrete, p::Array) = nothing, nothing, nothing |
| 20 | +canonicalize(::Tunable, p::AbstractArray) = vec(p), ArrayRepack(size(p), typeof(p)), true |
| 21 | +canonicalize(::Constants, p::AbstractArray) = nothing, nothing, nothing |
| 22 | +canonicalize(::Caches, p::AbstractArray) = nothing, nothing, nothing |
| 23 | +canonicalize(::Discrete, p::AbstractArray) = nothing, nothing, nothing |
18 | 24 |
|
19 |
| -isscimlstructure(::Array) = true |
| 25 | +isscimlstructure(::AbstractArray) = true |
20 | 26 |
|
21 |
| -function SciMLStructures.replace(::SciMLStructures.Tunable, arr::AbstractArray, new_arr::AbstractArray) |
| 27 | +function SciMLStructures.replace( |
| 28 | + ::SciMLStructures.Tunable, arr::AbstractArray, new_arr::AbstractArray) |
22 | 29 | reshape(new_arr, size(arr))
|
23 | 30 | end
|
0 commit comments