Skip to content

Commit

Permalink
fix the LogDetEstimator unit test and use unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeLing authored and vigsterkr committed Jul 11, 2017
1 parent 706872f commit da08025
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions tests/unit/features/StreamingDenseFeatures_unittest.cc
Expand Up @@ -25,7 +25,7 @@ TEST(StreamingDenseFeaturesTest, example_reading_from_file)
index_t dim=2;
char fname[] = "StreamingDenseFeatures_reading.XXXXXX";
generate_temp_filename(fname);
CRandom* m_rng = new CRandom();
auto m_rng = std::unique_ptr<CRandom>(new CRandom());
SGMatrix<float64_t> data(dim,n);
for (index_t i=0; i<dim*n; ++i)
data.matrix[i] = m_rng->std_normal_distrib();
Expand Down Expand Up @@ -60,7 +60,6 @@ TEST(StreamingDenseFeaturesTest, example_reading_from_file)

SG_UNREF(orig_feats);
SG_UNREF(feats);
SG_FREE(m_rng);

std::remove(fname);
}
Expand All @@ -69,7 +68,7 @@ TEST(StreamingDenseFeaturesTest, example_reading_from_features)
{
index_t n=20;
index_t dim=2;
CRandom* m_rng = new CRandom();
auto m_rng = std::unique_ptr<CRandom>(new CRandom());
SGMatrix<float64_t> data(dim,n);
for (index_t i=0; i<dim*n; ++i)
data.matrix[i] = m_rng->std_normal_distrib();
Expand All @@ -95,18 +94,16 @@ TEST(StreamingDenseFeaturesTest, example_reading_from_features)
feats->end_parser();

SG_UNREF(feats);
SG_FREE(m_rng);
}

TEST(StreamingDenseFeaturesTest, reset_stream)
{
index_t n=20;
index_t dim=2;
CRandom* m_rng = new CRandom();
auto m_rng = std::unique_ptr<CRandom>(new CRandom());
SGMatrix<float64_t> data(dim,n);
for (index_t i=0; i<dim*n; ++i)
data.matrix[i] = m_rng->std_normal_distrib();
SG_FREE(m_rng);

CDenseFeatures<float64_t>* orig_feats=new CDenseFeatures<float64_t>(data);
CStreamingDenseFeatures<float64_t>* feats=new CStreamingDenseFeatures<float64_t>(orig_feats);
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/machine/kerneldensity_unittest.cc
Expand Up @@ -169,7 +169,7 @@ TEST(KernelDensity,dual_tree)

TEST(KernelDensity,dual_tree_single_tree_equivalence)
{
CRandom* m_rng = new CRandom(1);
auto m_rng = std::unique_ptr<CRandom>(new CRandom(1));

SGMatrix<float64_t> data(5,100);
m_rng->fill_array_oo(data.matrix, 500);
Expand All @@ -195,5 +195,4 @@ TEST(KernelDensity,dual_tree_single_tree_equivalence)
SG_UNREF(testfeats);
SG_UNREF(feats);
SG_UNREF(k);
SG_FREE(m_rng);
}
1 change: 1 addition & 0 deletions tests/unit/mathematics/linalg/LogDetEstimator_unittest.cc
Expand Up @@ -139,6 +139,7 @@ TEST(LogDetEstimator, sample_ratapp_dense)
SG_REF(op_func);

CNormalSampler* trace_sampler=new CNormalSampler(size);
trace_sampler->set_seed(1);
SG_REF(trace_sampler);

CLogDetEstimator estimator(trace_sampler, op_func, e);
Expand Down

0 comments on commit da08025

Please sign in to comment.