scalala / Scalala

Scalala has been superseded by dlwh/breeze. Scalala is a high performance numeric linear algebra library for Scala, with rich Matlab-like operators on vectors and matrices; a library of numerical routines; support for plotting.
http://groups.google.com/group/scalala
GNU Lesser General Public License v2.1
298 stars 30 forks source link

test showing how wrong operator is picked if DenseVector is up casted (jo #19

Closed gbasler closed 13 years ago

gbasler commented 13 years ago

Please have a look at this test case.

If I cast a DenseVector to a Tensor and do something like a :-= b then the wrong operator implementation and some optimization kicks. If an operation on an element results to zero then that operation is executed again... (Tensor.Scala: joinEitherNonZero)

dramage commented 13 years ago

Thanks for filing this. I can't reopen the issue on github because it's a pull request, but rest assured the issue itself is not closed.

dramage commented 13 years ago

Fixed in c94437f33e78ee93f65c.

The bug isn't actually it's picking the wrong implementation. There's no way for it to pick the right one without the static type. In other words, you can't write generic Scalala code using the more general types and have any hope it will be efficient. You have to do everything with the implementation types or with generic parametrized types and take the appropriate implicits for doing math on them.

The bug is in the default Tensor implementation of CanJoin.joinEitherNonZero when the left argument mutates.