Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array generation: allow specifying dims as distributions #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rfourquet
Copy link
Member

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.

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
Copy link
Member Author

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
Copy link
Member Author

@mschauer Maybe you have an opinion on this feature?

@mschauer
Copy link

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.

@rfourquet
Copy link
Member Author

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.

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

Successfully merging this pull request may close these issues.

2 participants