@@ -447,6 +447,25 @@ function zeromatrix(u)
447447 x .* x' .* false
448448end
449449
450+ """
451+ restructure(x,y)
452+
453+ Restructures the object `y` into a shape of `x`, keeping its values intact. For
454+ simple objects like an `Array`, this simply amounts to a reshape. However, for
455+ more complex objects such as an `ArrayPartition`, not all of the structural
456+ information is adequately contained in the type for standard tools to work. In
457+ these cases, `restructure` gives a way to convert for example an `Array` into
458+ a matching `ArrayPartition`.
459+ """
460+ function restructure (x,y)
461+ out = similar (x,eltype (y))
462+ out .= y
463+ end
464+
465+ function restructure (x:: Array ,y)
466+ reshape (convert (Array,y),size (x)... )
467+ end
468+
450469function __init__ ()
451470
452471 @require SuiteSparse= " 4607b0f0-06f3-5cda-b6b1-a6196a1729e9" begin
@@ -461,13 +480,18 @@ function __init__()
461480 ismutable (:: Type{<:StaticArrays.StaticArray} ) = false
462481 can_setindex (:: Type{<:StaticArrays.StaticArray} ) = false
463482 ismutable (:: Type{<:StaticArrays.MArray} ) = true
483+
464484 function lu_instance (_A:: StaticArrays.StaticMatrix{N,N} ) where {N}
465485 A = StaticArrays. SArray (_A)
466486 L = LowerTriangular (A)
467487 U = UpperTriangular (A)
468488 p = StaticArrays. SVector {N,Int} (1 : N)
469489 return StaticArrays. LU (L, U, p)
470490 end
491+
492+ function restructure (x:: StaticArrays.SArray ,y)
493+ error (" Currently not supported" )
494+ end
471495 end
472496
473497 @require LabelledArrays= " 2ee39098-c373-598a-b85f-a56591580800" begin
@@ -483,7 +507,9 @@ function __init__()
483507 end
484508
485509 @require CuArrays= " 3a865a2d-5b23-5a0f-bc46-62713ec82fae" begin
486- include (" cuarrays.jl" )
510+ @require Adapt= " 79e6a3ab-5dfb-504d-930d-738a2a938a0e" begin
511+ include (" cuarrays.jl" )
512+ end
487513 end
488514
489515 @require BandedMatrices= " aae01518-5342-5314-be14-df237901396f" begin
0 commit comments