Recently, Oleksandr kindly showed a list of Mathematica commands that can be compiled. RandomVariate was part of that list. However, whether this can be compiled depends upon the distribution that is being sampled.
Needs["CompiledFunctionTools`"]
cf1 = Compile[{{m, _Real}, {s, _Real}},
Module[{v1, v2, v3, v4, v5, v6},
v1 = RandomVariate[NormalDistribution[m, s]];
v2 = RandomVariate[UniformDistribution[{m, s}]];
v3 = RandomVariate[GammaDistribution[m, s]];
v4 = RandomVariate[PoissonDistribution[m]];
v5 = RandomVariate[ChiSquareDistribution[m]];
v6 = RandomVariate[ExponentialDistribution[m]];
{v1, v2, v3, v4, v5, v6}
]
]
Using CompilePrint shows that RandomVariate can be compiled for the Normal Distribution or the Uniform Distribution and not with some others.
CompilePrint[cf1]
2 arguments
4 Integer registers
8 Real registers
1 Tensor register
Underflow checking off
Overflow checking off
Integer overflow checking on
RuntimeAttributes -> {}
R0 = A1
R1 = A2
Result = T(R1)0
1 R2 = RandomNormal[ R0, R1]]
2 R3 = RandomReal[ R0, R1]]
3 I0 = MainEvaluate[ Function[{m, s},
RandomVariate[GammaDistribution[m, s]]][ R0, R1]]
4 I1 = MainEvaluate[ Function[{m, s},
RandomVariate[PoissonDistribution[m]]][ R0, R1]]
5 I2 = MainEvaluate[ Function[{m, s},
RandomVariate[ChiSquareDistribution[m]]][ R0, R1]]
6 I3 = MainEvaluate[ Function[{m, s},
RandomVariate[ExponentialDistribution[m]]][ R0, R1]]
7 R4 = I0
8 R5 = I1
9 R6 = I2
10 R7 = I3
11 T(R1)0 ={ R2, R3, R4, R5, R6, R7 }
12 Return
Does anyone have a list of all the distributions that can be compiled (including, PDF, CDF and RandomVariate functionality)?