Skip to content

Instantly share code, notes, and snippets.

@lambday
Last active December 19, 2015 15:48
Show Gist options
  • Select an option

  • Save lambday/5978701 to your computer and use it in GitHub Desktop.

Select an option

Save lambday/5978701 to your computer and use it in GitHub Desktop.
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2013 Soumyajit De
*/
#include <shogun/lib/common.h>
#include <shogun/lib/SGMatrix.h>
#include <shogun/features/SparseFeatures.h>
#include <shogun/mathematics/logdet/SparseMatrixOperator.h>
using namespace shogun;
using namespace std;
void test()
{
const int32_t size=2;
SGMatrix<float64_t> m(size, size);
m.set_const(1.0);
CSparseFeatures<float64_t> feat(m);
SGSparseMatrix<float64_t> sp_mat=feat.get_sparse_feature_matrix();
CSparseMatrixOperator<float64_t>* mat=new CSparseMatrixOperator<float64_t>(sp_mat);
CSparseMatrixOperator<float64_t>* cloned
=dynamic_cast<CSparseMatrixOperator<float64_t>*>(mat->clone());
if (mat->equals(cloned))
SG_SPRINT("Voila!\n");
SG_UNREF(mat);
SG_UNREF(cloned);
}
int main(int argc, char **argv)
{
init_shogun_with_defaults();
//sg_io->set_loglevel(MSG_GCDEBUG);
sg_io->set_loglevel(MSG_DEBUG);
test();
exit_shogun();
return 0;
}
Voila!
[GCDEBUG] unref() refcount 0, obj SparseMatrixOperator (0x6462a0) destroying
[GCDEBUG] SparseMatrixOperator destroyed (0x6462a0)
[GCDEBUG] LinearOperator destroyed (0x6462a0)
[GCDEBUG] SGObject destroyed (0x6462a0)
[GCDEBUG] unref() refcount 0, obj SparseMatrixOperator (0x647580) destroying
[GCDEBUG] SparseMatrixOperator destroyed (0x647580)
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff707aae0 in shogun::sg_generic_free<shogun::SGSparseVector<double> > (ptr=0x6488c0) at lib/memory.cpp:349
349 SG_SPECIALIZED_MALLOC(SGSparseVector<float64_t>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment