Could exponent of an array be inproved in speed ? Maybe mex file with exp function (reduced accuracy) for windows 64 bit.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Could this line of code be improved in speed ? MM is an array 512x512^2 elements.
MM =ones(512^2,512); tic; exp(1i*(MM)); toc
Elapsed time is 3.824361 seconds.
I am looking for mex file for 64bit windows of exp function with reduced accuracy ?
#include <stddef.h>
#include <math.h>
#include "mex.h"
#ifndef mwSize
#define mwSize int
#endif
/* these 2 #define lines help make the later code more
readable */
/* Input Arguments */
#define PARAMETER_IN prhs[0]
/* Output Arguments */
#define RESULT_OUT plhs[0]
#define LITTLE_ENDIAN 1
static union
{
double d;
struct {
#ifdef LITTLE_ENDIAN
int j,i;
#else
int i,j;
#endif
} n;
} _eco;
#define EXP_A (1048576/0.69314718055994530942)
#define EXP_C 60801
#define EXP(y) (_eco.n.i = EXP_A*(y) + (1072693248 - EXP_C),_eco.d)
void mexexp(double*y, double*yp, mwSize m) {
while(m--) {
*yp++ = EXP(*y++);
}
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
mwSize numel;
mwSize ndim;
mwSize *dims;
/* Check for proper number of arguments */
if (nrhs != 1) {
mexErrMsgTxt("One input argument required.");
} else if (nlhs > 1) {
mexErrMsgTxt("Too many output arguments.");
} else if ( !mxIsDouble(PARAMETER_IN) ) {
mexErrMsgTxt("Input must be double.");
} else if ( mxIsComplex(PARAMETER_IN) ) {
mexErrMsgTxt("Input cannot be complex.");
}
ndim = mxGetNumberOfDimensions(PARAMETER_IN);
dims = mxGetDimensions(PARAMETER_IN);
numel = mxGetNumberOfElements(PARAMETER_IN);
/* Create a matrix for the return argument */
RESULT_OUT = mxCreateNumericArray(ndim, dims,
mxDOUBLE_CLASS, mxREAL);
/* Do the actual computation*/
mexexp(mxGetPr(PARAMETER_IN),mxGetPr(RESULT_OUT),numel);
return;
}
0 comentarios
Respuestas (1)
James Tursa
el 14 de Mzo. de 2015
Editada: James Tursa
el 14 de Mzo. de 2015
For your particular posed example all the elements are the same, so only compute the exp calculation once and don't do all of those multiplies either. E.g.,
NN = complex(zeros(512^2,512)); tic; NN(:) = exp(1i); toc
Is this the real problem, or is MM not really all 1's in your actual problem?
2 comentarios
Jan
el 14 de Mzo. de 2015
@Ole: Usually it is impossible to give suggestions for speed improvements, if only a roughly simplified version of the code is posted. So please post the relevant part of the code.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!