From 7c35471acf923285397f06a618e8dde26d10bdf9 Mon Sep 17 00:00:00 2001 From: Fernando Iglesias Date: Fri, 26 Jul 2013 00:00:14 +0200 Subject: [PATCH] Minor refactoring in SGMatrixList. Methods don't return refs to matrix elements and a setter is provided instead --- src/shogun/features/MatrixFeatures.cpp | 2 +- src/shogun/lib/SGMatrixList.cpp | 18 ++++++++++++++++++ src/shogun/lib/SGMatrixList.h | 18 ++++++++++-------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/shogun/features/MatrixFeatures.cpp b/src/shogun/features/MatrixFeatures.cpp index 15e05ba1f6e..bcb700688f4 100644 --- a/src/shogun/features/MatrixFeatures.cpp +++ b/src/shogun/features/MatrixFeatures.cpp @@ -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( diff --git a/src/shogun/lib/SGMatrixList.cpp b/src/shogun/lib/SGMatrixList.cpp index fd9a6741869..bf5318dc794 100644 --- a/src/shogun/lib/SGMatrixList.cpp +++ b/src/shogun/lib/SGMatrixList.cpp @@ -43,6 +43,24 @@ SGMatrixList::~SGMatrixList() unref(); } +template +SGMatrix SGMatrixList::get_matrix(index_t index) const +{ + return matrix_list[index]; +} + +template +SGMatrix SGMatrixList::operator[](index_t index) const +{ + return matrix_list[index]; +} + +template +void SGMatrixList::set_matrix(index_t index, const SGMatrix matrix) +{ + matrix_list[index] = matrix; +} + template void SGMatrixList::copy_data(const SGReferencedData &orig) { diff --git a/src/shogun/lib/SGMatrixList.h b/src/shogun/lib/SGMatrixList.h index 7559bf83c61..ef4408ed69a 100644 --- a/src/shogun/lib/SGMatrixList.h +++ b/src/shogun/lib/SGMatrixList.h @@ -44,10 +44,7 @@ template class SGMatrixList : public SGReferencedData * * @return the matrix at position index of the list */ - inline SGMatrix& get_matrix(index_t index) const - { - return matrix_list[index]; - } + SGMatrix get_matrix(index_t index) const; /** operator overload to get a matrix for read & write access * @@ -56,10 +53,15 @@ template class SGMatrixList : public SGReferencedData * * @return the matrix at position index of the list */ - inline SGMatrix& operator[](index_t index) const - { - return matrix_list[index]; - } + SGMatrix 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 matrix); /** * divide the matrix into a list of matrices. Each of the new