Skip to content

Commit

Permalink
-added create_identity_matrix based on SGMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jun 3, 2012
1 parent e04a0e6 commit 96dc418
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/shogun/mathematics/Math.cpp
Expand Up @@ -266,6 +266,45 @@ void CMath::display_matrix(
name, prefix);
}

template <>
SGMatrix<float64_t> CMath::create_identity_matrix(index_t size, float64_t scale)
{
SGMatrix<float64_t> I(size, size);
for (index_t i=0; i<size; ++i)
{
for (index_t j=0; j<size; ++j)
I(i,j)=i==j ? scale : 0.0;
}

return I;
}

template <>
SGMatrix<float32_t> CMath::create_identity_matrix(index_t size, float32_t scale)
{
SGMatrix<float32_t> I(size, size);
for (index_t i=0; i<size; ++i)
{
for (index_t j=0; j<size; ++j)
I(i,j)=i==j ? scale : 0.0;
}

return I;
}

template <>
SGMatrix<int32_t> CMath::create_identity_matrix(index_t size, int32_t scale)
{
SGMatrix<int32_t> I(size, size);
for (index_t i=0; i<size; ++i)
{
for (index_t j=0; j<size; ++j)
I(i,j)=i==j ? scale : 0;
}

return I;
}

}

SGVector<float64_t> CMath::fishers_exact_test_for_multiple_2x3_tables(SGMatrix<float64_t> tables)
Expand Down
8 changes: 8 additions & 0 deletions src/shogun/mathematics/Math.h
Expand Up @@ -493,6 +493,14 @@ class CMath : public CSGObject
}
}

/** returns the identity matrix, scaled by a factor
*
* @param size size of square idenity matrix
* @param scale (optional) scaling factor
*/
template <class T>
static SGMatrix<T> create_identity_matrix(index_t size, T scale);

#ifdef HAVE_LAPACK
/** compute eigenvalues and eigenvectors of symmetric matrix using
* LAPACK
Expand Down

0 comments on commit 96dc418

Please sign in to comment.