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

    https://github.com/apache/spark/pull/2378#discussion_r17697102
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/api/python/PythonMLLibAPI.scala ---
    @@ -476,259 +436,167 @@ class PythonMLLibAPI extends Serializable {
           numRows: Long,
           numCols: Int,
           numPartitions: java.lang.Integer,
    -      seed: java.lang.Long): JavaRDD[Array[Byte]] = {
    +      seed: java.lang.Long): JavaRDD[Vector] = {
         val parts = getNumPartitionsOrDefault(numPartitions, jsc)
         val s = getSeedOrDefault(seed)
    -    RG.poissonVectorRDD(jsc.sc, mean, numRows, numCols, parts, 
s).map(SerDe.serializeDoubleVector)
    +    RG.poissonVectorRDD(jsc.sc, mean, numRows, numCols, parts, s)
       }
     
     }
     
     /**
    - * :: DeveloperApi ::
    - * MultivariateStatisticalSummary with Vector fields serialized.
    + * SerDe utility functions for PythonMLLibAPI.
      */
    -@DeveloperApi
    -class MultivariateStatisticalSummarySerialized(val summary: 
MultivariateStatisticalSummary)
    -  extends Serializable {
    +private[spark] object SerDe extends Serializable {
     
    -  def mean: Array[Byte] = SerDe.serializeDoubleVector(summary.mean)
    +  val PYSPARK_PACKAGE = "pyspark.mllib"
     
    -  def variance: Array[Byte] = SerDe.serializeDoubleVector(summary.variance)
    +  /**
    +   * Base class used for pickle
    +   */
    +  private[python] abstract class BasePickler[T: ClassTag]
    +    extends IObjectPickler with IObjectConstructor {
    +
    +    private val cls = implicitly[ClassTag[T]].runtimeClass
    +    private val module = PYSPARK_PACKAGE + "." + cls.getName.split('.')(4)
    +    private val name = cls.getSimpleName
    +
    +    // register this to Pickler and Unpickler
    +    def register(): Unit = {
    +      Pickler.registerCustomPickler(this.getClass, this)
    +      Pickler.registerCustomPickler(cls, this)
    +      Unpickler.registerConstructor(module, name, this)
    +    }
     
    -  def count: Long = summary.count
    +    def pickle(obj: Object, out: OutputStream, pickler: Pickler): Unit = {
    +      if (obj == this) {
    +        out.write(Opcodes.GLOBAL)
    +        out.write((module + "\n" + name + "\n").getBytes())
    +      } else {
    +        pickler.save(this)  // it will be memorized by Pickler
    +        saveState(obj, out, pickler)
    +        out.write(Opcodes.REDUCE)
    +      }
    +    }
    +
    +    private[python] def saveObjects(out: OutputStream, pickler: Pickler,
    +                                    objects: Any*) = {
    --- End diff --
    
    Can fit def on 1 line.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to