#include <torch/torch.h>
#include <torch/script.h>
#include <array>
#include <iostream>
#include <iomanip>
torch::Dimname dimnameFromString(const std::string& str);
int main()
{
std::cout << std::fixed << std::setprecision(4);
auto options =
torch::TensorOptions()
.dtype(torch::kFloat32);
auto r = dimnameFromString("r"); // name of the first dimension
auto c = dimnameFromString("c"); // name of the second dimension
std::vector<torch::Dimname> names = { r, c }; // put them into a vector
auto z_ = torch::zeros({5, 5}, names,options); // make a dummy zeros tensor
std::array<torch::Tensor, 2> arrayRefz_ = {z_, z_}; // make a arrayRef
auto cat_out_z = at::cat(arrayRefz_, c); // concatinate besed on the dimension names
std::cout << z_.names() << std::endl; // print the dimension names
std::cout << "Concatinate z_ with z_: \n" << cat_out_z << std::endl;
}
torch::Dimname dimnameFromString(const std::string& str) {
return torch::Dimname::fromSymbol(torch::Symbol::dimname(str));
}