scalanlp / breeze

Breeze is a numerical processing library for Scala.
www.scalanlp.org
Apache License 2.0
3.44k stars 691 forks source link

Elementwise multiplication - operation example or explanation for implicit #829

Closed minnieshi closed 2 years ago

minnieshi commented 2 years ago

Hello,

I would love to get some help to make below working, i have trouble understanding the signature in terms of the implicits required. it would be highly appreciated if the answer gives me some link to do further study.

I intend to multiply the elements by elements for the matching index, so below i expect it to return

0  0
4  5

code below:

import breeze.linalg.DenseMatrix.ones
import breeze.linalg.{*, DenseMatrix}
import spire.implicits.rightModuleOps

val m1=DenseMatrix((1,2),(4,5));
val m2=DenseMatrix((0,0),(1,1))
m1 :* m2

it has error when i try to compile

could not find implicit value for parameter ev: spire.algebra.RightModule[breeze.linalg.DenseMatrix[Int],breeze.linalg.DenseMatrix[Int]]

output in console for creating the m1 and m2

val m1: breeze.linalg.DenseMatrix[Int] =
1  2
4  5
val m2: breeze.linalg.DenseMatrix[Int] =
0  0
1  1

what should I do to get create/load/import the required implict? what is the implicit trying to do?

minnieshi commented 2 years ago

oh.... maybe i should have used :*=, i just found it in the code base when searching for :*

dlwh commented 2 years ago

Sorry for being slow. The operator for elementwise multiplication is now *:* because it has better precedence behavior