3 and 4 dimensional Tensors

120 views
Skip to first unread message

Alexander Ulanov

unread,
Dec 15, 2015, 2:44:11 PM12/15/15
to Scala Breeze
Dear Breeze developers,

Is it possible to declare a 3 and 4 dimensional tensor? If not, what would be a simple way of implementing it with the current Breeze API?

Best regards, Alexander

David Hall

unread,
Dec 15, 2015, 3:58:17 PM12/15/15
to scala-...@googlegroups.com
It's not. I have a bit of decision paralysis when it comes to this and data frames that amount to basically the same thing: do we want a single TensorN, which allows for dynamically choosing the number of axes, or do we want Tensor3, Tensor4, etc, which gives us static type safety. (Or one could do TensorN and enforce dimensions at compile time as well, but it seems hard to do that and allow for dynamically choosing the arity)

To implement TensorN, just implement DenseTensorN[V] extends Tensor[IndexedSeq[Int], V]. To do Tensor3/Tensor4, do DenseTensor3[V] extends Tensor[(Int, Int, Int), V] etc.

-- David

--
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/764fc9ae-4a1f-49e3-8bd9-cedcdb9e9ec5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Ulanov

unread,
Dec 15, 2015, 6:31:08 PM12/15/15
to Scala Breeze
Hi David,

Thank you for the suggestion! Let me clarify my use case. I am currently using DenseVector and DenseMatrix for the implementation of MultilayerPerceptron for Spark. I would like to switch to tensors to support multidimensional data. I need a wrapper for a (part of) Array[Double/Float] that will be able to re-shape to 1, 2, or 3 dimensions. That is, I need just a small subset of features. Do you think I should use Breeze API?

Best regards, Alexander

David Hall

unread,
Dec 15, 2015, 6:37:01 PM12/15/15
to scala-...@googlegroups.com
I guess it depends on what you want to do with it. If you just want indexing and maybe some slicing, it shouldn't be too bad. If you want something more complex than that, there's probably a lot of work to do.

Alexander Ulanov

unread,
Dec 15, 2015, 7:11:29 PM12/15/15
to Scala Breeze
I am thinking about something like Caffe's blob: http://caffe.berkeleyvision.org/doxygen/classcaffe_1_1Blob.html

David Hall

unread,
Dec 15, 2015, 7:15:45 PM12/15/15
to scala-...@googlegroups.com
yeah, shouldn't be too bad. You'd have to write most of the reshaping and indexing yourself, but if you implemented the core type classes (https://github.com/scalanlp/breeze/wiki/Universal-Functions#enabling-ufuncs-for-your-collection-type) you'd get most of the basic breeze functionality working. (No binary operators though, I think.)



Alexander Ulanov

unread,
Dec 15, 2015, 7:55:19 PM12/15/15
to Scala Breeze
Thank you for the comment. Actually, I don't find UFunc useful for my case because I want to apply arbitrary functions in place (we had a discussion earlier about this: https://groups.google.com/forum/#!topic/scala-breeze/OTlDf_IItgY). I had to implement something like def apply(x: BDM[Double], y: BDM[Double], func: Double => Double): Unit that apply the function inside the loop. Another problem is related to in-place GEMM and GEMV. I had to write def dgemm(alpha: Double, a: BDM[Double], b: BDM[Double], beta: Double, c: BDM[Double]): Unit that calls netlib-java. Now, I need to implement tensors. My concern is that the amount of Breeze features that I use is rather small comparing to the features that I need to implement. Please, correct me if I am wrong.

David Hall

unread,
Dec 15, 2015, 7:59:04 PM12/15/15
to scala-...@googlegroups.com
that's entirely possible, honestly.

Right, I forgot about the inplace stuff, but it's definitely a problem with how breeze works right now. I know how to fix it, but it's a long process I don't have the bandwidth for.

Reply all
Reply to author
Forward
0 new messages