Github user feynmanliang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9678#discussion_r44721007
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/clustering/LDA.scala ---
    @@ -480,58 +494,38 @@ class DistributedLDAModel private[ml] (
         vocabSize: Int,
         private val oldDistributedModel: OldDistributedLDAModel,
         sqlContext: SQLContext)
    -  extends LDAModel(uid, vocabSize, None, sqlContext) {
    +  extends LDAModel(uid, vocabSize, sqlContext) {
    +
    +  /** Used to implement [[oldLocalModel]] as a lazy val, but with cheap 
[[copy()]] */
    +  private var oldLocalModelOption: Option[OldLocalLDAModel] = None
    +
    +  override protected def oldLocalModel: OldLocalLDAModel = {
    +    if (oldLocalModelOption.isEmpty) {
    +      oldLocalModelOption = Some(oldDistributedModel.toLocal)
    +    }
    +    oldLocalModelOption.get
    +  }
    +
    +  override protected def getModel: OldLDAModel = oldDistributedModel
     
       /**
        * Convert this distributed model to a local representation.  This 
discards info about the
        * training dataset.
        */
       @Since("1.6.0")
    -  def toLocal: LDAModel = {
    -    if (oldLocalModel.isEmpty) {
    -      oldLocalModel = Some(oldDistributedModel.toLocal)
    -    }
    -    new LDAModel(uid, vocabSize, oldLocalModel, sqlContext)
    -  }
    -
    -  @Since("1.6.0")
    -  override protected def getModel: OldLDAModel = oldDistributedModel
    +  def toLocal: LocalLDAModel = new LocalLDAModel(uid, vocabSize, 
oldLocalModel, sqlContext)
     
       @Since("1.6.0")
       override def copy(extra: ParamMap): DistributedLDAModel = {
         val copied = new DistributedLDAModel(uid, vocabSize, 
oldDistributedModel, sqlContext)
    -    if (oldLocalModel.nonEmpty) copied.oldLocalModel = oldLocalModel
    +    copied.oldLocalModelOption = oldLocalModelOption
    --- End diff --
    
    Any harm in making `oldLocalModelOption` part of the constructor and 
avoiding this private var access?


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to