Skip to content

zeros, rand, randn could infer the length parameter of incompletely parameterized StaticArrays #1303

@mikmoore

Description

@mikmoore

From https://discourse.julialang.org/t/why-does-smatrix-allocate-in-this-case/127808.

julia> zeros(SMatrix{2,2,Float32,4}, 1)
1-element Vector{SMatrix{2, 2, Float32, 4}}:
 [0.0 0.0; 0.0 0.0]

julia> zeros(SMatrix{2,2,Float32}, 1) # container is incompletely typed
1-element Vector{SMatrix{2, 2, Float32}}:
 [0.0 0.0; 0.0 0.0]

The same behavior happens for rand, randn, and probably any others in this family. And also for the MArray type.

It seems that it should be possible for the function to infer a missing length parameter and use it for the container's type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions