The C++ equivalent of numpy.linalg.norm?

Hello,
In Pytorch/Python I am generating Resnet34 feature vectors,e.g. a vector of size 512 for a single image which I normalise using:
numpy.linalg.norm.

What is the equivalent form in libtorch? This (libtorch 1.2) does not seem to work.

torch::Tensor out_tensor = module.forward({input_tensor}).toTensor();
const auto dimensions = out_tensor.ndimension();
const auto v_size = out_tensor.size(1); //Should be 512
//std::cout << out_tensor.norm().item() <<std::endl;
std::cout << torch::norm(out_tensor) <<std::endl;

The code in PyTorch:

f =features[i].cpu().detach().numpy()
f= f / np.linalg.norm(f)

Thanks,

Dear dambo,

I had the same concerns as you, and designed a cpp function, linalg_norm [1] using the LibTorch that performs the functions of the numpy.linalg.norm.
Actually, the LibTorch also provides Function torch::linalg::norm() [2], but I cannot use it because I don’t know the required data types for the function.

I hope this reply is helpful to you.

Best regards,
Vujadeyoon

[1] How to convert numpy.linalg.norm to LibTorch codes

[2] Function torch::linalg::norm(const Tensor&, const optional<Scalar>&, OptionalIntArrayRef, bool, optional<ScalarType>) — PyTorch master documentation