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

Random Generation #82

Closed
ghost opened this issue Oct 27, 2020 · 5 comments
Closed

Random Generation #82

ghost opened this issue Oct 27, 2020 · 5 comments

Comments

@ghost
Copy link

ghost commented Oct 27, 2020

I try to generate random matrices with Arblib. I notice that there is a random generation function in Arb to generate real-valued random matrices:

void arb_mat_randtest(arb_mat_t mat, flint_rand_t state, slong prec, slong mag_bits).

But I don't find its correspondence in Arblib. I have tried Arblib.randtest! and other options. Julia always returns error messages like this: "ERROR: UndefVarError: randtest! not defined".

Does Arblib have a julia wrapper for random generation?

@Joel-Dahne
Copy link
Collaborator

The methods for random generation in Arb are currently not wrapped. At some point they might be, but I'm not sure. As you can notice they have the name test, indicating that they are mainly used for testing. There is no way, other than iterating a random number of times, to get a different seed for them. What should be done at some point is to add methods for conveniently generating random Arb-values in Julia directly.

I can also mention that one simple way to check which methods are wrapped is to check the files in src/arbcall/. They correspond to the header files of Arb and for example arb_mat_randtest is commented out there.

@kalmarek
Copy link
Owner

@dbai1989 probably the best option now is to ArbMatrix(Arf.(rand(BigFloat, 5,5))). Note that this allocates at least 2 unnecessary objects per entry...

@Joel-Dahne I thought that ArbMatrix(rand(BigFloat, 5,5)) should work, but it doesn't (the catch-all constructors going through Arf are defined only for honest Arb and Acb). Shall we do something about it or not?

@saschatimme
Copy link
Collaborator

I also would be surprised if just using the Float64 random number generator wouldn't provide enough randomness for almost all applications. Additionally you have plenty of probability distributions to choose from.

@Joel-Dahne
Copy link
Collaborator

I thought that ArbMatrix(rand(BigFloat, 5,5)) would have worked as well. This is probably something we should add at some point for sure!

I would also think that Float64 is enough in most cases. However for testing it would be beneficial to be able to generate random Arbs with non-zero radius, possibly something similar to arb_randtest_special. Maybe something to look take a look at at some point.

@kalmarek
Copy link
Owner

@dbai1989 as of #86 you can generate random Arbs and Arfs and Acbs using the standard random API. It will cost as much as generating random BigFloats + conversion to Arblib type.
In particular rand(Arb, 5,5) will create julia Matrix of Arbs in default precision. To get Arblib matrices you can use ArbMatrix(rand(Arb, 5,5)), or AcbMatrix(rand(Acb(3+2im, prec=128), 5,5). Just to warn you: if you don't need much randomness you're much better calling ArbMatrix(rand(5,5)):

julia> @btime ArbMatrix(rand(Arb(prec=256), 100,100));
  4.085 ms (50007 allocations: 3.21 MiB)

julia> @btime ArbMatrix(rand(Arb, 100,100));
  4.507 ms (60005 allocations: 4.27 MiB)

julia> @btime ArbMatrix(rand(BigFloat, 100,100));
  2.665 ms (30006 allocations: 2.06 MiB)

julia> @btime ArbMatrix(rand(Float64, 100,100));
  175.099 μs (5 allocations: 547.81 KiB)

julia> @btime rand(Arb)
  298.833 ns (5 allocations: 336 bytes)
[0.88919508199801528481643321841955846498685775854589236199210746792567750560825 +/- 3.65e-78]

julia> @btime rand(BigFloat)
  172.728 ns (3 allocations: 224 bytes)
0.9547999587690397939516420169440272364400015480044632809034564083050837641068108

The positive side of this is that the rng is shared between BigFloats and Arbs, so setting seed! will give you "the same" values

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

No branches or pull requests

3 participants