RE: tensor() function and sets

About this list Date view Thread view Subject view Author view Other groups

Subject: RE: tensor() function and sets
From: Jonathan Rougier (
Date: Thu 22 Jul 1999 - 19:11:50 EST

Message-ID: <Pine.GSO.3.96.990722094020.10355D-100000@laplace>

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

> 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
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:

About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:06 EST