Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add get/set functions for combined kernel weights (forgotten sgvector…
… transition)
  • Loading branch information
Soeren Sonnenburg committed Dec 7, 2011
1 parent 8108a74 commit 50fb405
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
16 changes: 7 additions & 9 deletions src/shogun/kernel/CombinedKernel.cpp
Expand Up @@ -685,19 +685,15 @@ const float64_t* CCombinedKernel::get_subkernel_weights(int32_t& num_weights)
return subkernel_weights_buffer ;
}

void CCombinedKernel::get_subkernel_weights(float64_t** weights, int32_t* num_weights)
SGVector<float64_t> CCombinedKernel::get_subkernel_weights()
{
int32_t num=0;
const float64_t* w=get_subkernel_weights(num);

ASSERT(num>0);
*num_weights=num;
*weights = SG_MALLOC(float64_t, num);
memcpy(*weights, w, num*sizeof(float64_t));
return SGVector<float64_t>((float64_t*) w, num);
}

void CCombinedKernel::set_subkernel_weights(
float64_t* weights, int32_t num_weights)
void CCombinedKernel::set_subkernel_weights(SGVector<float64_t> weights)
{
if (append_subkernel_weights)
{
Expand All @@ -707,7 +703,8 @@ void CCombinedKernel::set_subkernel_weights(
while(k)
{
int32_t num = k->get_num_subkernels() ;
k->set_subkernel_weights(&weights[i],num);
ASSERT(i<weights.vlen);
k->set_subkernel_weights(&weights.vector[i],num);

SG_UNREF(k);
k = get_next_kernel(current);
Expand All @@ -721,7 +718,8 @@ void CCombinedKernel::set_subkernel_weights(
CKernel* k = get_first_kernel(current);
while(k)
{
k->set_combined_kernel_weight(weights[i]);
ASSERT(i<weights.vlen);
k->set_combined_kernel_weight(weights.vector[i]);

SG_UNREF(k);
k = get_next_kernel(current);
Expand Down
9 changes: 3 additions & 6 deletions src/shogun/kernel/CombinedKernel.h
Expand Up @@ -355,18 +355,15 @@ class CCombinedKernel : public CKernel

/** get subkernel weights (swig compatible)
*
* @param weights subkernel weights
* @param num_weights number of weights
* @return subkernel weights
*/
virtual void get_subkernel_weights(float64_t** weights, int32_t* num_weights);
virtual SGVector<float64_t> get_subkernel_weights();

/** set subkernel weights
*
* @param weights new subkernel weights
* @param num_weights number of subkernel weights
*/
virtual void set_subkernel_weights(
float64_t* weights, int32_t num_weights);
virtual void set_subkernel_weights(SGVector<float64_t> weights);

/** set optimization type
*
Expand Down

0 comments on commit 50fb405

Please sign in to comment.