forked from sshekh/conv-filters
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNDGrid.cc
More file actions
68 lines (57 loc) · 1.32 KB
/
NDGrid.cc
File metadata and controls
68 lines (57 loc) · 1.32 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
/*
* Build obj linking with cc_library NDGrid Class.
*
* Copyright Bazel organization
*
*/
#include <stdexcept>
#include <utility>
#include <random>
template <typename T, size_t N>
NDGrid<T, N>::NDGrid(size_t size)
{
resize(size);
}
template <typename T, size_t N>
void NDGrid<T, N>::resize(size_t newSize)
{
mElements.resize(N == 3 ? newSize : kDefaultSize);
// Resizing the vector calls the 0-argument constructor for
// the NDGrid<T, N-1> elements, which constructs
// them with the default size. Thus, we must explicitly call
// resize() on each of the elements to recursively resize all
// nested Grid elements.
for (auto& element : mElements) {
element.resize(kDefaultSize);
}
}
template <typename T, size_t N>
NDGrid<T, N-1>& NDGrid<T, N>::operator[](size_t x)
{
return mElements[x];
}
template <typename T, size_t N>
const NDGrid<T, N-1>& NDGrid<T, N>::operator[](size_t x) const
{
return mElements[x];
}
template <typename T>
NDGrid<T, 1>::NDGrid(size_t size)
{
resize(size);
}
template <typename T>
void NDGrid<T, 1>::resize(size_t newSize)
{
mElements.resize(newSize);
}
template <typename T>
T& NDGrid<T, 1>::operator[](size_t x)
{
return mElements[x];
}
template <typename T>
const T& NDGrid<T, 1>::operator[](size_t x) const
{
return mElements[x];
}