1 /* matrix/copy_source.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 FUNCTION (gsl_matrix, memcpy) (TYPE (gsl_matrix) * dest,
22 const TYPE (gsl_matrix) * src)
24 const size_t src_size1 = src->size1;
25 const size_t src_size2 = src->size2;
26 const size_t dest_size1 = dest->size1;
27 const size_t dest_size2 = dest->size2;
29 if (src_size1 != dest_size1 || src_size2 != dest_size2)
31 GSL_ERROR ("matrix sizes are different", GSL_EBADLEN);
35 const size_t src_tda = src->tda ;
36 const size_t dest_tda = dest->tda ;
39 for (i = 0; i < src_size1 ; i++)
41 for (j = 0; j < MULTIPLICITY * src_size2; j++)
43 dest->data[MULTIPLICITY * dest_tda * i + j]
44 = src->data[MULTIPLICITY * src_tda * i + j];
54 FUNCTION (gsl_matrix, swap) (TYPE (gsl_matrix) * dest, TYPE (gsl_matrix) * src)
56 const size_t src_size1 = src->size1;
57 const size_t src_size2 = src->size2;
58 const size_t dest_size1 = dest->size1;
59 const size_t dest_size2 = dest->size2;
61 if (src_size1 != dest_size1 || src_size2 != dest_size2)
63 GSL_ERROR ("matrix sizes are different", GSL_EBADLEN);
67 const size_t src_tda = src->tda ;
68 const size_t dest_tda = dest->tda ;
71 for (i = 0; i < src_size1 ; i++)
73 for (j = 0; j < MULTIPLICITY * src_size2; j++)
75 ATOMIC tmp = src->data[MULTIPLICITY * src_tda * i + j];
76 src->data[MULTIPLICITY * src_tda * i + j]
77 = dest->data[MULTIPLICITY * dest_tda * i + j];
78 dest->data[MULTIPLICITY * dest_tda * i + j] = tmp ;