tensor-compiler / taco

The Tensor Algebra Compiler (taco) computes sparse tensor expressions on CPUs and GPUs
http://tensor-compiler.org
Other
1.25k stars 188 forks source link

reducing #194

Open jcrbloch opened 5 years ago

jcrbloch commented 5 years ago

I am trying to reduce the order of a tensor, as seemingly fixing one of the indices in a contraction is not possible. To reduce one mode of the tensor I contract with a tensor of order one with only a single element put to 1.0. When using compressed mode (sparse matrices), the result is wrong. Some elements are correct, while others have arbitrarily large values. When changing to dense mode the computation is correct.

jcrbloch commented 5 years ago

In connection with my remark: Is it possible that cout is printing all tensor components in compressed mode, but that the "zero" ones are printed with a wrong value? So just the output would be wrong, but not the actual calculations using the tensor?

oicirtap commented 5 years ago

Could you provide an example of the index expression you are using to define the computation?

jcrbloch commented 5 years ago

An example would be

T(x,y) = A(x,y,z,t) for fixed z and t

jcrbloch commented 5 years ago

The naive and inefficient workaround that I have implemented is the following: Let's say that I have a tensor T of order 4, which I want to reduce to one of order 3 by keeping the second mode fixed to its 9th value:

    Tensor<int> reductor("reductor", {d2}, Format({Sparse}));
    reductor.insert({8},1);
    reductor.pack();

        IndexVar i1,i2,i3,i4;
    Tensor<double> Tred("Tred", {d1,d3,d4}, Format({Sparse}));
    Tred(i1,i3,i4) = reductor(i2) * T(i1,i2,i3,i4);
    Tred.evaluate();