package tensor

Jordi Burguet Castell jordi.burguet.castell@cern.ch
Sat Nov 6 03:24:00 GMT 2004


Hi,

I have prepared a package to do tensor manipulation. It is the update of a 
version I did some time ago but which did not work well for some subtle bug 
(I've talked about it before in the list, so you probably know that already). 
Now it is fixed and all the basic functions are working.

Some comments:
* it is a package, following the recent suggestion by Brian
* it is fully functional, complex numbers excluded.
* its interface mimics that of gsl_matrix
* it still uses varargs, though I am considering to use int* for the set of 
tensor indices instead.
* I am working on a modified version, "gtensor", which allows for different 
dimensions on each index, suited for multidimensional grids (but then, not 
for operations such as tensor product or index contraction).

To try it one just needs to
     $ bunzip2 tensor-0.9.tar.bz2
     $ tar xvf tensor-0.9.tar 
     $ cd tensor-0.9
     $ ./autogen.sh && ./configure && make && make check && make install
     $ ...
     $ gcc -Wall main.c -lgsltensor -lgsl -lgslcblas -lm


And finally an example:

/* define a 2x2x2 "cube" (rank=3, dimension=2)
 * t = [ [ [1 2] [3 4] ] [ [5 6] ] [ [7 8] ] ]
 */
gsl_tensor * t = gsl_tensor_alloc(3, 2);
count = 1;
for (i = 0; i < 2; i++)
  for (j = 0; j < 2; j++)
    for (k = 0; k < 2; k++)
       gsl_tensor_set(t, count++, i,j,k);  /* rank 3, 3 indices */

/* when we contract indices 0,1 we get a tensor of rank 1 (a vector) */
gsl_tensor * v = gsl_tensor_contract(t, 0, 1);

for (i = 0; i < 2; i++)
  printf("%g\t", gsl_tensor_get(v, i));  /* rank 1, so just 1 index */

/* swapping indices generalizes the transpose of a matrix */
gsl_tensor * tt = gsl_tensor_swap_indices(t, 1, 2);

/* the tensor product creates tensors of higher rank */
gsl_tensor * p = gsl_tensor_product(t, v);


The attached file contains the code. Enjoy,
Jordi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tensor-0.9.tar.bz2
Type: application/x-tbz
Size: 64066 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gsl-discuss/attachments/20041106/d4585947/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gsl-discuss/attachments/20041106/d4585947/attachment.sig>


More information about the Gsl-discuss mailing list