36 #ifndef MADNESS_TENSOR_TENSORITER_H__INCLUDED
37 #define MADNESS_TENSOR_TENSORITER_H__INCLUDED
54 template <
class T>
class Tensor;
55 template <
class T>
class SliceTensor;
82 bool optimize=
true,
bool fusedim=
true,
156 template <
class T,
class Q,
class R>
175 TENSOR_ASSERT(iterlevel==0 || iterlevel==1,
"invalid iteration level",iterlevel,t0);
179 _p0_save = _p0 =
const_cast<T*
>(t0->
ptr());
180 for (
int i=0; i<ndim; ++i) {
182 stride0[i] = t0->
stride(i);
187 _p1_save = _p1 =
const_cast<Q*
>(t1->
ptr());
188 for (
int i=0; i<ndim; ++i) stride1[i] = t1->
stride(i);
196 _p2_save = _p2 =
const_cast<R*
>(t2->
ptr());
197 for (
int i=0; i<ndim; ++i) stride2[i] = t2->
stride(i);
203 if (iterlevel == 0) {
212 else if (iterlevel == 1) {
214 if (jdim < 0) jdim += ndim;
219 for (
int i=0; i<ndim; ++i) {
221 for (
int j=i; j<ndim; ++j) {
225 if (t1)
std::swap(stride1[i],stride1[j]);
226 if (t2)
std::swap(stride2[i],stride2[j]);
243 TENSOR_ASSERT(jdim>=0 && jdim < ndim,
"invalid index for external iteration",
264 for (
int i=jdim+1; i<=ndim; ++i) {
266 stride0[i-1] = stride0[i];
269 for (
int i=jdim+1; i<=ndim; ++i) stride1[i-1] = stride1[i];
272 for (
int i=jdim+1; i<=ndim; ++i) stride2[i-1] = stride2[i];
277 for (
int i=ndim-1; i>=0; --i) {
278 if (_s0*dimj == stride0[i] &&
279 _s1*dimj == stride1[i] &&
280 _s2*dimj == stride2[i]) {
290 for (
int i=ndim-1; i>=0; --i) {
291 if (_s0*dimj == stride0[i] &&
292 _s1*dimj == stride1[i]) {
302 for (
int i=ndim-1; i>=0; --i) {
303 if (_s0*dimj == stride0[i]) {
327 template <
class T,
class Q,
class R>
334 while (ind[
d] >= (dim[
d] - 1)) {
335 _p0 -= ind[
d] * stride0[
d];
336 if (_p1) _p1 -= ind[
d] * stride1[
d];
337 if (_p2) _p2 -= ind[
d] * stride2[
d];
346 if (_p1) _p1 += stride1[
d];
347 if (_p2) _p2 += stride2[
d];
353 template <
class T,
class Q,
class R>
369 template <
class T,
class Q,
class R>
373 _p0 = _p0_save = t0->
ptr();
374 if (t1) _p1 = _p1_save = t1->
ptr();
375 if (t2) _p2 = _p2_save = t2->
ptr();
long dim(int i) const
Returns the size of dimension i.
Definition: basetensor.h:147
long stride(int i) const
Returns the stride associated with dimension i.
Definition: basetensor.h:150
long ndim() const
Returns the number of dimensions in the tensor.
Definition: basetensor.h:144
Definition: tensoriter.h:61
R * _p2_save
Definition: tensoriter.h:64
long stride0[TENSOR_MAXDIM]
Definition: tensoriter.h:76
bool operator==(const TensorIterator< T, Q, R > &a) const
Definition: tensoriter.h:87
T & operator*() const
Definition: tensoriter.h:99
long dim[TENSOR_MAXDIM]
Definition: tensoriter.h:74
long stride1[TENSOR_MAXDIM]
Definition: tensoriter.h:77
T * _p0_save
Definition: tensoriter.h:62
void reuse(const Tensor< T > *t0, const Tensor< Q > *t1=0, const Tensor< R > *t2=0)
Reuse this iterator to iterate over other Tensors.
Definition: tensoriter.h:370
long dimj
Definition: tensoriter.h:70
long _s1
Definition: tensoriter.h:72
bool operator!=(const TensorIterator< T, Q, R > &a) const
Definition: tensoriter.h:91
long _s0
Definition: tensoriter.h:71
Q * _p1
Definition: tensoriter.h:67
long ndim
Definition: tensoriter.h:69
TensorIterator< T, Q, R > & operator++()
Definition: tensoriter.h:328
void reset()
Reset the iterator back to the start ...
Definition: tensoriter.h:354
long ind[TENSOR_MAXDIM]
Definition: tensoriter.h:75
Q * _p1_save
Definition: tensoriter.h:63
TensorIterator< T, Q, R > * operator->()
Definition: tensoriter.h:95
R * _p2
Definition: tensoriter.h:68
T * _p0
Definition: tensoriter.h:66
long stride2[TENSOR_MAXDIM]
Definition: tensoriter.h:78
long _s2
Definition: tensoriter.h:73
A tensor is a multidimension array.
Definition: tensor.h:317
T * ptr()
Returns a pointer to the internal data.
Definition: tensor.h:1824
bool conforms(const Tensor< Q > &t) const
Test if *this and t conform.
Definition: tensor.h:1657
static const double R
Definition: csqrt.cc:46
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
TensorIterator(const Tensor< T > *t0, const Tensor< Q > *t1=0, const Tensor< R > *t2=0, long iterlevel=0, bool optimize=true, bool fusedim=true, long jdim=default_jdim)
Constructor for general iterator to compose operations over up to three tensors.
Definition: tensoriter.h:157
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
static const long default_jdim
Definition: tensoriter.h:57
void swap(Vector< T, N > &l, Vector< T, N > &r)
Swap the contents of two Vectors.
Definition: vector.h:497
static long abs(long a)
Definition: tensor.h:218
static const double a
Definition: nonlinschro.cc:118
double Q(double a)
Definition: relops.cc:20
Defines and implements most of Tensor.
#define TENSOR_MAXDIM
Definition: tensor_macros.h:194
Declares and implements TensorException.
#define TENSOR_ASSERT(condition, msg, value, t)
Definition: tensorexcept.h:130
void d()
Definition: test_sig.cc:79