gsl_matrix__copy_source.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* matrix/copy_source.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
  4. *
  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.
  9. *
  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.
  14. *
  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.
  18. */
  19. int
  20. FUNCTION (gsl_matrix, memcpy) (TYPE (gsl_matrix) * dest,
  21. const TYPE (gsl_matrix) * src)
  22. {
  23. const size_t src_size1 = src->size1;
  24. const size_t src_size2 = src->size2;
  25. const size_t dest_size1 = dest->size1;
  26. const size_t dest_size2 = dest->size2;
  27. if (src_size1 != dest_size1 || src_size2 != dest_size2)
  28. {
  29. GSL_ERROR ("matrix sizes are different", GSL_EBADLEN);
  30. }
  31. {
  32. const size_t src_tda = src->tda ;
  33. const size_t dest_tda = dest->tda ;
  34. size_t i, j;
  35. for (i = 0; i < src_size1 ; i++)
  36. {
  37. for (j = 0; j < MULTIPLICITY * src_size2; j++)
  38. {
  39. dest->data[MULTIPLICITY * dest_tda * i + j]
  40. = src->data[MULTIPLICITY * src_tda * i + j];
  41. }
  42. }
  43. }
  44. return GSL_SUCCESS;
  45. }
  46. int
  47. FUNCTION (gsl_matrix, swap) (TYPE (gsl_matrix) * dest, TYPE (gsl_matrix) * src)
  48. {
  49. const size_t src_size1 = src->size1;
  50. const size_t src_size2 = src->size2;
  51. const size_t dest_size1 = dest->size1;
  52. const size_t dest_size2 = dest->size2;
  53. if (src_size1 != dest_size1 || src_size2 != dest_size2)
  54. {
  55. GSL_ERROR ("matrix sizes are different", GSL_EBADLEN);
  56. }
  57. {
  58. const size_t src_tda = src->tda ;
  59. const size_t dest_tda = dest->tda ;
  60. size_t i, j;
  61. for (i = 0; i < src_size1 ; i++)
  62. {
  63. for (j = 0; j < MULTIPLICITY * src_size2; j++)
  64. {
  65. ATOMIC tmp = src->data[MULTIPLICITY * src_tda * i + j];
  66. src->data[MULTIPLICITY * src_tda * i + j]
  67. = dest->data[MULTIPLICITY * dest_tda * i + j];
  68. dest->data[MULTIPLICITY * dest_tda * i + j] = tmp ;
  69. }
  70. }
  71. }
  72. return GSL_SUCCESS;
  73. }