File tree Expand file tree Collapse file tree 6 files changed +42
-0
lines changed Expand file tree Collapse file tree 6 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,14 @@ Collects = "08986516-18db-4a8b-8eaa-f5ef1828d8f1"
8
8
9
9
[weakdeps ]
10
10
Random = " 9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
11
+ Adapt = " 79e6a3ab-5dfb-504d-930d-738a2a938a0e"
11
12
12
13
[extensions ]
13
14
RandomExt = " Random"
15
+ AdaptExt = " Adapt"
14
16
15
17
[compat ]
18
+ Adapt = " 4"
16
19
Collects = " 1"
17
20
Random = " 1"
18
21
julia = " 1.10"
Original file line number Diff line number Diff line change 1
1
[deps ]
2
+ Adapt = " 79e6a3ab-5dfb-504d-930d-738a2a938a0e"
2
3
Changelog = " 5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
3
4
Collects = " 08986516-18db-4a8b-8eaa-f5ef1828d8f1"
4
5
Documenter = " e30172f5-a6a5-5a46-863b-614d45cd2de4"
@@ -8,6 +9,7 @@ FixedSizeArrays = "3821ddf9-e5b5-40d5-8e25-6813ab96b5e2"
8
9
FixedSizeArrays = {path = " .." }
9
10
10
11
[compat ]
12
+ Adapt = " 4"
11
13
Changelog = " 1.1"
12
14
Collects = " 1"
13
15
Documenter = " 1"
Original file line number Diff line number Diff line change @@ -34,6 +34,22 @@ julia> FixedSizeArray{Float64}(arr) # construct from an `AbstractArray` value w
34
34
30.0 14.0
35
35
```
36
36
37
+ To "convert" a wrapper type like ` Adjoint ` while preserving the wrapper structure, you can use ` Adapt ` :
38
+
39
+ ``` jldoctest
40
+ julia> using FixedSizeArrays, Adapt
41
+
42
+ julia> arr = transpose([10 20; 30 14])
43
+ 2×2 transpose(::Matrix{Int64}) with eltype Int64:
44
+ 10 30
45
+ 20 14
46
+
47
+ julia> adapt(FixedSizeArray, arr)
48
+ 2×2 transpose(::FixedSizeArray{Int64, 2, Memory{Int64}}) with eltype Int64:
49
+ 10 30
50
+ 20 14
51
+ ```
52
+
37
53
For 1- and 2-dimensional arrays you can use the aliases [ ` FixedSizeVector ` ] ( @ref ) and [ ` FixedSizeMatrix ` ] ( @ref ) , respectively:
38
54
39
55
``` @repl
Original file line number Diff line number Diff line change
1
+ module AdaptExt
2
+
3
+ using Adapt
4
+ using FixedSizeArrays: FixedSizeArray
5
+
6
+ Adapt. adapt_storage (fixed:: Type{<:FixedSizeArray} , A) = fixed (A)
7
+
8
+ end # module AdaptExt
Original file line number Diff line number Diff line change 1
1
[compat ]
2
+ Adapt = " 4"
2
3
Aqua = " 0.8"
3
4
Collects = " 1"
5
+ LinearAlgebra = " 1"
4
6
OffsetArrays = " 1.14"
5
7
Random = " 1.10"
6
8
Test = " 1.10"
7
9
8
10
[deps ]
11
+ Adapt = " 79e6a3ab-5dfb-504d-930d-738a2a938a0e"
9
12
Aqua = " 4c88cf16-eb10-579e-8560-4a9242c79595"
10
13
Collects = " 08986516-18db-4a8b-8eaa-f5ef1828d8f1"
14
+ LinearAlgebra = " 37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
11
15
OffsetArrays = " 6fe1bfb0-de20-5000-8ca7-80f57d26f881"
12
16
Random = " 9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
13
17
Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
Original file line number Diff line number Diff line change 1
1
using Test
2
+ using LinearAlgebra, Adapt
2
3
using FixedSizeArrays
3
4
using Collects: collect_as
4
5
using OffsetArrays: OffsetArray
669
670
@test v == fv
670
671
end
671
672
end
673
+
674
+ @testset " Adapt" begin
675
+ # Preserver wrapper types:
676
+ arr = transpose ([10 20 ; 30 14 ])
677
+ farr = adapt (FixedSizeArray, arr)
678
+ @test farr isa Transpose
679
+ @test parent (farr) isa FixedSizeArray
680
+ end
672
681
end
You can’t perform that action at this time.
0 commit comments