forked from btgraham/SparseConvNet-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparseGrid.h
More file actions
68 lines (60 loc) · 1.99 KB
/
SparseGrid.h
File metadata and controls
68 lines (60 loc) · 1.99 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//We need a hash table:
//We can either use
// a) Google's sparsehash dense_hash_map, or
// b) the C++11 std::unordered_map
// c) the C++11 std::unordered_map with tbb::scalable_alloc (or similar) to prevent threads getting in each others way as they access memory to grow the maps,
// d) vectors disguised as a hash map (ok in 2 dimensions)
#define USE_GOOGLE_SPARSEHASH
//#define USE_UNORDERED_MAP
//#define USE_UNORDERED_MAP_TBB
//#define USE_VECTOR_HASH
#pragma once
#include <stdint.h>
#ifdef USE_GOOGLE_SPARSEHASH
#include <functional>
#include <google/dense_hash_map>
typedef google::dense_hash_map<int64_t, int, std::hash<int64_t>, std::equal_to<int64_t> > SparseGridMap;
class SparseGrid {
public:
int backgroundCol;
SparseGridMap mp;
SparseGrid() {
backgroundCol=-1; //Indicate that no "null vector" is needed
mp.set_empty_key(-99); // dense_hash_map needs an empty key that will not be used as a real key
mp.set_deleted_key(-98);
mp.min_load_factor(0.0f);
}
};
#endif
#ifdef USE_UNORDERED_MAP
#include <unordered_map>
typedef std::unordered_map<int64_t,int,std::hash<int64_t>,std::equal_to<int64_t>,std::allocator< std::pair<const int64_t,int> > > SparseGridMap;
class SparseGrid {
public:
int backgroundCol; //Set to -1 when no "null vector" is needed
SparseGridMap mp;
SparseGrid() : backgroundCol(-1) {}
};
#endif
#ifdef USE_UNORDERED_MAP_TBB
//Libraries -ltbb -ltbbmalloc
#include <unordered_map>
#include <tbb/scalable_allocator.h>
typedef std::unordered_map<int64_t,int,std::hash<int64_t>,std::equal_to<int64_t>,tbb::scalable_allocator< std::pair<const int64_t,int> > > SparseGridMap;
class SparseGrid {
public:
int backgroundCol; //Set to -1 when no "null vector" is needed
SparseGridMap mp;
SparseGrid() : backgroundCol(-1) {}
};
#endif
#ifdef USE_VECTOR_HASH
#include "vectorHash.h"
typedef vectorHash SparseGridMap;
class SparseGrid {
public:
int backgroundCol; //Set to -1 when no "null vector" is needed
SparseGridMap mp;
SparseGrid() : backgroundCol(-1) {}
};
#endif