I am moving from Matlab to C + GSL, and I would like to know what is the most efficient way to calculate matrix B, for which:
B[i][j] = exp(A[i][j])
where I am in [0, Ny] and j in [0, Nx].
Note that this is different from the exponent of the matrix:
B = exp(A)
which can be executed with some unstable / unsupported code in GSL (linalg.h).
I just found a brute force solution (a couple of "for" loops), but is there a smarter way to do this?
EDIT
Drew Hall Solution Results
All results are from the 1024x1024 cycle for(for), in which two values are assigned at each iteration double(complex number). Time is the average time of more than 100 performances .
- [Row, Column} -Major :
- 226,56 "-" ( 1).
- 223.22 "-" ( 2).
- 224.60
gsl_matrix_complex_set, GSL ( 3).
1:
for(i=0; i<Nx; i++)
{
for(j=0; j<Ny; j++)
{
matrix[2*(i*s_tda + j)] = GSL_REAL(c_value);
matrix[2*(i*s_tda + j)+1] = GSL_IMAG(c_value);
}
}
2:
for(i=0; i<Nx; i++)
{
for(j=0; j<Ny; j++)
{
matrix->data[2*(j*s_tda + i)] = GSL_REAL(c_value);
matrix->data[2*(j*s_tda + i)+1] = GSL_IMAG(c_value);
}
}
3:
for(i=0; i<Nx; i++)
{
for(j=0; j<Ny; j++)
{
gsl_matrix_complex_set(matrix, i, j, c_value);
}
}