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

Possible issue with Matrix/Tensor2 apply #44

Closed afwlehmann closed 12 years ago

afwlehmann commented 12 years ago

There might be a small glitch concerning Matrix's or Tensor2's apply method:

scala> foo(0 until 2, ::)
res1: scalala.tensor.mutable.Matrix[Int] = 
1  2  3  4  
5  6  7  8  

scala> foo(::, 0 until 2)
res2: scalala.tensor.mutable.Matrix[Int] = 
1  2  
5  6 

Up to this place, everything works just fine. But then

scala> foo(1, 0 until 2)
res3: scalala.tensor.mutable.Vector[Int] = 
0 5
1 6

I would have expected a view of the first elements of foo's second row. Furthermore:

scala> foo(5, 0 until 2)
res4: scalala.tensor.mutable.Vector[Int] = 
0 7
1 8

scala> foo(99, 0 until 2)
java.lang.ArrayIndexOutOfBoundsException: 99
    at scala.runtime.ScalaRunTime$.array_apply(ScalaRunTime.scala:54)
    at scalala.tensor.dense.DenseVectorRow.apply(DenseVector.scala:411)
    at scalala.tensor.dense.DenseVectorRow.apply(DenseVector.scala:402)
        ...

It might as well be that this is really two issues, one between my ears and the other allowing invalid array indices :)

dramage commented 12 years ago

This isn't as bad a problem as it looks. What's actually happening is that the slice isn't returning a shaped vector - and so it isn't using a shaped toString (either a VectorRow or VectorCol implementation). It's using the default Tensor toString, which prints out all elements as "%key %value" - i.e. 0 and 1 are the indexes (in the slice) of the elements you asked it to pull out.

dramage commented 12 years ago

Fixed as of ec4f4318eb