2

我尝试对 Breeze ( https://github.com/scalanlp/breeze ) DenseVector 类 ( http://www.scalanlp.org/api/breeze/#breeze.linalg.DenseVector ) 的对象进行酸洗和解酸。不需要添加任何自定义pickler。酸洗成功时,解酸会引发 scala.MatchError。代码如下所示。任何调试此问题的帮助/指针表示赞赏!有趣的是,我能够毫无问题地腌制/取消腌制 DenseMatrix。

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)

输出是:

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
4

0 回答 0