Skip to content

Commit

Permalink
Fixed sparse copy subset method and its example
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Sep 2, 2012
1 parent a97a0ed commit 442ceac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv)
for (index_t i=0; i<num_vectors; ++i)
{
/* put elements only at even indices */
data.sparse_matrix[i]=SGSparseVector<float64_t>(num_features, 2*i);
data.sparse_matrix[i]=SGSparseVector<float64_t>(num_features);

/* fill */
for (index_t j=0; j<num_features; ++j)
Expand Down Expand Up @@ -106,7 +106,7 @@ int main(int argc, char **argv)
for (index_t i=0; i<subset_copy->get_num_vectors(); ++i)
{
SGSparseVector<float64_t> vec=subset_copy->get_sparse_feature_vector(i);
index_t ind=i+offset_copy+offset_subset;
index_t ind=i+offset_copy+offset_subset+1;

for (index_t j=0; j<vec.num_feat_entries; ++j)
{
Expand All @@ -124,6 +124,7 @@ int main(int argc, char **argv)

SG_UNREF(f);
SG_UNREF(subset_copy);

exit_shogun();
return 0;
}
Expand Down
9 changes: 2 additions & 7 deletions src/shogun/features/SparseFeatures.cpp
Expand Up @@ -1059,13 +1059,8 @@ template<class ST> CFeatures* CSparseFeatures<ST>::copy_subset(SGVector<index_t>
index_t real_index=m_subset_stack->subset_idx_conversion(index);

/* copy sparse vector */
SGSparseVector<ST> current=get_sparse_feature_vector(index);
matrix_copy.sparse_matrix[i]=SGSparseVector<ST>(
current.num_feat_entries, real_index);

/* copy entries */
memcpy(matrix_copy.sparse_matrix[i].features, current.features,
sizeof(SGSparseVectorEntry<ST>)*current.num_feat_entries);
SGSparseVector<ST> current=get_sparse_feature_vector(real_index);
matrix_copy.sparse_matrix[i]=current;

free_sparse_feature_vector(index);
}
Expand Down

0 comments on commit 442ceac

Please sign in to comment.