Skip to content

Commit

Permalink
Fix memory bugs related to the SO framework
Browse files Browse the repository at this point in the history
  • Loading branch information
iglesias committed Jul 26, 2013
1 parent 7c35471 commit fc1c7f1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/shogun/lib/SGMatrixList.cpp
Expand Up @@ -92,22 +92,19 @@ SGMatrixList<T> SGMatrixList<T>::split(SGMatrix<T> matrix, int32_t num_component
matrix.num_cols, num_components);

int32_t new_num_cols = matrix.num_cols / num_components;
int32_t start;
SGMatrixList<T> out(num_components);

for ( int32_t i = 0 ; i < num_components ; ++i )
{
out[i] = SGMatrix<T>(matrix.num_rows, new_num_cols);
start = i*matrix.num_rows*new_num_cols;
SGMatrix<T> new_matrix = SGMatrix<T>(matrix.num_rows, new_num_cols);

for ( int32_t row = 0 ; row < matrix.num_rows ; ++row )
{
for ( int32_t col = 0 ; col < new_num_cols ; ++col )
{
out[i][col*matrix.num_rows + row] =
matrix[start + col*matrix.num_rows + row];
}
new_matrix(row, col) = matrix(row, i*new_num_cols + col);
}

out.set_matrix(i, new_matrix);
}

return out;
Expand Down
6 changes: 4 additions & 2 deletions src/shogun/machine/StructuredOutputMachine.cpp
Expand Up @@ -87,16 +87,18 @@ float64_t CStructuredOutputMachine::risk_nslack_margin_rescale(float64_t* subgra
int32_t dim = m_model->get_dim();

int32_t from=0, to=0;
CFeatures* features = get_features();
if (info)
{
from = info->m_from;
to = (info->m_N == 0) ? get_features()->get_num_vectors() : from+info->m_N;
to = (info->m_N == 0) ? features->get_num_vectors() : from+info->m_N;
}
else
{
from = 0;
to = get_features()->get_num_vectors();
to = features->get_num_vectors();
}
SG_UNREF(features);

float64_t R = 0.0;
for (int32_t i=0; i<dim; i++)
Expand Down
4 changes: 0 additions & 4 deletions src/shogun/structure/DualLibQPBMSOSVM.cpp
Expand Up @@ -115,13 +115,9 @@ bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
}

if (m_result.exitflag==1)
{
return true;
}
else
{
return false;
}
}

EMachineType CDualLibQPBMSOSVM::get_classifier_type()
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/structure/DualLibQPBMSOSVM.h
Expand Up @@ -63,7 +63,7 @@ class CDualLibQPBMSOSVM : public CLinearStructuredOutputMachine
SGVector< float64_t > W=0);

/** destructor */
~CDualLibQPBMSOSVM();
virtual ~CDualLibQPBMSOSVM();

/** @return name of SGSerializable */
virtual const char* get_name() const { return "DualLibQPBMSOSVM"; }
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/structure/libbmrm.cpp
Expand Up @@ -196,7 +196,9 @@ BmrmStatistics svm_bmrm_solver(
floatmax_t rsum, sq_norm_W, sq_norm_Wdiff=0.0;
uint32_t *I;
uint8_t S=1;
uint32_t nDim=machine->get_model()->get_dim();
CStructuredModel* model=machine->get_model();
uint32_t nDim=model->get_dim();
SG_UNREF(model);

CTime ttime;
float64_t tstart, tstop;
Expand Down

0 comments on commit fc1c7f1

Please sign in to comment.