-
Notifications
You must be signed in to change notification settings - Fork 71
[WIP] use RandomTest to define random distributions for tests #655
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
Conversation
|
CC @fingolfin |
|
Can we make this a test dependency? |
Absolutely, I was about to mention it but didn't want to overload the already long OP. Ideally it would be an optional dependency when Pkg implements it (i.e. loaded only when |
|
Thanks @rfourquet this looks really promising to me. And sorry for not commenting earlier, I somehow missed it :/. The following is somewhat orthogonal to your PR and your RandomTest.jl (both of which I still need to study in more detail), but I thought I'd throw it out here anyway while I am here: Personally, one of the things I'd want/need on the long run is being able to, say, create 10 random invertible Oscar matrices (so not For the former, I'd imagine that I'd write something like But I am somewhat concerned that some code really, really doesn't want to go to the effort of creating this group object just to create random matrices (unless we tune it very carefully so it can be turned into a zero-cost abstraction). That code then would need a way to specify the desired output in another way. But types don't quite cut it, as you know, as the same type might be shared by several different finite fields (resp. matrices over them), and also the dimension of the matrix is not in the type in general. Also, we still would need a way to convey the information the invertible elements are desired. I guess that could be taken off by suitable Perhaps this is a non-issue and I worry for nothing? (To be clear: even if there is reason to worry, that's not an objection to this PR, it's a wider issue). Perhaps there are good suggestions how to deal with this? |
|
Thanks @fingolfin for your comment. So a first remark is that to have So, my first thought is that ideally, creating parent objects is cheap, and if some useful precomputed stuff is expensive, it would be computed lazily. For example, creating in AbstractAlgebra a 2x3 julia> @btime matrix($ZZ, 2, 3, $(rand(1:9, 2, 3)))
399.070 ns (14 allocations: 400 bytes)
[3 5 9]
[8 9 9]
julia> @btime MatrixSpace($ZZ, 2, 3)
84.410 ns (0 allocations: 0 bytes)
Matrix Space of 2 rows and 3 columns over Integers
julia> @btime MatrixSpace($ZZ, 2, 3, false) # don't cache
13.371 ns (1 allocation: 32 bytes)
Matrix Space of 2 rows and 3 columns over IntegersSo creating the parent object is relatively not very significant when creating 10 random matrices. julia> M = MatrixSpace(ZZ, 2, 3)
Matrix Space of 2 rows and 3 columns over Integers
julia> rand(make(M, 1:9))
[5 1 2]
[7 1 2]I see two obvious ways to specify the same distribution without creating Now, for invertible matrices, assuming there is a |
Are there situations where the creation is non-negligible compared to the subsequent call to |
|
On Sat, Oct 10, 2020 at 04:10:41AM -0700, thofma wrote:
> But I am somewhat concerned that some code really, _really_ doesn't want to go to the effort of creating this group object just to create random matrices (unless we tune it very carefully so it can be turned into a zero-cost abstraction).
Are there situations where the creation is non-negligible compared to the subsequent call to `rand(G)`? Of course one should not create `GF(p)` or `Z/nZ` if one wants efficiently uniform integers in the range `1:p` or `1:n`.
rand(GF(p)) SHOULD yield an gfp_elem
rand(1:p) an Int
rand(1:fmpz(p)) an fmpz
even if they are computer science or programming equivalent, in AA they
are not
…
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#655 (comment)
|
|
RandomTest.jl hasn't had any maintenance since Oct 2020, and isn't registered. Thus I do not see us using this in the near future. |
This is based off #648, so only the last commit is new here.
This uses the RandomTest.jl package to define easily new distributions which can be used for testing.
Starting with an example:
randt(x)is equivalent torand(test(x)), wheretest(x)creates a distribution, which ideally generates different "kinds" of values (whatever that means), including corner cases.Another example:
One of the benefits of using
randtcompared torandis when the parameters to supply torandare non very meaningful and arbitrary, thenrandtcan generate relatively sensible parameter.The couple implemented methods here, and modified examples, contain few comments to hopefully help understand how it works (there is of course no documentation yet).
This PR is currently just a preview. It also includes a (even) more speculative example using a
@quickcheckmacro (very rudimentary implementation), inspired by Haskell's QuickCheck library (I don't have a better link right now).Unlike in the original QuickCheck, the focus is more on "scaling the size distribution of the generated values" rather than controlling directly the size. For example, to get bigger numbers than above:
Of course, we can also define
testmethods which take a parameter to directly influence the size, e.g we could havetest(ZZ, 10)or whatnot where 10 suggests or imposes a size.The
RandomTestpackage is not registered, you need to clone yourself in order to run the examples above.