StructArrays.jl icon indicating copy to clipboard operation
StructArrays.jl copied to clipboard

rand() returns structarray

Open aplavin opened this issue 2 years ago • 5 comments

can turn it into an 1.9 extension if Random is considered a dependency

aplavin avatar Mar 25 '23 20:03 aplavin

Bump...

aplavin avatar May 05 '23 06:05 aplavin

Do other array libraries do this? It seems to me that rand always returns a plain array, regardless of the type of the container with the options:

julia> using Random

julia> s = [1, 2];

julia> rand(Random.MersenneTwister(), s, (3,))
3-element Vector{Int64}:
 2
 1
 2

julia> rand(Random.MersenneTwister(), Set(s), (3,))
3-element Vector{Int64}:
 2
 1
 2

julia> using CUDA

julia> rand(Random.MersenneTwister(), CUDA.cu(s), (3,))
3-element Vector{Int64}:
 1
 2
 2

piever avatar May 05 '23 14:05 piever

Do other array libraries do this?

That's a barrier for introducing any behavior in the first place, because at some point no packages do <insert anything> :)

I think it makes sense, if rand returned structarray then B = rand(A, length(A)) and A could be used completely interchangeably, eg for bootstrap sampling.

aplavin avatar May 06 '23 20:05 aplavin

bump...

aplavin avatar Jun 17 '23 15:06 aplavin

bump...

aplavin avatar Jul 13 '23 06:07 aplavin