I am trying to use ssyev to compute eigenvalues of a large matrix, but I could not get it working.
Later, I tried just finding the eigenvalues of an identity matrix of size 4, but still the results I am getting
are very arbitrary. I am not sure why this is happening. I would appreciate any help in this direction.
I am giving my code here, which just computes the eigenvectors of Identity matrix of size 4. I do get
info = 0, for this as output!
Thank you all,
df.
- Code: Select all
#include <acml.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define NSAMP 4
void printMatrix(float **mat, int r, int c, char*str = "Noname")
{
fprintf(stderr,"\nBegMat----%s--\n",str);
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
printf("%f ",mat[i][j]);
printf("\n");
}
fprintf(stderr,"EndMat---------\n");
}
float **newMatrix(int r, int c)
{
float **mat = (float **)calloc(r,sizeof(float *));
for (int i = 0; i < r; i++)
mat[i] = (float *)calloc(c,sizeof(float));
return mat;
}
float **eye(int r)
{
float **mat = newMatrix(r,r);
for (int i = 0; i < r; i++)
mat[i][i] = 1;
return mat;
}
int main(int argc, char ** argv)
{
// either load the pwdist from a file, or compute by calling the function
const char *kernelFile = PWDISTFILE;
const int nSamples = NSAMP;
const float sigma = 1;
float **pwdist = eye(4); // computes the identity matrix
int LDZ = NSAMP;
float Z[LDZ*nSamples];
float *W =(float *)malloc(nSamples*sizeof(float));
int lwork = 3*nSamples - 1;
float WorkSpace[lwork];
int info;
ssyev('V','U',nSamples,&(pwdist[0][0]),nSamples,W,&info);
printMatrix(&W,1,nSamples,"Eigvals");
printMatrix(pwdist,nSamples,nSamples,"Eigvecs");
fprintf(stderr,"Success Status: %d\n",info);
}

