Skip to content

Commit

Permalink
Got sparse features to work
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jun 24, 2012
1 parent a55f500 commit ddad7f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/interfaces/python_modular/swig_typemaps.i
Expand Up @@ -602,10 +602,7 @@ static bool spmatrix_from_numpy(SGSparseMatrix<type>& sg_matrix, PyObject* obj,
shogun::SGSparseVector<type>* sfm = SG_MALLOC(shogun::SGSparseVector<type>, num_vec);

for (int32_t i=0; i<num_vec; i++)
{
sfm[i].num_feat_entries = 0;
sfm[i].features = NULL;
}
new (&sfm[i]) SGSparseVector<type>();

for (int32_t i=1; i<len_indptr; i++)
{
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/features/SparseFeatures.cpp
Expand Up @@ -451,7 +451,10 @@ template<class ST> void CSparseFeatures<ST>::set_sparse_feature_matrix(SGSparseM

SGSparseVector<ST>* sparse_matrix = SG_MALLOC(SGSparseVector<ST>, sm.num_vectors);
for (int32_t i=0; i<sm.num_vectors; i++)
{
new (&sparse_matrix[i]) SGSparseVector<ST>();
sparse_matrix[i] = sm[i];
}

sparse_feature_matrix=sparse_matrix;
num_features=sm.num_features;
Expand Down
8 changes: 7 additions & 1 deletion src/shogun/lib/SGSparseMatrix.h
Expand Up @@ -46,7 +46,10 @@ template <class T> class SGSparseMatrix : public SGReferencedData
{
sparse_matrix=SG_MALLOC(SGSparseVector<T>, num_vectors);
for (int32_t i=0; i<num_vectors; i++)
sparse_matrix[i] = SGSparseVector<T>();
{
new (&sparse_matrix[i]) SGSparseVector<T>();
sparse_matrix[i] = SGSparseVector<T>(num_feat);
}
}

/** copy constructor */
Expand Down Expand Up @@ -88,6 +91,9 @@ template <class T> class SGSparseMatrix : public SGReferencedData

virtual void free_data()
{
for (int32_t i=0; i<num_vectors; i++)
(&sparse_matrix[i])->~SGSparseVector<T>();

SG_FREE(sparse_matrix);
sparse_matrix = NULL;
num_vectors = 0;
Expand Down

0 comments on commit ddad7f3

Please sign in to comment.