Skip to content

Commit

Permalink
added SGVector/SGMatrix based eigenvalue routine wrapper for the exis…
Browse files Browse the repository at this point in the history
…ting

eigenvalue function
  • Loading branch information
karlnapf committed May 29, 2012
1 parent bea615a commit 4c20d8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/shogun/mathematics/Math.cpp
Expand Up @@ -546,6 +546,22 @@ void CMath::inverse(SGMatrix<float64_t> matrix)
SG_FREE(ipiv);
}

SGVector<float64_t> CMath::compute_eigenvectors(SGMatrix<float64_t> matrix)
{
if (matrix.num_rows!=matrix.num_rows)
{
SG_SERROR("CMath::compute_eigenvectors(SGMatrix<float64_t>): matrix"
" rows and columns are not equal!\n");
}

/* use reference counting for SGVector */
SGVector<float64_t> result(NULL, 0, true);
result.vlen=matrix.num_rows;
result.vector=compute_eigenvectors(matrix.matrix, matrix.num_rows,
matrix.num_rows);
return result;
}

double* CMath::compute_eigenvectors(double* matrix, int n, int m)
{
ASSERT(n == m);
Expand Down
11 changes: 11 additions & 0 deletions src/shogun/mathematics/Math.h
Expand Up @@ -494,6 +494,17 @@ class CMath : public CSGObject
}

#ifdef HAVE_LAPACK
/** compute eigenvalues and eigenvectors of symmetric matrix using
* LAPACK
*
* @param matrix symmetric matrix to compute eigenproblem. Is
* overwritten and contains orthonormal eigenvectors afterwards
* @return eigenvalues vector with eigenvalues equal to number of rows
* in matrix
* */
static SGVector<float64_t> compute_eigenvectors(
SGMatrix<float64_t> matrix);

/** compute eigenvalues and eigenvectors of symmetric matrix
*
* @param matrix overwritten and contains n orthonormal eigenvectors
Expand Down

0 comments on commit 4c20d8a

Please sign in to comment.