Github user dorx commented on a diff in the pull request:
https://github.com/apache/spark/pull/1520#discussion_r15262023
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/random/DistributionGenerator.scala
---
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.mllib.random
+
+import cern.jet.random.Poisson
+import cern.jet.random.engine.DRand
+
+import org.apache.spark.util.random.{XORShiftRandom, Pseudorandom}
+
+/**
+ * Trait for random number generators that generate i.i.d values from a
distribution.
+ */
+trait DistributionGenerator extends Pseudorandom with Serializable {
+
+ /**
+ * @return An i.i.d sample as a Double from an underlying distribution.
+ */
+ def nextValue(): Double
+
+ /**
+ * @return A copy of the DistributionGenerator with a new instance of
the rng object used in the
+ * class when applicable. Each partition has a unique seed and
therefore requires its
+ * own instance of the DistributionGenerator.
+ */
+ def newInstance(): DistributionGenerator
--- End diff --
So ideally `newInstance` would be an abstract static method inside the
DistributionGenerator class that takes an instance as an argument to better
express the fact we're copying the class members in the new instance, but since
abstract static methods in interfaces aren't really supported in Scala (a
combination of trait and object here will be messy for users to implement),
copy will do nicely here.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---