20 #ifndef TENSOR_INDICES_H
21 #define TENSOR_INDICES_H
25 #include <tensor/vector.h>
26 #include <tensor/gen.h>
32 extern template class Vector<index>;
38 Indices(
const Vector<index> &v) : Vector<index>(v) {}
39 template<
size_t n>
Indices(StaticVector<index,n> v) : Vector<index>(v) {}
40 explicit Indices(index size) : Vector<index>(size) {}
42 static const Indices range(index min, index max, index step = 1);
44 index total_size()
const;
47 void surrounding_dimensions(
const Indices &d, index ndx, index *d1, index *d2, index *d3);
51 extern template class Vector<bool>;
59 explicit Booleans(index size) : Vector<bool>(size) {}
69 inline bool none_of(
const Booleans& b) {
return !any_of(b);}
71 bool all_equal(
const Indices &a,
const Indices &b);
72 inline bool some_unequal(
const Indices &a,
const Indices &b) {
return !all_equal(a,b); }
73 const Booleans operator==(
const Indices &a,
const Indices &b);
74 const Booleans operator<(
const Indices &a,
const Indices &b);
75 const Booleans operator>(
const Indices &a,
const Indices &b);
76 const Booleans operator<=(
const Indices &a,
const Indices &b);
77 const Booleans operator>=(
const Indices &a,
const Indices &b);
78 const Booleans operator!=(
const Indices &a,
const Indices &b);
80 const Booleans operator==(
const Indices &a, index b);
81 const Booleans operator<(
const Indices &a, index b);
82 const Booleans operator>(
const Indices &a, index b);
83 const Booleans operator<=(
const Indices &a, index b);
84 const Booleans operator>=(
const Indices &a, index b);
85 const Booleans operator!=(
const Indices &a, index b);
87 inline const Booleans operator==(index a,
const Indices &b) {
return b == a; }
88 inline const Booleans operator<(index a,
const Indices &b) {
return b >= a; }
89 inline const Booleans operator>(index a,
const Indices &b) {
return b <= a; }
90 inline const Booleans operator<=(index a,
const Indices &b) {
return b > a; }
91 inline const Booleans operator>=(index a,
const Indices &b) {
return b < a; }
92 inline const Booleans operator!=(index a,
const Indices &b) {
return b != a; }
110 virtual void set_factor(index new_factor);
111 virtual void set_limit(index new_limit);
112 virtual index size()
const;
113 virtual void reset();
114 index nomore()
const {
return ~(index)0; }
115 index get_offset()
const {
return base_; }
116 index get_limit()
const {
return limit_; }
117 index get_factor()
const {
return factor_; }
118 void set_offset(index new_base) { base_ = new_base; }
120 index base_, limit_, factor_;
123 class FullRange :
public Range {
127 virtual void set_factor(index new_factor);
128 virtual void set_limit(index new_limit);
129 virtual index size()
const;
130 virtual void reset();
132 index counter_, counter_end_;
135 class StepRange :
public Range {
137 StepRange(index start, index end, index step = 1);
139 virtual void set_factor(index new_factor);
140 virtual void set_limit(index new_limit);
141 virtual index size()
const;
142 virtual void reset();
144 index ndx_, start_, end_, step_;
147 class SingleRange :
public Range {
149 SingleRange(index ndx);
151 virtual void set_factor(index new_factor);
152 virtual void set_limit(index new_limit);
153 virtual index size()
const;
154 virtual void reset();
156 index ndx_, counter_;
159 class IndexRange :
public Range {
161 IndexRange(
const Indices &i);
163 virtual void set_factor(index new_factor);
164 virtual void set_limit(index new_limit);
165 virtual index size()
const;
166 virtual void reset();
172 class ProductRange :
public Range {
174 ProductRange(Range *r1, Range *r2);
177 virtual void set_factor(index new_factor);
178 virtual void set_limit(index new_limit);
179 virtual index size()
const;
180 virtual void reset();
188 PRange(Range *r) : ptr_(r) {};
189 operator Range*()
const {
return ptr_; }
190 Range &operator*() {
return *ptr_; }
191 Range *operator->() {
return ptr_; }
198 inline PRange range(index ndx) {
return new SingleRange(ndx); }
200 inline PRange range(index start, index end) {
return new StepRange(start, end); }
202 inline PRange range(index start, index end, index step) {
return new StepRange(start, end, step); }
204 inline PRange range(Indices i) {
return new IndexRange(i); }
206 inline PRange range() {
return new FullRange(); }
209 inline Indices iota(index start, index end, index step = 1) {
210 return Indices::range(start, end, step);
215 const tensor::StaticVector<tensor::index,n> &v1)
218 if (v0.size() != v2.size())
return false;
219 return std::equal(v0.begin_const(), v0.end_const(), v2.begin_const());
223 bool operator==(
const tensor::StaticVector<tensor::index,n> &v1,
227 if (v0.size() != v2.size())
return false;
228 return std::equal(v0.begin_const(), v0.end_const(), v2.begin_const());
Vector of boolean values.
Vector of 'index' type, where 'index' fits the indices of a tensor.