# Using torch::normal with the C++ frontend

I am probably missing something, but I am having trouble using the torch::normal function in the C++ API. Here’s the minimal example:

``````#include <torch/torch.h>
#include <iostream>

int main() {
torch::Tensor tensor = torch::rand({2, 3});
auto x = torch::normal(tensor,1);
std::cout << x << std::endl;
}
``````

The compilation of this example fails with:

``````/Users/dfalbel/Documents/testtorch/example-app.cpp:6:12: error: too few arguments to function call, expected at least 3, have 2; did you mean 'at::normal'?
auto x = torch::normal(tensor,1);
^~~~~
at::normal
/Users/dfalbel/libtorch/include/ATen/Functions.h:13495:22: note: 'at::normal' declared here
static inline Tensor normal(const Tensor & mean, double std, Generator * generator) {
^
1 error generated.
``````

This is can be fixed by using `at` namespace instead of `torch`. I could do that, but it seems to me that all signatures of `at::normal` (1, 2, 3, 4) should be exported in the `torch` namespace too? Does this make sense?

1 Like

It seems that the reason is that when we autogenerate wrapers for some ATen functions here

we are generating a single `torch::normal` definition and not all it’s overloaded defs.

And this seems to happen because of this line which excludes from the `variable_factories.h` all functions that don’t have TensorOptions as an argument, thus excluding the other signatures.

Adding the following to my code fixes the compiler error, but i am pretty sure it’s wrong when in autograd contexts:

``````namespace torch {

torch::Tensor normal (const torch::Tensor &mean, double std = 1, torch::Generator *generator = nullptr) {
return at::normal(mean, std, generator);
}

torch::Tensor normal (double mean, const torch::Tensor &std, torch::Generator *generator = nullptr) {
return at::normal(mean, std, generator);
}

torch::Tensor normal (const torch::Tensor &mean, const torch::Tensor &std, torch::Generator *generator = nullptr) {
return at::normal(mean, std, generator);
}

} // namespace torch
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.72153866,"math_prob":0.6580081,"size":963,"snap":"2022-27-2022-33","text_gpt3_token_len":261,"char_repetition_ratio":0.12304484,"word_repetition_ratio":0.0,"special_character_ratio":0.28556594,"punctuation_ratio":0.26244345,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97943836,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-18T09:47:13Z\",\"WARC-Record-ID\":\"<urn:uuid:d794aaa2-49a3-40ce-a798-7a66a6e2e7e0>\",\"Content-Length\":\"18808\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5c0bbc6d-45d3-4383-829c-7649a5ed931a>\",\"WARC-Concurrent-To\":\"<urn:uuid:93091503-ca1a-49f6-af37-899f654e7d00>\",\"WARC-IP-Address\":\"159.203.145.104\",\"WARC-Target-URI\":\"https://discuss.pytorch.org/t/using-torch-normal-with-the-c-frontend/68971\",\"WARC-Payload-Digest\":\"sha1:ZIEFABGM5IKLP3RSZ5WLD24JMXQOCKPW\",\"WARC-Block-Digest\":\"sha1:FFSKYZWFFBXHLUOR3ZZPELU47HHJEXVL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882573193.35_warc_CC-MAIN-20220818094131-20220818124131-00116.warc.gz\"}"}