It has nothing to do with the implementation of AlignedAllocs
, the FixedSizeArray
type just doesn’t (yet) support directly wrapping an input DenseVector
with a possibly different size. It’s just some uninitialized instantiation and collecting input AbstractArray
s into new parent DenseVector
s (currently defaulting to Memory
), which is a bit strange because the latter seems to be what FixedSizeArrayDefault
is intended for.
julia> methods(FixedSizeArray.body.body.body)
# 4 methods for type constructor:
[1] (::Type{FSA})(::UndefInitializer, size::Tuple{Vararg{Integer}}) where {T, FSA<:(FixedSizeArray{T, N, Mem} where {N, Mem<:DenseVector{T}})}
@ C:\Users\benm1\.julia\packages\FixedSizeArrays\22QFl\src\FixedSizeArray.jl:138
[2] (::Type{FSA})(::UndefInitializer, size::Integer...) where {T, FSA<:(FixedSizeArray{T, N, Mem} where {N, Mem<:DenseVector{T}})}
@ C:\Users\benm1\.julia\packages\FixedSizeArrays\22QFl\src\FixedSizeArray.jl:141
[3] (::Type{FSA})(src::AbstractArray) where {N, FSA<:(FixedSizeArray{var"#s3", N, Mem} where {var"#s3", Mem<:DenseVector{var"#s3"}})}
@ C:\Users\benm1\.julia\packages\FixedSizeArrays\22QFl\src\FixedSizeArray.jl:336
[4] (::Type{FSA})(src::AbstractArray) where FSA<:FixedSizeArray
@ C:\Users\benm1\.julia\packages\FixedSizeArrays\22QFl\src\FixedSizeArray.jl:343
We can verify with a minimal example type:
julia> begin
# might be an incorrect subtype, but it'll serve the example
mutable struct OneElement{T} <: DenseVector{T} value::T end
Base.size(::OneElement) = (1,)
Base.getindex(A::OneElement, i::Int) = if i == 1 A.value else throw(BoundsError(A, i)) end
Base.setindex!(A::OneElement, v, i::Int) = if i == 1 A.value = v else throw(BoundsError(A, i)) end
using FixedSizeArrays
end
julia> FixedSizeArray(OneElement(2f0)) # input collected into parent Memory
1-element FixedSizeArray{Float32, 1, Memory{Float32}}:
2.0
julia> FixedSizeVector(OneElement(2f0)) # of course aliases also do this
1-element FixedSizeArray{Float32, 1, Memory{Float32}}:
2.0
There is only a private inner constructor(?) that can do this, but it’s not ideal because there isn’t an option to compute the size directly from the DenseVector
and broadcasting fails at a with_stripped_type_parameters_unchecked
call that is only implemented for Vector
and GenericMemory
.
julia> FixedSizeArrays.new_fixed_size_array(OneElement(2f0), (1,)) # no idea why the alias is printed
1-element FixedSizeVector{Float32, OneElement{Float32}}:
2.0
julia> 1 .+ FixedSizeArrays.new_fixed_size_array(OneElement(2f0), (1,1))
ERROR: MethodError: no method matching with_stripped_type_parameters_unchecked(::FixedSizeArrays.TypeParametersElementType, ::Type{OneElement{Float32}})