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

array generation: allow specifying dims as distributions

Open rfourquet opened this issue 4 years ago • 4 comments

The number of dimensions is still fixed, but the sizes can be computed at runtime, when specified as a distributions. For example rand(make(Vector, Int, 1:3)) creates a Vector{Int} of random length in 1:3.

rfourquet avatar Mar 21 '20 18:03 rfourquet

The motivation for this change is to derive (probably in a separate package) a distribution for testing purposes (à la QuichCheck), where we want to test arrays with different sizes. The API could look like:

for _=1:100
    @test myfunction(rand(test(Matrix{Int})))
end

Where test(Matrix{Int}) is a distribution for which the length of the resulting matrix is taken randomly, with sane parameters as defaults (e.g. Int with bit size taken in (the positive part of) Normal(0, 5)).

Of course, this is the first step, the same would follow for other containers.

rfourquet avatar Mar 21 '20 20:03 rfourquet

@mschauer Maybe you have an opinion on this feature?

rfourquet avatar Mar 21 '20 20:03 rfourquet

I am not sure. I can see that a random matrix might have random size, but I would expect that a typical situation would sample the elements of the matrix conditional on the matrix sizes.

mschauer avatar Mar 23 '20 09:03 mschauer

Thanks for your input!

I would expect that a typical situation would sample the elements of the matrix conditional on the matrix sizes.

Ok, I think I see what you mean, and if so then this would have to be implemented at another level. The current design is that each generation of "scalar" doesn't know the context, in particular doesn't know the dimensions of the array. The array as a whole would need to be considered as the unit of generation, probably similar as for MatrixVariate in Distributions.jl.

I agree that random dimensions seems like a very marginal need, but I precisely had this need so I believe it's a good idea to enable that as an experimental feature, as it doesn't seem to be in the way of other features.

rfourquet avatar Mar 23 '20 14:03 rfourquet