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
CodePudding user response:
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))