Torch::linalg::linalg_norm() usage

Using torch::linalg::linalg_norm() like torch::linalg::linalg_norm(tensor, 2, 2) gives this error
error: no matching function for call to ‘linalg_norm(at::Tensor&, int, int)’

I want to do this

np.linalg.norm(diff, ord=2, axis=2)

in Libtorch.

torch::linalg_norm is defined as:

Tensor linalg_norm(const Tensor& self, const optional<Scalar>& opt_ord, optional<IntArrayRef> opt_dim, bool keepdim, optional<ScalarType> opt_dtype)

so you might need to change the input arguments.

I also did torch::linalg::linalg_norm(tensor, 2, {2}, false); I did not work.

Then tried

      int64_t arr[1] = {2};
      c10::IntArrayRef dim_arr = c10::IntArrayRef(arr, 1);
      result = torch::linalg::linalg_norm(
          tensor, 2, dim_arr, false, torch::dtype(torch::kFloat));

Still same error.

These functions are defined here.

You might want to use in this case linalg::vector_norm. It has signature:

Tensor vector_norm(const Tensor& self, Scalar ord, optional<IntArrayRef> opt_dim, bool keepdim, optional<ScalarType> opt_dtype)

Resulting in

result = torch::linalg::vector_norm(tensor, 2, 2, false, c10::nullopt);