blitzpp / blitz

Blitz++ Multi-Dimensional Array Library for C++
https://github.com/blitzpp/blitz/wiki
Other
404 stars 83 forks source link

[bug/help needed] this tensor-dot-product does not evaluate to the right values! #112

Closed ClmnsRck closed 5 years ago

ClmnsRck commented 5 years ago
template<t,L,M,K,N,O>(this is not right, i know)
void blitz3d(cTensor<T> &A, cTensor<T> &B, cTensor<T> &C){
    blitz::Array<T, 3> t1(randVec<T>(L*M*K).data(), blitz::shape(L,M,K), blitz::duplicateData);
    blitz::Array<T, 3> t2(randVec<T>(K*N*O).data(), blitz::shape(K,N,O), blitz::duplicateData);
    blitz::Array<T, 4> t3(L, M, N, O);

    for (int l = 0; l < L; l++)
    {
        for (int m = 0; m < M; m++)
        {
            for (int k = 0; k < K; k++)
            {
                t1(l, m, k) = A.get2({l, m, k});
            }
        }
    }
    for (int k = 0; k < K; k++)
    {
        for (int n = 0; n < N; n++)
        {
            for (int o = 0; o < O; o++)
            {
                t2(k, n, o) = B.get2({k, n, o});
            }
        }
    }

    blitz::firstIndex a;
    blitz::secondIndex b;
    blitz::thirdIndex c;
    blitz::fourthIndex d;
    blitz::fifthIndex e;

        **_t3 = sum(t1(a,b,c) * t2(c,d,e),c);_**

    for (int mi = 0; mi < M; mi++)
    {
        for (int ni = 0; ni < N; ni++)
        {
            for (int oi = 0; oi < O; oi++)
            {
                for(int li = 0; li < L; li++){
                    assert(("Blitz3D", t3(li,mi,ni,oi) == C.get2({li,mi,ni,oi})));
                }
            }
        }
    }
}

Could somebody tell me the right way to do a tensor-dot on 2 by 2 dimensions and like here 3 by 3? Or maybe tell me, why the assert fails, while it works perfectly fine on any other lib i have tested?

std::cout outputs the same number, and some tests pass, i dont understand why this is ... is blitz doing some funky casting or something?