/* tensor/swap_source.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman, Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * t_ int FUNCTION (gsl_tensor, swap_indices) (TYPE (gsl_tensor) * t, ) { const size_t size1 = m->size1; const size_t size2 = m->size2; size_t i, j, k; if (size1 != size2) { GSL_ERROR ("tensor must be square to take transpose", GSL_ENOTSQR); } for (i = 0; i < size1; i++) { for (j = i + 1 ; j < size2 ; j++) { for (k = 0; k < MULTIPLICITY; k++) { size_t e1 = (i * m->tda + j) * MULTIPLICITY + k ; size_t e2 = (j * m->tda + i) * MULTIPLICITY + k ; { ATOMIC tmp = m->data[e1] ; m->data[e1] = m->data[e2] ; m->data[e2] = tmp ; } } } } return GSL_SUCCESS; } int FUNCTION (gsl_tensor, transpose_memcpy) (TYPE (gsl_tensor) * dest, const TYPE (gsl_tensor) * src) { const size_t src_size1 = src->size1; const size_t src_size2 = src->size2; const size_t dest_size1 = dest->size1; const size_t dest_size2 = dest->size2; size_t i, j, k; if (dest_size2 != src_size1 || dest_size1 != src_size2) { GSL_ERROR ("dimensions of dest tensor must be transpose of src tensor", GSL_EBADLEN); } for (i = 0; i < dest_size1; i++) { for (j = 0 ; j < dest_size2; j++) { for (k = 0; k < MULTIPLICITY; k++) { size_t e1 = (i * dest->tda + j) * MULTIPLICITY + k ; size_t e2 = (j * src->tda + i) * MULTIPLICITY + k ; dest->data[e1] = src->data[e2] ; } } } return GSL_SUCCESS; }