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;
57 static const long default_jdim = 5551212;
80 TensorIterator(
const Tensor<T>* t0,
const Tensor<Q>* t1=0,
const Tensor<R>* t2=0,
82 bool optimize=
true,
bool fusedim=
true,
83 long jdim=default_jdim);
105 void reuse(
const Tensor<T>* t0,
const Tensor<Q>* t1=0,
const Tensor<R>* t2=0);
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);
185 TENSOR_ASSERT(t0->conforms(*t1),
"first and second tensors do not conform",
187 _p1_save = _p1 =
const_cast<Q*
>(t1->ptr());
188 for (
int i=0; i<ndim; ++i) stride1[i] = t1->stride(i);
194 TENSOR_ASSERT(t0->conforms(*t2),
"first and third tensors do not conform",
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) {
223 if (std::abs(stride0[i]) < std::abs(stride0[j])) {
225 if (t1)
std::swap(stride1[i],stride1[j]);
226 if (t2)
std::swap(stride2[i],stride2[j]);
237 if (jdim == default_jdim) {
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>
372 const Tensor<R> *t2) {
373 _p0 = _p0_save = t0->ptr();
374 if (t1) _p1 = _p1_save = t1->ptr();
375 if (t2) _p2 = _p2_save = t2->ptr();
381 #endif // MADNESS_TENSOR_TENSORITER_H__INCLUDED
TensorIterator< T, Q, R > * operator->()
Definition: tensoriter.h:95
#define TENSOR_ASSERT(condition, msg, value, t)
Definition: tensorexcept.h:130
const double R
Definition: dielectric.cc:191
long _s2
Definition: tensoriter.h:73
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t rnd_mode)
Definition: mpreal.h:2201
Q * _p1
Definition: tensoriter.h:67
long _s1
Definition: tensoriter.h:72
T * _p0
Definition: tensoriter.h:66
long ind[TENSOR_MAXDIM]
Definition: tensoriter.h:75
T & operator*() const
Definition: tensoriter.h:99
Defines and implements most of Tensor.
long dim[TENSOR_MAXDIM]
Definition: tensoriter.h:74
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
long stride1[TENSOR_MAXDIM]
Definition: tensoriter.h:77
long stride0[TENSOR_MAXDIM]
Definition: tensoriter.h:76
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
long ndim
Definition: tensoriter.h:69
long stride2[TENSOR_MAXDIM]
Definition: tensoriter.h:78
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
#define TENSOR_MAXDIM
Definition: tensor_macros.h:194
R * _p2
Definition: tensoriter.h:68
TensorIterator< T, Q, R > & operator++()
Definition: tensoriter.h:328
bool operator!=(const TensorIterator< T, Q, R > &a) const
Definition: tensoriter.h:91
bool operator==(const TensorIterator< T, Q, R > &a) const
Definition: tensoriter.h:87
long _s0
Definition: tensoriter.h:71
void reset()
Reset the iterator back to the start ...
Definition: tensoriter.h:354
Definition: tensoriter.h:61
long dimj
Definition: tensoriter.h:70
Declares and implements TensorException.
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
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition: mpreal.h:3069