cart-elc

Source code for CART-ELC
git clone git://git.laack.co/cart-elc.git
Log | Files | Refs | README | LICENSE

Tutorial_ReductionsVisitorsBroadcasting_broadcast_1nn.cpp (440B)


      1 #include <iostream>
      2 #include <Eigen/Dense>
      3 
      4 using namespace std;
      5 using namespace Eigen;
      6 
      7 int main()
      8 {
      9   Eigen::MatrixXf m(2,4);
     10   Eigen::VectorXf v(2);
     11   
     12   m << 1, 23, 6, 9,
     13        3, 11, 7, 2;
     14        
     15   v << 2,
     16        3;
     17 
     18   MatrixXf::Index index;
     19   // find nearest neighbour
     20   (m.colwise() - v).colwise().squaredNorm().minCoeff(&index);
     21 
     22   cout << "Nearest neighbour is column " << index << ":" << endl;
     23   cout << m.col(index) << endl;
     24 }