Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BruteForceIterator.hh
Go to the documentation of this file.
1 ///
2 /// @file BruteForceIterator.hh
3 /// @brief Generic tensor indexing iterator
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #ifndef HAMMER_MATH_MULTIDIM_BRUTEFORCEITERATOR
13 #define HAMMER_MATH_MULTIDIM_BRUTEFORCEITERATOR
14 
17 
18 namespace Hammer {
19 
20 
21  namespace MultiDimensional {
22 
24  public:
26  BruteForceIterator(IndexList dimensions, IndexList fixed = {});
27 
28  BruteForceIterator(const BruteForceIterator&) = default;
32 
33  ~BruteForceIterator() = default;
34 
35  public:
36 
37  BruteForceIterator begin() const;
38 
39  BruteForceIterator end() const;
40 
42 
44 
46 
47  bool isSame(const BruteForceIterator& other) const;
48 
49  private:
50  void incrementEntry(size_t position, int n);
51  void setInitialState();
52 
54  IndexList _fixedMask; ///< the strides for each tensor index (necessary to convert coordinates to position in `_data`)
56 
57  };
58 
59 
60  inline bool operator==(const BruteForceIterator& lhs,
61  const BruteForceIterator& rhs) {
62  return lhs.isSame(rhs);
63  }
64 
65  inline bool operator!=(const BruteForceIterator& lhs, const BruteForceIterator& rhs) {
66  return !(lhs == rhs);
67  }
68 
69  }
70 
71 } // namespace Hammer
72 
73 namespace std {
74 
75  template<>
76  struct iterator_traits<Hammer::MultiDimensional::BruteForceIterator> {
77  using difference_type = ptrdiff_t;
81  using iterator_category = forward_iterator_tag;
82  };
83 
84 }
85 
86 #endif
bool operator!=(const OuterElemIterator &lhs, const OuterElemIterator &rhs)
IndexList _fixedMask
the strides for each tensor index (necessary to convert coordinates to position in _data) ...
bool operator==(const OuterElemIterator &lhs, const OuterElemIterator &rhs)
Forward declarations of types used in the tensor classes.
BruteForceIterator & operator=(const BruteForceIterator &)=default
std::vector< IndexType > IndexList
bool isSame(const BruteForceIterator &other) const
Sparse tensor indexer.