Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
TensorIterator.h
Go to the documentation of this file.
1#ifndef TENSOR_ITERATOR_H
2#define TENSOR_ITERATOR_H
3#pragma once
4
5#include <cstddef>
6#include <iterator>
7
8namespace txeo {
9
10template <typename T>
12 public:
13 using value_type = T;
14 using pointer = T *;
15 using reference = T &;
16 using difference_type = std::ptrdiff_t;
17 using iterator_category = std::random_access_iterator_tag;
18
19 TensorIterator(T *elements, std::ptrdiff_t step = 1) : _elements(elements), _step(step) {}
20
21 inline reference operator*() const { return *_elements; }
22 inline pointer operator->() const { return _elements; }
23
25 _elements += _step;
26 return *this;
27 }
28
30 auto aux = *this;
31 ++(*this);
32 return aux;
33 }
34
36 _elements -= _step;
37 return *this;
38 }
39
41 auto aux = *this;
42 --(*this);
43 return aux;
44 }
45
47 _elements += val * _step;
48 return *this;
49 }
50
52 _elements -= val * _step;
53 return *this;
54 }
55
57 iterator += val;
58 return iterator;
59 }
60
62 iterator += val;
63 return iterator;
64 }
65
67 iterator -= val;
68 return iterator;
69 }
70
71 inline difference_type operator-(const TensorIterator &other) const {
72 return (_elements - other._elements) / _step;
73 }
74
75 inline bool operator==(const TensorIterator &other) const {
76 return _elements == other._elements;
77 }
78 inline bool operator!=(const TensorIterator &other) const {
79 return _elements != other._elements;
80 }
81 inline bool operator<(const TensorIterator &other) const { return _elements < other._elements; }
82 inline bool operator>(const TensorIterator &other) const { return _elements > other._elements; }
83 inline bool operator<=(const TensorIterator &other) const {
84 return _elements <= other._elements;
85 }
86 inline bool operator>=(const TensorIterator &other) const {
87 return _elements >= other._elements;
88 }
89
90 private:
91 T *_elements;
92 std::ptrdiff_t _step;
93};
94
95} // namespace txeo
96
97#endif
reference operator*() const
friend TensorIterator operator+(const difference_type &val, TensorIterator iterator)
TensorIterator & operator++()
bool operator<(const TensorIterator &other) const
TensorIterator(T *elements, std::ptrdiff_t step=1)
TensorIterator operator--(int)
difference_type operator-(const TensorIterator &other) const
bool operator<=(const TensorIterator &other) const
TensorIterator & operator--()
pointer operator->() const
TensorIterator & operator-=(const difference_type &val)
TensorIterator & operator+=(const difference_type &val)
bool operator!=(const TensorIterator &other) const
bool operator>=(const TensorIterator &other) const
bool operator>(const TensorIterator &other) const
std::random_access_iterator_tag iterator_category
TensorIterator operator++(int)
friend TensorIterator operator+(TensorIterator iterator, const difference_type &val)
std::ptrdiff_t difference_type
bool operator==(const TensorIterator &other) const
friend TensorIterator operator-(TensorIterator iterator, const difference_type &val)
Definition Matrix.h:11