In one of my projects, I encountered the following weird behavior of Compile:
In[94]:= Compile[{{r, _Integer}},
Module[{gst = Total@RandomVariate[GammaDistribution[3, 1], r]},
gst]][5]
Out[94]= 12.8387
In[93]:= Compile[{{r, _Integer}},
Module[{gs = RandomVariate[GammaDistribution[3, 1], r]},
Total@gs]][5]
During evaluation of In[93]:= CompiledFunction::cfse: Compiled expression {2.77053,4.99208,2.51185,1.84878,2.6716} should be a machine-size real number.
During evaluation of In[93]:= CompiledFunction::cfex: Could not complete external evaluation at instruction 2; proceeding with uncompiled evaluation.
Out[93]= 14.6549
In[92]:= Compile[{{r, _Integer}},
Module[{gs = RandomVariate[NormalDistribution[3, 1], r]},
Total@gs]][5]
Out[92]= 14.2334
It seems that the rank of RandomVariate[NormalDistribution[x,y],l]
can be properly inferred, but not for GammaDistribution
.
Thanks in advance!