1
scala> val B = DenseMatrix((0.5,0.2,0.3),
                        (0.1,0.4,0.5),
                        (0.25,0.35,0.4),
                        (0.6,0.2,0.2),
                        (0.7,0.1,0.2))


scala> (B *:* B)(::,1)
<console>:38: error: too many arguments for method *:*: (implicit op: breeze.linalg.operators.OpMulScalar.Impl2[breeze.linalg.DenseMatrix[Double],breeze.linalg.DenseMatrix[Double],That])That
       (B *:* B)(::,1)

However if I tweak the code a little bit with double transpose, it works. What caused the error and is there any other way to work around it.

scala> (B *:* B).t.t(::,1)
res317: breeze.linalg.DenseVector[Double] = DenseVector(0.25, 0.010000000000000002, 0.0625, 0.36, 0.48999999999999994)
Jack Chen
  • 77
  • 7

1 Answers1

1

This is because of how implicits work in Scala.

 (B *:* B)(::,1)

expands as:

 B.*:*(B)(::,1)

but *:* is defined as (simplifying a bit):

def *:*[U, R](u: U)(implicit op: OpMulScalar.Impl2[T, U, R])

so Scala thinks you're trying to pass (::, 1) as an implicit argument. It's pretty annoying, admittedly.

To fix it, you can use your solution, or

 (B *:* B).apply(::,1)

or extract (B *:* B) as a val.

dlwh
  • 2,257
  • 11
  • 23