Skip to content

Commit a8ea92d

Browse files
committed
Reviewer comments
1 parent 063ea0b commit a8ea92d

File tree

5 files changed

+371
-225
lines changed

5 files changed

+371
-225
lines changed

mllib/src/main/scala/org/apache/spark/mllib/random/DistributionGenerator.scala

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,49 @@ import org.apache.spark.util.random.{XORShiftRandom, Pseudorandom}
2828
trait DistributionGenerator extends Pseudorandom with Serializable {
2929

3030
/**
31-
* @return An i.i.d sample as a Double from an underlying distribution.
31+
* Returns an i.i.d sample as a Double from an underlying distribution.
3232
*/
3333
def nextValue(): Double
3434

3535
/**
36-
* @return A copy of the DistributionGenerator with a new instance of the rng object used in the
37-
* class when applicable. Each partition has a unique seed and therefore requires its
38-
* own instance of the DistributionGenerator.
36+
* Returns a copy of the DistributionGenerator with a new instance of the rng object used in the
37+
* class when applicable for non-locking concurrent usage.
3938
*/
40-
def newInstance(): DistributionGenerator
39+
def copy(): DistributionGenerator
4140
}
4241

4342
/**
4443
* Generates i.i.d. samples from U[0.0, 1.0]
4544
*/
46-
class UniformGenerator() extends DistributionGenerator {
45+
class UniformGenerator extends DistributionGenerator {
4746

4847
// XORShiftRandom for better performance. Thread safety isn't necessary here.
4948
private val random = new XORShiftRandom()
5049

51-
/**
52-
* @return An i.i.d sample as a Double from U[0.0, 1.0].
53-
*/
5450
override def nextValue(): Double = {
5551
random.nextDouble()
5652
}
5753

58-
/** Set random seed. */
5954
override def setSeed(seed: Long) = random.setSeed(seed)
6055

61-
override def newInstance(): UniformGenerator = new UniformGenerator()
56+
override def copy(): UniformGenerator = new UniformGenerator()
6257
}
6358

6459
/**
6560
* Generates i.i.d. samples from the Standard Normal Distribution.
6661
*/
67-
class StandardNormalGenerator() extends DistributionGenerator {
62+
class StandardNormalGenerator extends DistributionGenerator {
6863

6964
// XORShiftRandom for better performance. Thread safety isn't necessary here.
7065
private val random = new XORShiftRandom()
7166

72-
/**
73-
* @return An i.i.d sample as a Double from the Normal distribution.
74-
*/
7567
override def nextValue(): Double = {
7668
random.nextGaussian()
7769
}
7870

79-
/** Set random seed. */
8071
override def setSeed(seed: Long) = random.setSeed(seed)
8172

82-
override def newInstance(): StandardNormalGenerator = new StandardNormalGenerator()
73+
override def copy(): StandardNormalGenerator = new StandardNormalGenerator()
8374
}
8475

8576
/**
@@ -91,15 +82,11 @@ class PoissonGenerator(val mean: Double) extends DistributionGenerator {
9182

9283
private var rng = new Poisson(mean, new DRand)
9384

94-
/**
95-
* @return An i.i.d sample as a Double from the Poisson distribution.
96-
*/
9785
override def nextValue(): Double = rng.nextDouble()
9886

99-
/** Set random seed. */
10087
override def setSeed(seed: Long) {
10188
rng = new Poisson(mean, new DRand(seed.toInt))
10289
}
10390

104-
override def newInstance(): PoissonGenerator = new PoissonGenerator(mean)
91+
override def copy(): PoissonGenerator = new PoissonGenerator(mean)
10592
}

0 commit comments

Comments
 (0)