commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [38/53] [math] MATH-1158.
Date Fri, 25 Mar 2016 15:19:23 GMT
MATH-1158.

Syntactic sugar.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/7530b4bd
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/7530b4bd
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/7530b4bd

Branch: refs/heads/feature-MATH-1158
Commit: 7530b4bdceef0ef37af252f0b97978554fb9b99f
Parents: 6c94c16
Author: Gilles <erans@apache.org>
Authored: Fri Mar 11 04:14:57 2016 +0100
Committer: Gilles <erans@apache.org>
Committed: Fri Mar 11 04:14:57 2016 +0100

----------------------------------------------------------------------
 .../distribution/AbstractRealDistribution.java     | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/7530b4bd/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
b/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
index 4afdb6d..f584253 100644
--- a/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
+++ b/src/main/java/org/apache/commons/math4/distribution/AbstractRealDistribution.java
@@ -281,6 +281,23 @@ public abstract class AbstractRealDistribution
         return FastMath.log(density(x));
     }
 
+    /**
+     * Utility function for allocating an array and filling it with {@code n}
+     * samples generated by the given {@code sampler}.
+     *
+     * @param n Number of samples.
+     * @param sampler Sampler.
+     * @return an array of size {@code n}.
+     */
+    public static double[] sample(int n,
+                                  RealDistribution.Sampler sampler) {
+        final double[] samples = new double[n];
+        for (int i = 0; i < n; i++) {
+            samples[i] = sampler.sample();
+        }
+        return samples;
+    }
+
     /**{@inheritDoc} */
     @Override
     public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {


Mime
View raw message