tensor() function and sets

Jonathan Rougier Jonathan Rougier <J.C.Rougier@durham.ac.uk>
Thu, 22 Jul 1999 10:11:50 +0100 (BST)


On Thu, 22 Jul 1999, Martyn Plummer wrote:

> I have some code that could certainly be tidied up with the tensor()
> function [1], but I wonder if "tensor" is the right name.
> 1) I would expect a function called "tensor" to construct a tensor object
>    rather than multiply two arrays together.
> 2) The arguments aren't tensors. They are arrays.

You are right of course!  I used the name `tensor' because in my notation
I use the tensor convention of summing over repeated indices.  Hence the
arguments da and db in the function are matched pairs of repeated indices.
But the name `aprod' would do just as well (it's rather unattractive
though!).

> How fast is it? It would be _really_ nice if this were done efficiently
> in C code.

It's reasonably fast as is, because it is just two aperms (which may be
degenerate) on top of a matrix product.  We are about to do some large
calculations which are extensively `tensorised' -- the largest object will
be the variance of a 100 by 100 by 10 array, which we have to divide into
5000 operations on 100 by 10 by 100 by 10 arrays (this will take hours
rather than minutes): oh for a sparse array class!  In case you are
wondering, our work is on prediction for large physical systems, eg oil
reservoirs, the weather, contaminated ground water plumes. 

But you could definitely argue that `aprod' is the primitive operation
that should be realised in C code, and then A %*% B is simply aprod(A, B,
2, 1) and outer(A, B, "*") could be aprod(A, B, NULL, NULL). 

Cheers, Jonathan.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE

"[B]egin upon the precept ... that the things we see are to be 
 weighed in the scale with what we know"  (Meredith, 1879, The Egoist)


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._