romeric / Fastor

A lightweight high performance tensor algebra framework for modern C++
MIT License
749 stars 69 forks source link

Binary operators on tensor views #140

Open tbb300 opened 3 years ago

tbb300 commented 3 years ago

Not sure if the below is supposed to work or not, but seems strange that there is inconsistent behavior between operator += and operator +. Should this work? If not is there an easy way to get the desired behavior of taking a slice of a higher dimensional tensor and adding to a lower dimensional tensor?

Fastor::Tensor<double,2,2,2> test1 = 1;
Fastor::Tensor<double,2,2> test2 = 3;
test2 += test1(1,Fastor::all,Fastor::all); // <- works fine
test2 = test2 + test1(1,Fastor::all,Fastor::all); // <- compiles but throws runtime_error EXPRESSION SHAPE MISMATCH
romeric commented 3 years ago

This is certainly a bug. I will have a look. Thanks for reporting.