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"
88
99[weakdeps ]
1010Random = " 9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
11+ Adapt = " 79e6a3ab-5dfb-504d-930d-738a2a938a0e"
1112
1213[extensions ]
1314RandomExt = " Random"
15+ AdaptExt = " Adapt"
1416
1517[compat ]
18+ Adapt = " 4"
1619Collects = " 1"
1720Random = " 1"
1821julia = " 1.10"
Original file line number Diff line number Diff line change 11[deps ]
2+ Adapt = " 79e6a3ab-5dfb-504d-930d-738a2a938a0e"
23Changelog = " 5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
34Collects = " 08986516-18db-4a8b-8eaa-f5ef1828d8f1"
45Documenter = " e30172f5-a6a5-5a46-863b-614d45cd2de4"
@@ -8,6 +9,7 @@ FixedSizeArrays = "3821ddf9-e5b5-40d5-8e25-6813ab96b5e2"
89FixedSizeArrays = {path = " .." }
910
1011[compat ]
12+ Adapt = " 4"
1113Changelog = " 1.1"
1214Collects = " 1"
1315Documenter = " 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
3434 30.0 14.0
3535```
3636
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+
3753For 1- and 2-dimensional arrays you can use the aliases [ ` FixedSizeVector ` ] ( @ref ) and [ ` FixedSizeMatrix ` ] ( @ref ) , respectively:
3854
3955``` @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 11[compat ]
2+ Adapt = " 4"
23Aqua = " 0.8"
34Collects = " 1"
5+ LinearAlgebra = " 1"
46OffsetArrays = " 1.14"
57Random = " 1.10"
68Test = " 1.10"
79
810[deps ]
11+ Adapt = " 79e6a3ab-5dfb-504d-930d-738a2a938a0e"
912Aqua = " 4c88cf16-eb10-579e-8560-4a9242c79595"
1013Collects = " 08986516-18db-4a8b-8eaa-f5ef1828d8f1"
14+ LinearAlgebra = " 37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1115OffsetArrays = " 6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1216Random = " 9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1317Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
Original file line number Diff line number Diff line change 11using Test
2+ using LinearAlgebra, Adapt
23using FixedSizeArrays
34using Collects: collect_as
45using OffsetArrays: OffsetArray
669670 @test v == fv
670671 end
671672 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
672681end
You can’t perform that action at this time.
0 commit comments