[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-gsl] Copy matrix from the one do not has tda to the other one

**From**: |
Francesco Abbate |

**Subject**: |
Re: [Help-gsl] Copy matrix from the one do not has tda to the other one that has tda |

**Date**: |
Wed, 11 Jan 2012 08:51:51 +0100 |

2012/1/10 liufenglai <address@hidden>:
>* Hi Everyone,*
>
>* I constructed several matrices, one of them has tda and is imported from*
>* the outside data:*
>* gsl_matrix_view M1 = gsl_matrix_view_array_with_tda(M,row,col,ld);*
>* I also constructed a gsl_matrix named as M2;*
>* gsl_matrix* M2 = gsl_matrix_alloc(row,col);*
>* after some calculations I want to copy the data in M2 back to the M1.*
>* However, M1 could be some submatrix of the original one, and M2 is some*
>* full matrix. I am going to call the gsl_matrix_memcpy, I do not whether*
>* it will takes care of the situation above?*
Hi,
all the GSL matrix functions are safe to be used in any matrix, the
tda will always be taken into account correctly.
Here the code that perform the matrix copy:
int
FUNCTION (gsl_matrix, memcpy) (TYPE (gsl_matrix) * dest,
const TYPE (gsl_matrix) * 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;
if (src_size1 != dest_size1 || src_size2 != dest_size2)
{
GSL_ERROR ("matrix sizes are different", GSL_EBADLEN);
}
{
const size_t src_tda = src->tda ;
const size_t dest_tda = dest->tda ;
size_t i, j;
for (i = 0; i < src_size1 ; i++)
{
for (j = 0; j < MULTIPLICITY * src_size2; j++)
{
dest->data[MULTIPLICITY * dest_tda * i + j]
= src->data[MULTIPLICITY * src_tda * i + j];
}
}
}
return GSL_SUCCESS;
}
As you can see the tda is taken into account for both the source and
destination matrix.
Best regards,
Francesco