Skip to content

Commit

Permalink
use DnymicObject only, add name to wrapped objects, use from .sg example
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf authored and vigsterkr committed Mar 10, 2016
1 parent d763373 commit 251e63e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
17 changes: 7 additions & 10 deletions examples/meta/src/classifier/knn.sg
Expand Up @@ -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)

7 changes: 5 additions & 2 deletions src/shogun/lib/DynamicObjectArray.h
Expand Up @@ -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<class T> bool append_element_wrapped(T data)
template<class T> bool append_element_wrapped(T data,
const char* data_name="")
{
return this->append_element(new CSGObjectWrapper<T>(data));
return this->append_element(new CSGObjectWrapper<T>(data,
data_name));
}

/** append array element to the end of array
Expand Down
11 changes: 0 additions & 11 deletions src/shogun/lib/List.h
Expand Up @@ -18,7 +18,6 @@
#include <shogun/lib/common.h>
#include <shogun/base/SGObject.h>
#include <shogun/base/Parameter.h>
#include <shogun/lib/SGObjectWrapper.h>

namespace shogun
{
Expand Down Expand Up @@ -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<class T> bool append_element_wrapped(T data)
{
return this->append_element(new CSGObjectWrapper<T>(data));
}

/** append element AFTER the current element and move to the newly
* added element
*
Expand Down
18 changes: 9 additions & 9 deletions src/shogun/lib/SGObjectWrapper.h
Expand Up @@ -37,6 +37,8 @@
#define SGOBJECT_WRAPPER_H__

#include <shogun/base/SGObject.h>
#include <shogun/lib/SGString.h>
#include <string.h>


namespace shogun
Expand All @@ -47,27 +49,25 @@ template<class T> 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;

};

Expand Down

0 comments on commit 251e63e

Please sign in to comment.