Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/ml/utils.hpp
Go to the documentation of this file.
00001 #ifndef UTILS_HPP_
00002 #define UTILS_HPP_
00003 
00004 #include <elemental.hpp>
00005 
00006 int max(elem::Matrix<double> Y) {
00007     int k =  (int) *std::max_element(Y.Buffer(), Y.Buffer() + Y.Height());
00008     return k;
00009 }
00010 
00011 int min(elem::Matrix<double> Y) {
00012     int k =  (int) *std::min_element(Y.Buffer(), Y.Buffer() + Y.Height());
00013     return k;
00014 }
00015 
00016 template<class LabelType>
00017 int GetNumTargets(const boost::mpi::communicator &comm, LabelType& Y) {
00018     int k = 0;
00019     int kmax = max(Y);
00020     int kmin = min(Y);
00021     int targets = 0;
00022 
00023     boost::mpi::all_reduce(comm, kmin, k, boost::mpi::minimum<int>());
00024     if (k==-1) {
00025         targets = 1;
00026     }
00027     else {
00028         boost::mpi::all_reduce(comm, kmax, k, boost::mpi::maximum<int>());
00029         targets = k+1;
00030     }
00031 
00032     return targets;
00033 }
00034 
00035 #endif