Via tensor.accessor crash error in c++?


(cuixing) #1

my program is like this,Why is the last sentence output crash?

torch::Tensor temp = torch::rand({ 1,8 });
		std::tuple<torch::Tensor, torch::Tensor> result1 = temp.sort(-1, true);
		torch::Tensor top_scores1 = std::get<0>(result1).slice(1, 0, 5);
		auto top_scores_a = top_scores1.accessor<float, 2>();
		cout << top_scores1 << endl;
		cout << top_scores_a[0][0]; // collapse error

after i modify “top_scores1” to “temp” is OK,why, thanks!

torch::Tensor temp = torch::rand({ 1,8 });
		std::tuple<torch::Tensor, torch::Tensor> result1 = temp.sort(-1, true);
		torch::Tensor top_scores1 = std::get<0>(result1).slice(1, 0, 5);
		auto top_scores_a = temp.accessor<float, 2>();
		cout << temp << endl;
		cout << top_scores_a[0][0]; // OK

(Will Feng) #2

@cuixing158_1I wasn’t able to reproduce this error. Could you try it on the latest libtorch nightly build https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip ?