tch-rs
tch-rs copied to clipboard
Enable the function linalg_vector_norm
This pull request is to enable the function linalg_vector_norm, disable in the original code.
I need it to compute the L2 norm of matrices and vectors.
It looks like it was disabled because of compile errors, caused by the removal of the parameter ord in the code generator, because it had a default value. After removing the default_value attribute in Declarations-v2.0.0.yaml, the code is correctly generated.
Of course, there are better solutions, but I wasn't able to make changes in the Ocaml code in gen/gen.ml.
Thank you for your time.
ping
Sorry for the delayed answer, making changes to the Definitions.yaml
file would be a bit tricky to maintain when upgrading to new torch versions. If your goal is to compute the l2 norm, maybe you can use mse_loss
or compute it directly via something like x.pow_tensor_scalar(2).sum(Kind::float).sqrt()
?
Thanks, I overlooked the fact that the files Declarations*.yaml are autogenerated. I am going to review the patch to change the code generator instead.
Note that in addition of the particular case of generating the norm, one needs the general case of having access to all the Torch API. So that one looks the documentation and finds the solution. Your solution would work for me, thank you.
I would still encourage you to try the manual computations from my previous post if you can, it's certainly easier to get working and should cover all needs of norm computations that I can think of.