zhengruifeng commented on a change in pull request #30548:
URL: https://github.com/apache/spark/pull/30548#discussion_r534607937
##########
File path: mllib/src/main/scala/org/apache/spark/mllib/feature/Word2Vec.scala
##########
@@ -502,19 +502,19 @@ class Word2VecModel private[spark] (
private val vectorSize = wordVectors.length / numWords
// wordList: Ordered list of words obtained from wordIndex.
- private val wordList: Array[String] = {
- val (wl, _) = wordIndex.toSeq.sortBy(_._2).unzip
- wl.toArray
+ private lazy val wordList: Array[String] = {
+ wordIndex.toSeq.sortBy(_._2).iterator.map(_._1).toArray
}
// wordVecNorms: Array of length numWords, each value being the Euclidean
norm
// of the wordVector.
- private val wordVecNorms: Array[Float] = {
- val wordVecNorms = new Array[Float](numWords)
+ private lazy val wordVecNorms: Array[Float] = {
Review comment:
this var `wordVecNorms` is only used in method `findSynonyms` in the
.mllib.w2v; however, this `findSynonyms` is never used in the .ml side. So I
think we can make it lazy.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]