Skip to content

Commit

Permalink
+ Added one more convenience constructor for BinaryLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
iglesias committed Feb 25, 2013
1 parent d04bb50 commit fc7e2dc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/shogun/labels/BinaryLabels.cpp
Expand Up @@ -20,6 +20,15 @@ CBinaryLabels::CBinaryLabels(SGVector<int32_t> src) : CDenseLabels()
set_values(values);
}

CBinaryLabels::CBinaryLabels(SGVector<int64_t> src) : CDenseLabels()
{
SGVector<float64_t> values(src.vlen);
for (int32_t i=0; i<values.vlen; i++)
values[i] = src[i];
set_int_labels(src);
set_values(values);
}

CBinaryLabels::CBinaryLabels(SGVector<float64_t> src, float64_t threshold) : CDenseLabels()
{
SGVector<float64_t> labels(src.vlen);
Expand Down
7 changes: 7 additions & 0 deletions src/shogun/labels/BinaryLabels.h
Expand Up @@ -52,6 +52,13 @@ class CBinaryLabels : public CDenseLabels
*/
CBinaryLabels(SGVector<int32_t> src);

/** constructor
* sets labels with src elements (int64 version)
*
* @param src labels to set
*/
CBinaryLabels(SGVector<int64_t> src);

/** constructor
* sets values from src vector
* sets labels with sign of src elements with added threshold
Expand Down
11 changes: 11 additions & 0 deletions src/shogun/labels/DenseLabels.cpp
Expand Up @@ -119,6 +119,17 @@ void CDenseLabels::set_int_labels(SGVector<int32_t> lab)
set_int_label(i, lab.vector[i]);
}

void CDenseLabels::set_int_labels(SGVector<int64_t> lab)
{
if (m_subset_stack->has_subsets())
SG_ERROR("set_int_labels() is not possible on subset")

m_labels = SGVector<float64_t>(lab.vlen);

for (int32_t i=0; i<lab.vlen; i++)
set_int_label(i, lab.vector[i]);
}

void CDenseLabels::ensure_valid(const char* context)
{
if (m_labels.vector == NULL)
Expand Down
8 changes: 8 additions & 0 deletions src/shogun/labels/DenseLabels.h
Expand Up @@ -176,6 +176,14 @@ class CDenseLabels : public CLabels
*/
void set_int_labels(SGVector<int32_t> labels);

/** set INT64 labels
*
* not possible on subset
*
* @param labels INT labels
*/
void set_int_labels(SGVector<int64_t> labels);

/** get number of labels, depending on whether a subset is set
*
* @return number of labels
Expand Down

0 comments on commit fc7e2dc

Please sign in to comment.