The most efficient way to calculate the exponent of each matrix element

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++)
    {
        /* Operations to obtain c_value (including exponentiation) */
        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++)
    {
        /* Operations to obtain c_value (including exponentiation) */
        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++)
    {
        /* Operations to obtain c_value (including exponentiation) */
        gsl_matrix_complex_set(matrix, i, j, c_value);
    }
}
+3
4

exp() . .

, , . , , , , , ( ) ( ). , ( ).

, - . ( API- ) , ( M N) , ( MN). ( , ) **.

, (.. 8 16 ), , , , , . , switch ( % block size!= 0).

+5

, - , , .

+3

exp , . (Nx * Ny) . , 0, , .

, ( ), , , DGPADM, , f2c, C. .

+2

, , c_value, , . - . , .. , , .

, , . , . , , , . .

, . SIMD - , ( C/++ FPU ). , , : 4/5- . , SIMD FPU , . SIMD FPU . , ( , Pentium) MMU (.. - ).

0
source

Source: https://habr.com/ru/post/1756274/


All Articles