scalanlp/breeze — pull request #165 by ktakagaki (2014-03-01 18:48:42+00:00)
Title: Tuple pimper

Hi David,

This is kind of random, maybe out of left field... could you take a look?

I rigged up a mechanism to do this:
`````
scala> val temp = (0, 1, 2, 3, 4).v
temp: breeze.linalg.DenseVector[Int] = DenseVector(0, 1, 2, 3, 4)

scala> val temp2 = (0, 1.5, 2, 3, 4).v
temp: breeze.linalg.DenseVector[Double] = DenseVector(0.0, 1.5, 2.0, 3.0, 4.0)
`````
I'm starting to grow fond of breeze, and I was wondering if something like this would lower the bar for entry. I mean, for real use, DenseVector( ......)/DenseMatrix( ......) as constructors are totally fine, but it does look kind of clunky in the examples. The syntax is loosely inspired by the `"""regex""".r` notation.

Using Tuple this way is probably a complete travesty/hack in terms of language design, good programming, etc, but the problem I see with more elegant approaches is that all of the usual vector/matrix specifiers () [] {} are all reserved in Scala, and I think we don't want to get too esoteric with the symbols if we can avoid it. Tuple would only go to 22, but I think that's fine... beyond that, not many people would want to enter data in a REPL anyway. One thing that forces this approach to be particularly hackish is that the only common parent to the Tuple classes is Product...

I also considered implicitly converting tuples to DenseVector and/or DenseMatrix, but I'm not sure it's useful because then you would have to go
`````
scala> val temp: DenseVector[Int] = (0, 1, 2, 3, 4).v
`````
which would defeat the purpose. The other thing I was thinking of was to have a short-name constructor like `v(0, 1, 2, 3, 4)`, but that wouldn't really jibe with the scala/breeze naming conventions

Please tell me what you think, I'm sure you at least have some suggestions for improvement, etc. I'm totally open to your saying it's just a clunky hack, not necessary. If it's somehow a salvageable idea, I'll fill it out to work up to arity 22 and also to work for DenseMatrices with `((....), (.....), (.....), (.....)).m` (That would, however, cause a slight dissonance because we are entering row-major like, and it would be converted to column-major I guess for DenseMatrix.)

Sincerely,
Kenta