/src/igraph/src/centrality/prpack/prpack_utils.cpp
Line | Count | Source |
1 | | /** |
2 | | * @file prpack_utils.cpp |
3 | | * An assortment of utility functions for reporting errors, checking time, |
4 | | * and working with vectors. |
5 | | */ |
6 | | |
7 | | #include "prpack_utils.h" |
8 | | |
9 | | #ifdef PRPACK_IGRAPH_SUPPORT |
10 | | #include "igraph_error.h" |
11 | | #else |
12 | | #include <iostream> |
13 | | #endif |
14 | | |
15 | | #include <string> |
16 | | using namespace prpack; |
17 | | using namespace std; |
18 | | |
19 | | #if defined(_WIN32) |
20 | | #ifndef WIN32_LEAN_AND_MEAN |
21 | | #define WIN32_LEAN_AND_MEAN |
22 | | #include <windows.h> |
23 | | #endif |
24 | | double prpack_utils::get_time() { |
25 | | LARGE_INTEGER t, freq; |
26 | | QueryPerformanceCounter(&t); |
27 | | QueryPerformanceFrequency(&freq); |
28 | | return double(t.QuadPart)/double(freq.QuadPart); |
29 | | } |
30 | | #else |
31 | | #include <sys/types.h> |
32 | | #include <sys/time.h> |
33 | 11.5k | double prpack_utils::get_time() { |
34 | 11.5k | struct timeval t; |
35 | 11.5k | gettimeofday(&t, NULL); |
36 | 11.5k | return (t.tv_sec*1.0 + t.tv_usec/1000000.0); |
37 | 11.5k | } |
38 | | #endif |
39 | | |
40 | | // Fails and outputs 'msg' if 'condition' is false. |
41 | 0 | void prpack_utils::validate(const bool condition, const string& msg) { |
42 | 0 | if (!condition) { |
43 | 0 | #ifdef PRPACK_IGRAPH_SUPPORT |
44 | 0 | IGRAPH_FATALF("Internal error in PRPACK: %s", msg.c_str()); |
45 | | #else |
46 | | cerr << msg << endl; |
47 | | exit(-1); |
48 | | #endif |
49 | 0 | } |
50 | 0 | } |
51 | | |
52 | | // Permute a vector. |
53 | 0 | double* prpack_utils::permute(const int length, const double* a, const int* coding) { |
54 | 0 | double* ret = new double[length]; |
55 | 0 | for (int i = 0; i < length; ++i) |
56 | 0 | ret[coding[i]] = a[i]; |
57 | 0 | return ret; |
58 | 0 | } |