Skip to content

Instantly share code, notes, and snippets.

@lambday
Last active December 19, 2015 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lambday/6028280 to your computer and use it in GitHub Desktop.
Save lambday/6028280 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/SGVector.h>
#include <shogun/lib/SGSparseVector.h>
#include <shogun/lib/SGSparseMatrix.h>
using namespace shogun;
// this is fine
void test1()
{
const int32_t size=10;
const int32_t num_feat=size/2;
SGSparseMatrix<float64_t> m(size, size);
for (index_t i=0; i<size; ++i)
{
m.sparse_matrix[i]=SGSparseVector<float64_t>(num_feat);
for (index_t j=0; j<num_feat; ++j)
{
SGSparseVectorEntry<float64_t> entry;
entry.feat_index=(j+1)*2;
entry.entry=0.5;
m.sparse_matrix[i].features[j]=entry;
}
}
}
// this is not
void test2()
{
const int32_t size=10;
const int32_t num_feat=size/2;
SGSparseMatrix<complex64_t> m(size, size);
for (index_t i=0; i<size; ++i)
{
m.sparse_matrix[i]=SGSparseVector<complex64_t>(num_feat);
for (index_t j=0; j<num_feat; ++j)
{
SGSparseVectorEntry<complex64_t> entry;
entry.feat_index=(j+1)*2;
entry.entry=0.5;
m.sparse_matrix[i].features[j]=entry;
}
}
}
int main(int argc, char** argv)
{
init_shogun_with_defaults();
sg_io->set_loglevel(MSG_DEBUG);
test1();
test2();
exit_shogun();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment