Skip to content

Commit

Permalink
Merge pull request #1314 from iglesias/feature/fix_matrixlist
Browse files Browse the repository at this point in the history
Fix crashers occurring with SGMatrixList.
  • Loading branch information
Soeren Sonnenburg committed Jul 25, 2013
2 parents ff18c6c + 7c35471 commit 86f58e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/shogun/features/MatrixFeatures.cpp
Expand Up @@ -133,7 +133,7 @@ template< class ST > void CMatrixFeatures< ST >::set_feature_vector(
"(get_num_features())\n", get_num_features());
}

m_features[num] = vec;
m_features.set_matrix(num, vec);
}

template< class ST > void CMatrixFeatures< ST >::set_features(
Expand Down
18 changes: 18 additions & 0 deletions src/shogun/lib/SGMatrixList.cpp
Expand Up @@ -43,6 +43,24 @@ SGMatrixList<T>::~SGMatrixList()
unref();
}

template <class T>
SGMatrix<T> SGMatrixList<T>::get_matrix(index_t index) const
{
return matrix_list[index];
}

template <class T>
SGMatrix<T> SGMatrixList<T>::operator[](index_t index) const
{
return matrix_list[index];
}

template <class T>
void SGMatrixList<T>::set_matrix(index_t index, const SGMatrix<T> matrix)
{
matrix_list[index] = matrix;
}

template <class T>
void SGMatrixList<T>::copy_data(const SGReferencedData &orig)
{
Expand Down
18 changes: 10 additions & 8 deletions src/shogun/lib/SGMatrixList.h
Expand Up @@ -44,10 +44,7 @@ template<class T> class SGMatrixList : public SGReferencedData
*
* @return the matrix at position index of the list
*/
inline SGMatrix<T>& get_matrix(index_t index) const
{
return matrix_list[index];
}
SGMatrix<T> get_matrix(index_t index) const;

/** operator overload to get a matrix for read & write access
*
Expand All @@ -56,10 +53,15 @@ template<class T> class SGMatrixList : public SGReferencedData
*
* @return the matrix at position index of the list
*/
inline SGMatrix<T>& operator[](index_t index) const
{
return matrix_list[index];
}
SGMatrix<T> operator[](index_t index) const;

/** set a matrix of the list
*
* @param index matrix index, index must be less than
* num_matrices although no check is performed in the method
* @param matrix matrix to set at index
*/
void set_matrix(index_t index, const SGMatrix<T> matrix);

/**
* divide the matrix into a list of matrices. Each of the new
Expand Down

0 comments on commit 86f58e3

Please sign in to comment.