Skip to content

Commit

Permalink
Add and test raw 2d array (aka matrix) in ::equals
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jan 23, 2018
1 parent 7e914e1 commit 3766aba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/shogun/base/SGObject.h
Expand Up @@ -527,6 +527,27 @@ class CSGObject
tag, AnyParameter(make_any_ref(value, len), properties));
}

/** Puts a pointer to some 2d parameter array (i.e. a matrix) into the
* parameter map.
*
* @param name name of the parameter array
* @param value pointer to the first element of the parameter array
* @param rows number of rows in the array
* @param cols number of columns in the array
* @param properties properties of the parameter (e.g. if model selection is
* supported)
*/
template <typename T, typename S>
void watch_param(
const std::string& name, T** value, S* rows, S* cols,
AnyParameterProperties properties =
AnyParameterProperties(MS_NOT_AVAILABLE, GRADIENT_NOT_AVAILABLE))
{
BaseTag tag(name);
create_parameter(
tag, AnyParameter(make_any_ref(value, rows, cols), properties));
}

public:
/** Updates the hash of current parameter combination */
virtual void update_parameter_hash();
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/base/MockObject.h
Expand Up @@ -172,6 +172,9 @@ namespace shogun
m_raw_matrix_basic = new T[size];
for (auto i : range(size))
m_raw_matrix_basic[i] = 1;
watch_param(
"raw_matrix_basic", &m_raw_matrix_basic,
&m_raw_matrix_basic_rows, &m_raw_matrix_basic_cols);
}

void free_raw_matrix()
Expand Down

0 comments on commit 3766aba

Please sign in to comment.