forked from DavidKurokawa/prpack
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprpack_utils.cpp
More file actions
52 lines (47 loc) · 1.22 KB
/
prpack_utils.cpp
File metadata and controls
52 lines (47 loc) · 1.22 KB
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
/**
* @file prpack_utils.cpp
* An assortment of utility functions for reporting errors, checking time,
* and working with vectors.
*/
#include <stdlib.h>
#include "prpack_utils.h"
#include <exception>
#include <iostream>
#include <string>
using namespace prpack;
using namespace std;
#if defined(_WIN32) || defined(_WIN64)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
double prpack_utils::get_time() {
LARGE_INTEGER t, freq;
QueryPerformanceCounter(&t);
QueryPerformanceFrequency(&freq);
return double(t.QuadPart)/double(freq.QuadPart);
}
#else
#include <sys/types.h>
#include <sys/timeb.h>
#include <sys/time.h>
double prpack_utils::get_time() {
struct timeval t;
gettimeofday(&t, 0);
return (t.tv_sec*1.0 + t.tv_usec/1000000.0);
}
#endif
// Fails and outputs 'msg' if 'condition' is false.
void prpack_utils::validate(const bool condition, const string& msg) {
if (!condition) {
cerr << msg << endl;
exit(-1);
}
}
// Permute a vector.
double* prpack_utils::permute(const int length, const double* a, const int* coding) {
double* ret = new double[length];
for (int i = 0; i < length; ++i)
ret[coding[i]] = a[i];
return ret;
}