Search code examples
scala-breeze

How to implements multiplication of DenseMatrix[BigDecimal] in Breeze?


My Codes are as below:

val bigArrs = Array(BigDecimal(1),BigDecimal(2))
val dm = new DenseMatrix[BigDecimal](2,1,bigArrs)
val cal = dm*dm.t

when I compile it,I'm getting the following compilation errors:

Error:(11, 15) diverging implicit expansion for type breeze.linalg.operators.OpMulMatrix.
Impl2[breeze.linalg.DenseMatrix[BigDecimal],breeze.linalg.DenseMatrix[BigDecimal],That]
starting with method canMulM_M_def in trait DenseMatrixOpsLowPrio
val cal = dm*dm.t
          ^
Error:(11, 15) not enough arguments for method *: (implicit op: breeze.linalg.operators.OpMulMatrix.Impl2
[breeze.linalg.DenseMatrix[BigDecimal],breeze.linalg.DenseMatrix[BigDecimal],That])That.
Unspecified value parameter op.
val cal = dm*dm.t
          ^

I am asking how to implement multiplication or addition on DenseMatrix[BigDecimal] in Breeze. I have read the https://github.com/scalanlp/breeze/wiki/Universal-Functions#enabling-ufuncs-for-your-collection-type and http://dlwh.org/tag/breeze/ trying to solve it. However,as a newer to Breeze and scala,it is really a little hard for me to finish these codes.Hope someone will do me a favor!


Solution

  •  val d = dm.*(dm.t)(DenseMatrix.op_DM_DM_Semiring[BigDecimal])
    

    This will work.Any operation of matrix can do like this.If the type of your return value is nothing,it may be that you have not apply an implicit parameter(as I showed in the second bracket).