From 251e63ecc5b74468c0e429169e3a14a909104cd1 Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Mon, 29 Feb 2016 15:36:37 +0000 Subject: [PATCH] use DnymicObject only, add name to wrapped objects, use from .sg example --- examples/meta/src/classifier/knn.sg | 17 +++++++---------- src/shogun/lib/DynamicObjectArray.h | 7 +++++-- src/shogun/lib/List.h | 11 ----------- src/shogun/lib/SGObjectWrapper.h | 18 +++++++++--------- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/examples/meta/src/classifier/knn.sg b/examples/meta/src/classifier/knn.sg index b20d170e61c..31fce8ec18a 100644 --- a/examples/meta/src/classifier/knn.sg +++ b/examples/meta/src/classifier/knn.sg @@ -21,22 +21,19 @@ Labels test_labels = knn.apply(feats_test) RealVector output = test_labels.get_values() #![train_and_apply] + +#################################################### +# Integration testing: Store all numerical results.# +#################################################### + # create some matrix that can serve as a fake result RealMatrix mat = feats_train.get_feature_matrix() #119 is char for 'w' SerializableAsciiFile f_results("knn_results.txt", 119) -SerializableAsciiFile f_names("knn_names.txt", 119) - DynamicObjectArray results() -DynamicObjectArray result_names() -results.append_element_wrapped(output) -result_names.append_element_wrapped("output") - -results.append_element_wrapped(mat) -result_names.append_element_wrapped("mat") +results.append_element_wrapped(output, "output") +results.append_element_wrapped(mat, "mat") results.save_serializable(f_results) -result_names.save_serializable(f_names) - diff --git a/src/shogun/lib/DynamicObjectArray.h b/src/shogun/lib/DynamicObjectArray.h index 3af30a1c84b..b4f6aa9ee5f 100644 --- a/src/shogun/lib/DynamicObjectArray.h +++ b/src/shogun/lib/DynamicObjectArray.h @@ -282,10 +282,13 @@ class CDynamicObjectArray : public CSGObject * which are wrapped through CSGObjectWrapper. * * @param data Data element to append, after being wrapped. + * @param data_name Name of wrapped data element. */ - template bool append_element_wrapped(T data) + template bool append_element_wrapped(T data, + const char* data_name="") { - return this->append_element(new CSGObjectWrapper(data)); + return this->append_element(new CSGObjectWrapper(data, + data_name)); } /** append array element to the end of array diff --git a/src/shogun/lib/List.h b/src/shogun/lib/List.h index 6d542726012..8c6cb9f97a3 100644 --- a/src/shogun/lib/List.h +++ b/src/shogun/lib/List.h @@ -18,7 +18,6 @@ #include #include #include -#include namespace shogun { @@ -323,16 +322,6 @@ class CList : public CSGObject } //@} - /** Works as ::append_element, but accepts non CSGObject input types, - * which are wrapped through CSGObjectWrapper. - * - * @param data Data element to append, after being wrapped. - */ - template bool append_element_wrapped(T data) - { - return this->append_element(new CSGObjectWrapper(data)); - } - /** append element AFTER the current element and move to the newly * added element * diff --git a/src/shogun/lib/SGObjectWrapper.h b/src/shogun/lib/SGObjectWrapper.h index 7700f9884e4..d2482719bba 100644 --- a/src/shogun/lib/SGObjectWrapper.h +++ b/src/shogun/lib/SGObjectWrapper.h @@ -37,6 +37,8 @@ #define SGOBJECT_WRAPPER_H__ #include +#include +#include namespace shogun @@ -47,27 +49,25 @@ template class CSGObjectWrapper: public CSGObject public: CSGObjectWrapper() { - init(); + m_value = 0; + m_value_name = NULL; + SG_ADD(&m_value, "NULL", "Wrapped value", MS_NOT_AVAILABLE); } - CSGObjectWrapper(T value) + CSGObjectWrapper(T value, const char* value_name="") { - init(); m_value = value; + m_value_name = value_name; + SG_ADD(&m_value, m_value_name, "Wrapped value", MS_NOT_AVAILABLE); } virtual const char* get_name() const { return "CSGObjectWrapper"; } private: - void init() - { - m_value = 0; - SG_ADD(&m_value, "Value", "Wrapped value", MS_NOT_AVAILABLE); - - } protected: T m_value; + const char* m_value_name; };