// #include // int main() // { // torch::Tensor t = torch::rand({ 5, 5 }); // // Print original tensor // std::cout << t << std::endl; // // New value // torch::Tensor new_val = torch::tensor(10.0f); // // Indices for the cell you want to update // auto index_i = torch::tensor({ 2 }); // auto index_j = torch::tensor({ 3 }); // // Update cell // t.index_put_({ index_i, index_j }, new_val); // // Print updated tensor // std::cout << t << std::endl; // } #include #include #include #include using namespace std; int main() { //int i = 3, j = 1, k = 2; // Indices for the cell you want to update // Print original tensor // torch::Tensor t = torch::tensor({ {1, 2, 3}, {4, 5, 6} }); // 3D tensor for this example auto variables = vector{ "A", "B" }; auto cardinalities = vector{ 5, 4 }; torch::Tensor values = torch::rand({ 5, 4 }); auto candidate = "B"; vector newVariables; vector newCardinalities; for (int i = 0; i < variables.size(); i++) { if (variables[i] != candidate) { newVariables.push_back(variables[i]); newCardinalities.push_back(cardinalities[i]); } } torch::Tensor newValues = values.sum(1); cout << "original values" << endl; cout << values << endl; cout << "newValues" << endl; cout << newValues << endl; cout << "newVariables" << endl; for (auto& variable : newVariables) { cout << variable << endl; } cout << "newCardinalities" << endl; for (auto& cardinality : newCardinalities) { cout << cardinality << endl; } // std::cout << t << std::endl; // std::cout << "sum(0)" << std::endl; // std::cout << t.sum(0) << std::endl; // std::cout << "sum(1)" << std::endl; // std::cout << t.sum(1) << std::endl; // std::cout << "Normalized" << std::endl; // std::cout << t / t.sum(0) << std::endl; // New value // torch::Tensor new_val = torch::tensor(10.0f); // // Indices for the cell you want to update // std::vector indices; // indices.push_back(torch::tensor(i)); // Replace i with your index for the 1st dimension // indices.push_back(torch::tensor(j)); // Replace j with your index for the 2nd dimension // indices.push_back(torch::tensor(k)); // Replace k with your index for the 3rd dimension // //torch::ArrayRef indices_ref(indices); // // Update cell // //torch::Tensor result = torch::stack(indices); // //torch::List> indices_list = { torch::tensor(i), torch::tensor(j), torch::tensor(k) }; // torch::List> indices_list; // indices_list.push_back(torch::tensor(i)); // indices_list.push_back(torch::tensor(j)); // indices_list.push_back(torch::tensor(k)); // //t.index_put_({ torch::tensor(i), torch::tensor(j), torch::tensor(k) }, new_val); // t.index_put_(indices_list, new_val); // // Print updated tensor // std::cout << t << std::endl; }