1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#pragma once
#include <utility>
#include <vector>
#include <bitset>
//#include <unordered_set>
#include <sys/stat.h>
#include <sstream>
#include <fstream>
#include <iostream>
#include <assert.h>
#include <stdlib.h>
using namespace std;
int which_max(int *x,int n);
//unordered_set<int> sampleIndex(int k,int n);
template <class T>
bool comparator ( const pair<T,int>& l, const pair<T,int>& r) { return l.first < r.first; }
template <class T>
vector<int> argsort(vector<T> *list) {
vector<pair<T,int> > tosort(list->size());
for(int i=0;i<list->size();i++) {
tosort[i] = make_pair( (*list)[i] ,i );
}
sort(tosort.begin(),tosort.end());//,comparator);
vector<int> ret(tosort.size());
for(int i=0;i<tosort.size();i++) {
ret[i] = tosort[i].second;
// cout << tosort[i].first << "\t" << tosort[i].second << endl;
}
return(ret);
}
template <class T>
T **newMatrix(int nrow,int ncol) {
T **ret = new T*[nrow];
for(int i=0;i<nrow;i++)
ret[i] = new T[ncol];
return(ret);
}
template <class T>
void delMatrix(T **mat,int nrow,int ncol) {
for(int i=0;i<nrow;i++)
delete[] mat[i];
delete[] mat;
}
template <class T>
void printMatrix(T **H,int nrow,int ncol) {
for(int i=0;i<nrow;i++) {
for(int j=0;j<ncol;j++)
cout << (unsigned int) H[i][j] << "\t";
cout << endl;
}
}
void die(const string & err);
bool fileexists(string fname);
int argmax(vector<double> & x);
|