Skip to content

offset_add is not behaving as expected

#include <xerus.h>
using namespace xerus;

int main() {
	auto test1  = xerus::Tensor::dirac({1,1,1},0);
	auto test2  = xerus::Tensor::dirac({2,2,1},0);
	test2[3] = 4;
	test2[1] = 2;
	test2[2] = 3;
	XERUS_LOG(info, "test1 =  \n" << test1  );
	XERUS_LOG(info, "test2 =  \n" << test2  );
	std::unique_ptr<Tensor> comb(new Tensor({3,3,2}));
	comb->offset_add(test1, std::vector<size_t>({0,0,0}));
	comb->offset_add(test2, std::vector<size_t>({1,1,1}));

	XERUS_LOG(info, "comb =  \n" << *comb );
}

The above code returns:

+00:00:00,000 testAddition.cpp    :  10 : info        : test1 =  
1.000000 

+00:00:00,000 testAddition.cpp    :  11 : info        : test2 =  
1.000000 	0.000000 
0.000000 	1.000000 

+00:00:00,002 testAddition.cpp    :  28 : info        : comb =  
1.000000 / 0.000000 	0.000000 / 0.000000 	0.000000 / 0.000000 
0.000000 / 0.000000 	0.000000 / 1.000000 	0.000000 / 2.000000 
0.000000 / 3.000000 	0.000000 / 4.000000 	0.000000 / 0.000000 

I expected

+00:00:00,000 testAddition.cpp    :  10 : info        : test1 =  
1.000000 

+00:00:00,000 testAddition.cpp    :  11 : info        : test2 =  
1.000000 	0.000000 
0.000000 	1.000000 

+00:00:00,002 testAddition.cpp    :  28 : info        : comb =  
1.000000 / 0.000000 	0.000000 / 0.000000 	0.000000 / 0.000000 
0.000000 / 0.000000 	0.000000 / 1.000000 	0.000000 / 2.000000 
0.000000 / 0.000000 	0.000000 / 3.000000 	0.000000 / 4.000000 

Is this a bug?

Cheers Micha

Edited by RoteKekse