Skip to content

Commit

Permalink
fixed memory bug for streaming data parser and added unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
lambday authored and karlnapf committed Jul 1, 2016
1 parent ea78548 commit c613b04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shogun/features/streaming/StreamingDenseFeatures.cpp
Expand Up @@ -70,6 +70,7 @@ template<class T> void CStreamingDenseFeatures<T>::reset_stream()
parser.exit_parser();
parser.init(working_file, has_labels, 1);
parser.set_free_vector_after_release(false);
parser.set_free_vectors_on_destruct(false);
parser.start_parser();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/shogun/io/streaming/InputParser.h
Expand Up @@ -403,6 +403,7 @@ template <class T>
else
example_type = E_UNLABELLED;

SG_UNREF(examples_ring);
examples_ring = new CParseBuffer<T>(size);
SG_REF(examples_ring);

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/features/StreamingDenseFeatures_unittest.cc
Expand Up @@ -92,3 +92,33 @@ TEST(StreamingDenseFeaturesTest, example_reading_from_features)

SG_UNREF(feats);
}

TEST(StreamingDenseFeaturesTest, reset_stream)
{
index_t n=20;
index_t dim=2;

SGMatrix<float64_t> data(dim,n);
for (index_t i=0; i<dim*n; ++i)
data.matrix[i]=sg_rand->std_normal_distrib();

CDenseFeatures<float64_t>* orig_feats=new CDenseFeatures<float64_t>(data);
CStreamingDenseFeatures<float64_t>* feats=new CStreamingDenseFeatures<float64_t>(orig_feats);

feats->start_parser();

CDenseFeatures<float64_t>* streamed=dynamic_cast<CDenseFeatures<float64_t>*>(feats->get_streamed_features(n));
ASSERT_TRUE(streamed!=nullptr);
ASSERT_TRUE(orig_feats->equals(streamed));
SG_UNREF(streamed);

feats->reset_stream();

streamed=dynamic_cast<CDenseFeatures<float64_t>*>(feats->get_streamed_features(n));
ASSERT_TRUE(streamed!=nullptr);
ASSERT_TRUE(orig_feats->equals(streamed));
SG_UNREF(streamed);

feats->end_parser();
SG_UNREF(feats);
}

0 comments on commit c613b04

Please sign in to comment.