Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

rand(Point2, 10) gives non-concrete type #176

Open
JonasIsensee opened this issue Jul 31, 2019 · 1 comment
Open

rand(Point2, 10) gives non-concrete type #176

JonasIsensee opened this issue Jul 31, 2019 · 1 comment

Comments

@JonasIsensee
Copy link

I noticed the following unfortunate behaviour.
Point2 does not specify it's precision but defaults to Float64.
However when calling rand(Point2, 2) we receive an array that is not concretely typed.

julia> rand(Point2f0, 2)
2-element Array{Point{2,Float32},1}:
 [0.258088, 0.584784]
 [0.374788, 0.938358]

julia> rand(Point2, 2)
2-element Array{Point{2,T} where T,1}:
 [0.860157, 0.0883986]
 [0.595633, 0.42712]  

julia> rand(Point2)
2-element Point{2,Float64}:
 0.5607439716284568 
 0.29493527430930033
@CarpeNecopinum
Copy link
Contributor

CarpeNecopinum commented Oct 18, 2019

From what I see, this is not really an issue with GeometryTypes.jl, but the underlying StaticArrays.jl that is used for the points.

I tracked this down to

@generated function _rand(rng::AbstractRNG, ::Size{s}, ::Type{SA}) where {s, SA <: StaticArray}
    T = eltype(SA)
    if T == Any
        T = Float64
    end
    v = [:(rand(rng, $T)) for i = 1:prod(s)]
    return quote
        @_inline_meta
        $SA(tuple($(v...)))
    end
end

which is in arraymath.jl of StaticArrays.

Though I don't really think this is even a real defect there, because as result it gives you an Array that you can still push more static arrays with other inner types to, and when you really want just Float64, you can still give it explicitly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants