Problem slicing and indexing DenseMatrix and DenseVector

229 views
Skip to first unread message

absalom_hicks

unread,
Jun 18, 2016, 4:11:56 PM6/18/16
to Scala Breeze
Hello,

I cannot understand why the first part in Test::foo works but the second does not.
This also presents a problem since I cannot write even simple functions,
such as Test::bar below.

I would be very grateful for an explanation and workaround to make functions like Test::bar
work.

    import breeze.linalg.DenseMatrix
   
import breeze.linalg.DenseVector

   
class Test {

        val dim
= 3
        val X
:DenseMatrix[Double] = DenseMatrix.rand(dim,dim)
        val u
:DenseVector[Double] = DenseVector.fill(dim){1.0}

       
def foo:Unit = {

            val i
=0;
            val row_i
:DenseVector[Double] = X(i,::).t  // OK
            val s
= u(i)+u(i)                          // OK

            val j
:Integer = 0
            val row_j
:DenseVector[Double] = X(j,::).t  // does not compile (A)
            val a
= u(j)+u(j)                          // does not compile (B)
       
}
       
def bar(i:Integer):Double = u(i)+u(i)          // does not compile (C)
   
}





Compilation errors:

(A) could not find implicit value for parameter canSlice:
breeze.linalg.support.CanSlice2[breeze.linalg.DenseMatrix[Double],Integer,collection.immutable.::.type,Result]
     
not enough arguments for method apply:
(implicit canSlice: breeze.linalg.support.CanSlice2[breeze.linalg.DenseMatrix[Double],Integer,collection.immutable.::.type,Result])
Result in trait TensorLike.
Unspecified value parameter canSlice.
      


(B), (C)

could not find implicit value for parameter canSlice:
breeze.linalg.support.CanSlice[breeze.linalg.DenseVector[Double],Integer,Result]
     
not enough arguments for method apply:
(implicit canSlice: breeze.linalg.support.CanSlice[breeze.linalg.DenseVector[Double],Integer,Result])Result in trait TensorLike.
Unspecified value parameter canSlice.

David Hall

unread,
Jun 18, 2016, 11:07:17 PM6/18/16
to scala-...@googlegroups.com
Breeze doesn't always do the right thing with type conversions, including autoboxing and even things like Int to Double promotion. It's a structural thing that is hard to fix without adding a lot more code bloat and a lot more classes (and slowing down compile times more)

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/18f0f2dd-1993-47b9-89f1-5db81f542ff7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages