Boost logo

Ublas :

Subject: Re: [ublas] Tensors
From: Andrey Asadchev (asadchev_at_[hidden])
Date: 2011-01-06 03:39:24


Sorry for late response.

Here is brief syntax:

#include "tensor/tensor.hpp"
#include "tensor/product.hpp"

namespace cc {

    template<class E0, class E1, class E2>
    void f(int i, int j, int k,
                 const tensor::expression<E0> &t2_,
                 const tensor::expression<E1> &VVVO_,
                 const tensor::expression<E2> &OVOO_,
                 tensor::tensor<3> &X) {

        USING_TENSOR_INDEX((a)(b)(c)(e)); // tensor::index<'a'> a; .. etc
        USING_TENSOR_INDEX((l)(m));

        const E0 &t2 = t2_();
        const E1 &VVVO = VVVO_();

        X(a,b,c) += (t2(a,e,i,j)*VVVO(b,c,e,k)); // ok
        X(a,b,c) += 3.0*(t2(a,e,i,j)*VVVO(b,c,e,k)); // ok
        X(a,c,b) += (t2(a,e,i,j)*VVVO(b,c,e,k)); // ok, transposed
        X(a,b,k) += (t2(a,e,i,j)*VVVO(b,c,e,k)); // compile error rank2 + rank3
        X(a,b,c) += (t2(a,e,m,j)*VVVO(b,c,m,k)); // compile error, rank3 + rank4
        X(a,b,m) += (t2(a,e,i,j)*VVVO(b,c,i,k)); // compile error,
index mismatch

    }

    void f(int i, int j, int k) {
        size_t size[4];
        tensor::tensor<4> t2, VVVO(size), OVOO(200,200,200,100);
        tensor::tensor<3> X(100,100,100);
        triples(i, j, k, t2, VVVO, OVOO, X);
    }

}

// No contravariance/covariance per se.

operators and constructors are generated using boost_pp.
integral index reduces tensor rank by one.
tensor index (which can be range) creates a view of tensor.
The storage is handled by multi_array by default - but can have other
backends via traits.
I think it has pretty flexible design, not finished yet but most of pieces
are there.
May need innermost loop optimization - something with iterators rather then
multi_array[index] i use now.
Can potentially add openmp for outermost loop.

My priority was static checks to verify correct indices/ranks/etc.
I can put the library on google code (about 500-700 lines) if you like
further look?

Bye.