BlackCat_Tensors
A GPU-supported autograd and linear algebra library, designed for neural network construction
blackcat
tensors
tensor_iterator_defs.h
Go to the documentation of this file.
1
2
#define BC_FORWARD_ITER(suffix, iter, access) \
3
auto suffix##iter() const { \
4
return iterators::iter_##suffix##iter(access); \
5
} \
6
auto suffix##iter() { \
7
return iterators::iter_##suffix##iter(access); \
8
} \
9
auto suffix##c##iter() const { \
10
return iterators::iter_##suffix##iter(access); \
11
} \
12
auto suffix##r##iter() const { \
13
return iterators::iter_##suffix##r##iter(access); \
14
} \
15
auto suffix##r##iter() { \
16
return iterators::iter_##suffix##r##iter(access); \
17
} \
18
auto suffix##cr##iter() const { \
19
return iterators::iter_##suffix##r##iter(access); \
20
}
21
22
#define BC_ITERATOR_DEF(suffix, iterator_name, begin_func, end_func) \
23
\
24
template<class Tensor> \
25
struct iterator_name { \
26
\
27
using size_t = bc::size_t; \
28
Tensor& tensor; \
29
\
30
using begin_t = decltype(tensor.begin_func ()); \
31
using end_t = decltype(tensor.end_func ()); \
32
\
33
begin_t m_begin = tensor.begin_func(); \
34
end_t m_end = tensor.end_func(); \
35
\
36
iterator_name(Tensor& tensor) : \
37
tensor(tensor) {} \
38
\
39
iterator_name(Tensor& tensor, size_t start): \
40
tensor(tensor) \
41
{ \
42
m_begin += start; \
43
} \
44
\
45
iterator_name(Tensor& tensor, size_t start, size_t end): \
46
tensor(tensor) \
47
{ \
48
m_begin += start; \
49
m_end = end; \
50
} \
51
\
52
auto begin() { \
53
return m_begin; \
54
} \
55
\
56
const begin_t& cbegin() const { \
57
return m_begin; \
58
} \
59
\
60
const end_t& end() const { \
61
return m_end; \
62
} \
63
}; \
64
\
65
\
66
template<class... params> auto suffix##iter(params... ps) const { \
67
return iterator_name<const self_type>(*this, ps...); \
68
} \
69
\
70
template<class... params> auto suffix##iter(params... ps) { \
71
return iterator_name<self_type>(*this, ps...); \
72
} \
73
\
74
template<class... params> auto suffix##const_iter(params... ps) const { \
75
return iterator_name<const self_type>(*this, ps...); \
76
}
Generated by
1.8.13