Skip to content

Commit 77dbd3f

Browse files
committed
Make initialization check an assertion
1 parent 9cfc301 commit 77dbd3f

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

mllib/src/main/scala/org/apache/spark/mllib/clustering/StreamingKMeans.scala

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class StreamingKMeans(
214214
* @param data DStream containing vector data
215215
*/
216216
def trainOn(data: DStream[Vector]) {
217-
this.isInitialized
217+
this.assertInitialized()
218218
data.foreachRDD { (rdd, time) =>
219219
model = model.update(rdd, this.a, this.units)
220220
}
@@ -227,7 +227,7 @@ class StreamingKMeans(
227227
* @return DStream containing predictions
228228
*/
229229
def predictOn(data: DStream[Vector]): DStream[Int] = {
230-
this.isInitialized
230+
this.assertInitialized()
231231
data.map(model.predict)
232232
}
233233

@@ -239,21 +239,14 @@ class StreamingKMeans(
239239
* @return DStream containing the input keys and the predictions as values
240240
*/
241241
def predictOnValues[K: ClassTag](data: DStream[(K, Vector)]): DStream[(K, Int)] = {
242-
this.isInitialized
242+
this.assertInitialized()
243243
data.mapValues(model.predict)
244244
}
245245

246-
/**
247-
* Check whether cluster centers have been initialized.
248-
*
249-
* @return Boolean, True if cluster centrs have been initialized
250-
*/
251-
def isInitialized: Boolean = {
246+
/** Check whether cluster centers have been initialized.*/
247+
def assertInitialized(): Unit = {
252248
if (Option(model.clusterCenters) == None) {
253-
logError("Initial cluster centers must be set before starting predictions")
254-
throw new IllegalArgumentException
255-
} else {
256-
true
249+
throw new IllegalStateException("Initial cluster centers must be set before starting predictions")
257250
}
258251
}
259252

0 commit comments

Comments
 (0)