2

I tried pickling and unpickling an object of Breeze's (https://github.com/scalanlp/breeze) DenseVector class (http://www.scalanlp.org/api/breeze/#breeze.linalg.DenseVector). Didn't need to add any custom picklers. While pickling succeeded, unpickling threw scala.MatchError. Code is shown below. Any help/pointers in debugging this problem appreciated! Interestingly enough, I was able to pickle/unpickle DenseMatrix without any issue.

import scala.pickling._
import scala.pickling.Defaults._
import json._
import breeze.linalg.DenseVector

val vec = DenseVector(1.1, 2.2)
val pickledVec = vec.pickle
println(pickledVec)

val unpickledVec = pickledVec.unpickle[DenseVector[Double]]
println(unpickledVec)

And the output is:

JSONPickle({
  "$type": "breeze.linalg.DenseVector$mcD$sp",
  "data": [
    1.1,
    2.2
  ],
  "offset": 0,
  "stride": 1,
  "length": 2,
  "noOffsetOrStride": true
})

scala.MatchError: [1.1, 2.2] (of class scala.util.parsing.json.JSONArray)
  at scala.pickling.json.JSONPickleReader.readField(JSONPickleFormat.scala:244)
  at scala.pickling.json.JSONPickleReader.beginCollection(JSONPickleFormat.scala:249)
  at scala.pickling.runtime.RuntimePicklersUnpicklers$$anon$1.unpickle(CustomRuntime.scala:110)
  at scala.pickling.runtime.InterpretedUnpicklerRuntime$$anon$4$$anonfun$fieldVals$1$1.apply(Runtime.scala:225)
  at scala.pickling.runtime.InterpretedUnpicklerRuntime$$anon$4$$anonfun$fieldVals$1$1.apply(Runtime.scala:200)
  at scala.collection.immutable.List.map(List.scala:273)
  at scala.pickling.runtime.InterpretedUnpicklerRuntime$$anon$4.fieldVals$1(Runtime.scala:200)
  at scala.pickling.runtime.InterpretedUnpicklerRuntime$$anon$4.unpickle(Runtime.scala:242)
  at BreezeLinalgDenseVector$u005BscalaDouble$u005DUnpickler$macro$4$2$.unpickle(<console>:24)
  at scala.pickling.Unpickler$class.unpickleEntry(Pickler.scala:79)
  at BreezeLinalgDenseVector$u005BscalaDouble$u005DUnpickler$macro$4$2$.unpickleEntry(<console>:24)
  at scala.pickling.functions$.unpickle(functions.scala:11)
  at scala.pickling.UnpickleOps.unpickle(Ops.scala:23)
  ... 53 elided
devendraj
  • 21
  • 3
  • It seems the unpickler has some difficulties with DenseVector being @specialized for Double. The unpickler does not attempt to read the array as Array[Double], but expects an JSON object with additional type info. – Michal Příhoda Apr 13 '16 at 10:08

0 Answers0