Skip to content

Commit

Permalink
Merge pull request #3581 from sudk1896/sg-ff
Browse files Browse the repository at this point in the history
Test for transposing Square SGSparseMatrix.
  • Loading branch information
karlnapf committed Jan 23, 2017
2 parents 072d3cb + 36199a2 commit 0021a9e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/unit/lib/SGSparseMatrix_unittest.cc
Expand Up @@ -265,3 +265,26 @@ TEST(SGSparseMatrix, from_dense)
for (index_t vecIndex=0; vecIndex<numberOfVectors; ++vecIndex)
EXPECT_EQ(sparseMatrix(featIndex,vecIndex), denseMatrix(featIndex,vecIndex));
}

TEST(SGSparseMatrix, transposed_square_matrix)
{
const float64_t sparse_level=0.1;
const index_t number_of_features=100;
const index_t number_of_vectors=100;
const index_t rand_seed=0;

SGSparseMatrix<float64_t> sparse_matrix(number_of_features, number_of_vectors);
GenerateMatrix<SGSparseMatrix<float64_t> >(sparse_level, number_of_features, number_of_vectors, rand_seed, &sparse_matrix);

SGSparseMatrix<float64_t> sparse_matrix_t=sparse_matrix.get_transposed();

EXPECT_EQ(sparse_matrix.num_features, sparse_matrix_t.num_vectors);
EXPECT_EQ(sparse_matrix.num_vectors, sparse_matrix_t.num_features);

//check contents
for (index_t feat_index=0; feat_index<number_of_features; ++feat_index)
{
for (index_t vec_index=0; vec_index<number_of_vectors; ++vec_index)
EXPECT_NEAR(sparse_matrix(feat_index,vec_index), sparse_matrix_t(vec_index,feat_index), 1E-14);
}
}

0 comments on commit 0021a9e

Please sign in to comment.