New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup non-const methods in dense and combined features #4365
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ class CCombinedFeatures : public CFeatures | |
} | ||
|
||
/** list feature objects */ | ||
void list_feature_objs(); | ||
void list_feature_objs() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol, this method should rather be deleted (or return a list of strings or so) |
||
|
||
/** check feature object compatibility | ||
* | ||
|
@@ -89,20 +89,20 @@ class CCombinedFeatures : public CFeatures | |
* | ||
* @return first feature object | ||
*/ | ||
CFeatures* get_first_feature_obj(); | ||
CFeatures* get_first_feature_obj() const; | ||
|
||
/** get feature object at index idx | ||
* | ||
* @param idx index of feature object | ||
* @return the feature object at index idx | ||
*/ | ||
CFeatures* get_feature_obj(int32_t idx); | ||
CFeatures* get_feature_obj(int32_t idx) const; | ||
|
||
/** get last feature object | ||
* | ||
* @return last feature object | ||
*/ | ||
CFeatures* get_last_feature_obj(); | ||
CFeatures* get_last_feature_obj() const; | ||
|
||
/** insert feature object at index idx | ||
* Important, idx must be < num_feature_obj | ||
|
@@ -131,7 +131,7 @@ class CCombinedFeatures : public CFeatures | |
* | ||
* @return number of feature objects | ||
*/ | ||
int32_t get_num_feature_obj(); | ||
int32_t get_num_feature_obj() const; | ||
|
||
/** Takes another feature instance and returns a new instance which is | ||
* a concatenation of a copy if this instace's data and the given | ||
|
@@ -143,7 +143,7 @@ class CCombinedFeatures : public CFeatures | |
* @return new feature object which contains copy of data of this | ||
* instance and of given one | ||
*/ | ||
CFeatures* create_merged_copy(CFeatures* other); | ||
CFeatures* create_merged_copy(CFeatures* other) const; | ||
|
||
/** adds a subset of indices on top of the current subsets (possibly | ||
* subset o subset. Calls subset_changed_post() afterwards. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,28 +170,6 @@ template<class ST> ST* CDenseFeatures<ST>::get_feature_vector(int32_t num, int32 | |
return feat; | ||
} | ||
|
||
template<class ST> void CDenseFeatures<ST>::set_feature_vector(SGVector<ST> vector, int32_t num) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, and i think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. absolutely, the instance should be tied to the matrix, and otherwise users can create a new instance |
||
{ | ||
/* index conversion for subset, only for array access */ | ||
int32_t real_num=m_subset_stack->subset_idx_conversion(num); | ||
|
||
if (num>=get_num_vectors()) | ||
{ | ||
SG_ERROR("Index out of bounds (number of vectors %d, you " | ||
"requested %d)\n", get_num_vectors(), num); | ||
} | ||
|
||
if (!feature_matrix.matrix) | ||
SG_ERROR("Requires a in-memory feature matrix\n") | ||
|
||
if (vector.vlen != num_features) | ||
SG_ERROR( | ||
"Vector not of length %d (has %d)\n", num_features, vector.vlen); | ||
|
||
sg_memcpy(&feature_matrix.matrix[real_num * int64_t(num_features)], vector.vector, | ||
int64_t(num_features) * sizeof(ST)); | ||
} | ||
|
||
template<class ST> SGVector<ST> CDenseFeatures<ST>::get_feature_vector(int32_t num) | ||
{ | ||
/* index conversion for subset, only for array access */ | ||
|
@@ -286,7 +264,7 @@ template<class ST> void CDenseFeatures<ST>::feature_subset(int32_t* idx, int32_t | |
} | ||
|
||
template <class ST> | ||
SGMatrix<ST> CDenseFeatures<ST>::get_feature_matrix() | ||
SGMatrix<ST> CDenseFeatures<ST>::get_feature_matrix() const | ||
{ | ||
if (!m_subset_stack->has_subsets()) | ||
return feature_matrix; | ||
|
@@ -331,16 +309,6 @@ void CDenseFeatures<ST>::copy_feature_matrix(SGMatrix<ST> target, index_t column | |
} | ||
} | ||
|
||
template<class ST> SGMatrix<ST> CDenseFeatures<ST>::steal_feature_matrix() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol another joker method :D |
||
{ | ||
SGMatrix<ST> st_feature_matrix=feature_matrix; | ||
m_subset_stack->remove_all_subsets(); | ||
SG_UNREF(feature_cache); | ||
clean_preprocessors(); | ||
free_feature_matrix(); | ||
return st_feature_matrix; | ||
} | ||
|
||
template<class ST> void CDenseFeatures<ST>::set_feature_matrix(SGMatrix<ST> matrix) | ||
{ | ||
m_subset_stack->remove_all_subsets(); | ||
|
@@ -350,7 +318,9 @@ template<class ST> void CDenseFeatures<ST>::set_feature_matrix(SGMatrix<ST> matr | |
num_vectors = matrix.num_cols; | ||
} | ||
|
||
template<class ST> ST* CDenseFeatures<ST>::get_feature_matrix(int32_t &num_feat, int32_t &num_vec) | ||
template <class ST> | ||
ST* CDenseFeatures<ST>::get_feature_matrix( | ||
int32_t& num_feat, int32_t& num_vec) const | ||
{ | ||
num_feat = num_features; | ||
num_vec = num_vectors; | ||
|
@@ -468,21 +438,6 @@ template<class ST> void CDenseFeatures<ST>::initialize_cache() | |
|
||
template<class ST> EFeatureClass CDenseFeatures<ST>::get_feature_class() const { return C_DENSE; } | ||
|
||
template<class ST> bool CDenseFeatures<ST>::reshape(int32_t p_num_features, int32_t p_num_vectors) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should just be in the matrix itself, i.e. create a new feature instance using the reshaped sgmatrix |
||
{ | ||
if (m_subset_stack->has_subsets()) | ||
SG_ERROR("A subset is set, cannot call reshape\n") | ||
|
||
if (p_num_features * p_num_vectors | ||
== this->num_features * this->num_vectors) | ||
{ | ||
num_features = p_num_features; | ||
num_vectors = p_num_vectors; | ||
return true; | ||
} else | ||
return false; | ||
} | ||
|
||
template<class ST> int32_t CDenseFeatures<ST>::get_dim_feature_space() const { return num_features; } | ||
|
||
template<class ST> float64_t CDenseFeatures<ST>::dot(int32_t vec_idx1, CDotFeatures* df, | ||
|
@@ -1005,7 +960,7 @@ template<class ST> bool CDenseFeatures<ST>::is_equal(CDenseFeatures* rhs) | |
} | ||
|
||
template <class ST> | ||
CFeatures* CDenseFeatures<ST>::create_merged_copy(CList* others) | ||
CFeatures* CDenseFeatures<ST>::create_merged_copy(CList* others) const | ||
{ | ||
SG_DEBUG("Entering.\n"); | ||
|
||
|
@@ -1017,7 +972,7 @@ CFeatures* CDenseFeatures<ST>::create_merged_copy(CList* others) | |
|
||
while (current!=nullptr) | ||
{ | ||
auto casted=dynamic_cast<CDenseFeatures<ST>*>(current); | ||
auto casted = dynamic_cast<const CDenseFeatures<ST>*>(current); | ||
|
||
REQUIRE(casted!=nullptr, "Provided object's type (%s) must match own type (%s)!\n", | ||
current->get_name(), get_name()); | ||
|
@@ -1042,7 +997,7 @@ CFeatures* CDenseFeatures<ST>::create_merged_copy(CList* others) | |
|
||
while (current!=nullptr) | ||
{ | ||
auto casted=static_cast<CDenseFeatures<ST>*>(current); | ||
auto casted = static_cast<const CDenseFeatures<ST>*>(current); | ||
casted->copy_feature_matrix(data, num_copied); | ||
num_copied+=casted->get_num_vectors(); | ||
|
||
|
@@ -1059,7 +1014,7 @@ CFeatures* CDenseFeatures<ST>::create_merged_copy(CList* others) | |
} | ||
|
||
template <class ST> | ||
CFeatures* CDenseFeatures<ST>::create_merged_copy(CFeatures* other) | ||
CFeatures* CDenseFeatures<ST>::create_merged_copy(CFeatures* other) const | ||
{ | ||
auto list=some<CList>(); | ||
list->append_element(other); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we would like to drop setters in features
set_num_vectors
,set_num_features
, we can't an empty features and then set feature matrix later, and here there is no need to store it in a member field