Description
The wrap
function, added by @MasonProtter in #52049, seems like it would be generally useful. It's like a converting constructor for arrays, but non-copying. The interface is basically wrap(output_type::Type, vector_to_be_wrapped)
, with optional trailing arguments for the shape also being supported:
Lines 3159 to 3206 in 895a981
Some questions that come to mind:
-
What's the generic signature? Something like
wrap(::Type{<:AbstractArray}, ::AbstractVector[, ::Dims])
? What's the most generic way to write the doc string? Can this support things other than arrays? -
What should happen when a non-
AbstractVector
AbstractArray
is passed as the second argument? -
The short and nondescript name makes me uncomfortable. Perhaps something like
wrap_in
orwrap_into
would be better? See also:wrap
is a very generic name to export #53552
Motivation: I think it'd be nice if FixedSizeArrays.jl could add methods to wrap
to support wrapping other array types, cc @giordano @oscardssmith. The method could look like this:
function Base.wrap(::Type{FixedSizeVector}, vec::Union{Vector, Memory})
new_fixed_size_array(vec, length(vec))
end