Libtorch c++ equivalent of F.normalize(x, p=2, dim=1)

To normalise, in python I simply do:

F.normalize(x, p=2, dim=1)

I was wondering what is the libtorch c++ equivalent of this.

This should work:

namespace F = torch::nn::functional;
F::normalize(input, F::NormalizeFuncOptions().p(1).dim(-1));
1 Like

Awesome! thank you @ptrblck your help is invaluable.