Skip to content

Commit

Permalink
Merge pull request #3421 from Saurabh7/fixguard
Browse files Browse the repository at this point in the history
fix guards KNN
  • Loading branch information
vigsterkr committed Aug 12, 2016
2 parents 96ec044 + 8d60208 commit 0dc725b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/shogun/multiclass/KNN.cpp
Expand Up @@ -20,8 +20,12 @@
#include <shogun/lib/Time.h>
#include <shogun/base/Parameter.h>
#include <shogun/multiclass/tree/KDTree.h>
#include <shogun/lib/external/falconn/lsh_nn_table.h>
#include <shogun/mathematics/eigen3.h>

#ifdef HAVE_CXX11
#include <shogun/lib/external/falconn/lsh_nn_table.h>
#endif

//#define DEBUG_KNN

using namespace shogun;
Expand Down Expand Up @@ -60,8 +64,10 @@ void CKNN::init()
m_num_classes=0;
m_leaf_size=1;
m_knn_solver=KNN_BRUTE;
#ifdef HAVE_CXX11
m_lsh_l = 0;
m_lsh_t = 0;
#endif

/* use the method classify_multiply_k to experiment with different values
* of k */
Expand Down Expand Up @@ -291,6 +297,7 @@ CMulticlassLabels* CKNN::apply_multiclass(CFeatures* data)
SG_UNREF(query);
break;
}
#ifdef HAVE_CXX11
case KNN_LSH:
{
CDenseFeatures<float64_t>* features = dynamic_cast<CDenseFeatures<float64_t>*>(distance->get_lhs());
Expand Down Expand Up @@ -347,6 +354,7 @@ CMulticlassLabels* CKNN::apply_multiclass(CFeatures* data)
SG_UNREF(query_features);
break;
}
#endif /* HAVE_CXX11 */
}

SG_FREE(classes);
Expand Down
6 changes: 6 additions & 0 deletions src/shogun/multiclass/KNN.h
Expand Up @@ -29,7 +29,9 @@ namespace shogun
KNN_BRUTE,
KNN_KDTREE,
KNN_COVER_TREE,
#ifdef HAVE_CXX11
KNN_LSH
#endif
};

class CDistanceMachine;
Expand Down Expand Up @@ -197,6 +199,7 @@ class CKNN : public CDistanceMachine
m_knn_solver = knn_solver;
}

#ifdef HAVE_CXX11
/** set parameters for LSH solver
* @param l number of hash tables for LSH
* @param t number of probes per query for LSH
Expand All @@ -206,6 +209,7 @@ class CKNN : public CDistanceMachine
m_lsh_l = l;
m_lsh_t = t;
}
#endif

protected:
/** Stores feature data of underlying model.
Expand Down Expand Up @@ -285,11 +289,13 @@ class CKNN : public CDistanceMachine

int32_t m_leaf_size;

#ifdef HAVE_CXX11
/* Number of hash tables for LSH */
int32_t m_lsh_l;

/* Number of probes per query for LSH */
int32_t m_lsh_t;
#endif
};

}
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/multiclass/KNN_unittest.cc
Expand Up @@ -8,6 +8,7 @@

using namespace shogun;

#ifdef HAVE_LAPACK
void generate_knn_data(SGMatrix<float64_t>& feat, SGVector<float64_t>& lab,
int32_t num, int32_t classes, int32_t feats)
{
Expand Down Expand Up @@ -205,3 +206,5 @@ TEST(KNN, classify_multiple_kdtree)
SG_UNREF(features_test);
SG_UNREF(labels_test);
}
#endif /* HAVE_LAPACK */

0 comments on commit 0dc725b

Please sign in to comment.