0

When trying to create a dense matrix of type Option with Scala 3 I receive an error.

  val dm1 = DenseMatrix((1,2),(1,2))   // <- this works
  val dm2 = DenseMatrix((Some(1),Some(2)),(Some(1),Some(2)))  <- doesn't work

Error: no implicit argument of type breeze.storage.Zero[V] was found for parameter zero of method apply in trait MatrixConstructors

Btw, it is working in Scastie and Scala 2.

https://scastie.scala-lang.org/89HUyuXNQrqWDPNpRbtrOw

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
Sven
  • 85
  • 2
  • 9

2 Answers2

2

Try to add necessary implicit

implicit val optIntZero: Zero[Option[Int]] = Zero(Some(0))
implicit val someIntZero: Zero[Some[Int]] = Zero(Some(0))

or more generally

implicit def optZero[A](implicit zero: Zero[A]): Zero[Option[A]] = Zero(Some(zero.zero))
implicit def someZero[A](implicit zero: Zero[A]): Zero[Some[A]] = Zero(Some(zero.zero))

or just

implicit def someZero[F[t] >: Some[t], A](implicit zero: Zero[A]): Zero[F[A]] = Zero(Some(zero.zero))

Problem with evidence parameters in breeze

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
1

Another easy approach. Create a "simple type" matrix and map to to the target type.

val v = DenseVector(1, 1, 1)
val dm1 = DenseMatrix(v,v)
val dm2 = dm1.map( Some(_))
Sven
  • 85
  • 2
  • 9