0

There are plenty of other questions round the error message could not find implicit value in Scala. The answers are very specific and are not applicable to this specific issue.

In Scala Breeze, I am trying to apply argmax to a SparseVector[Int]. According to the documentation (and intuition), this works easily with

argmax(SparseVector.zeros[Int](5))

after importing breeze.linalg._.

My actual testing code looks like this:

import breeze.linalg.{Vector, argmax, sum}

val counts: Map[Int, Vector[Int]] = ...
counts
  .filter(e => sum(e._2) > 10)
  .take(100)
  .map(e => (e._1, argmax(e._2)))
  .foreach(println)

However, the compiler throws the following error message:

Error:(41, 37) could not find implicit value for parameter impl: breeze.linalg.argmax.Impl[breeze.linalg.Vector[Int],VR]
.map(e => (e._1, argmax(e._2)))
                       ^

Some more or less surprising observations:

  • the sum(e._2) seems to compile fine.
  • using a DenseVector instead of of SparseVector internally does not change anything

How could I solve this or at least narrow down the root cause.

4

1 回答 1

0

我通过明确声明类型SparseVector而不是解决了这个问题Vector

val counts: Map[Int, SparseVector[Int]] = ...

据我了解,这个解决方案远非显而易见,我仍然不清楚为什么argmax()似乎无法处理更通用的Vector类,但它确实有效。

于 2015-11-13T10:09:16.520 回答