Closed afwlehmann closed 13 years ago
Nope inner product is only defined for shaped tensors (DenseVectorRow * DenseVectorCol). What code snippet got you here?
Ok, I see. I thought I'd be able to use `dot' for convenience so that I wouldn't have to e.g. do something like x.t * x for a DenseVectorCol. However, I think it's perfectly ok if you force the user to use explicit notation which in turn will prevent many common mistakes from happening.
Actually you were right in your first post - the dot products should work as you thought they would. I thought you were talking about the * operator, which can't use without shaped tensors. However, you can indeed call the "dot" method just as you thought you should be able to. The problem you saw was the fact that there wasn't a way to OpMul Boolean and Double. I just added that in:
https://github.com/scalala/Scalala/commit/13bfbf2c04022500a35d58db8ad15b77625a2411
scala> val x = scalala.tensor.dense.DenseVector(1,2,3) x: scalala.tensor.dense.DenseVectorCol[Int] = 1 2 3
scala> x dot x res0: Int = 14
scala> x dot x.t res1: Int = 14
scala> x.t dot x res2: Int = 14
scala> x.t * x res3: Int = 14
scala> x * x.t
res4: scalala.tensor.dense.DenseMatrix[Int] =
1 2 3
2 4 6
3 6 9
scala> x dot x res5: Int = 14
scala> (x : scalala.tensor.dense.DenseVector[Int]) dot x res6: Int = 14
scala> (x : scalala.tensor.dense.DenseVector[Int]) dot x.t res7: Int = 14
scala> x dot x > 1 res0: Int = 5
scala> x dot (x > 1) res1: Int = 5
scala> (x > 1) dot x res2: Int = 5
scala> x * (x > 1)
Thanks for checking back on this!
Interestingly enough, in my particular case the expression if (mu dot mu > 0) { ... }
produced the error message. Since I didn't expect the operator precedence to be like (mu dot (mu > 0)) I overlooked that the error messages talked about Double and Boolean.
Actually that's a pretty big problem! Thanks for pointing it out. Comparison operators now require the : (e.g. :> :< etc) to prevent exactly this kind of thing as of https://github.com/scalala/Scalala/commit/5f948e93e73b87af93b6436be129ff77e0e461ed
For a given DenseVector v, the dot-product v dot v fails with
error: Could not find a way to scalala.operators.OpMulInner values of type scalala.tensor.dense.DenseVector[Double] and scalala.tensor.dense.DenseVectorCol[Boolean]
This looks like a missing implicit?