std::vector<torch::Tensor> turns into nans

Hello there. I really need some help on the topic.

first i am using libtorch-1.4.0 on macos and Linux.

Now i get a weird error when creating tensors with from_blob via “loading function” looking somewhat like this:

void compute(std::vector<torch::Tensor> &output)
{
    for(int i = 0; i < batch_size; i++)
    {
        std::vector<float> vec(1 * 4 * 60 * 60);
        for(auto& v : vec)
        {
            // assigning some values after computation etc
        }
        
        // creating tensor
        output.emplace_back(torch::from_blob(vec.data(), {1, 4, 60, 60}) );

    }

    // Check for nan values
    for(size_t i = 0; i < out.size(); i++)
    {
        if(at::isnan(out[i]).any().item<bool>() )
        {
             throw std::string("Error in compute");
        }
}

No error is thrown but when i check after the function returns, I get an error message on linux for some reason. sometimes macos fails afterwards but most of the time it runs without errors (maybe silent ones tho)

The constructor calling the compute() function looks like this

Environment()
{
    compute(obs_storage);
   
    for(size_t i = 0; i < storage.size(); i++)
    {    
         if(at::isnan(out[i]).any().item<bool>() )
        {
             throw std::string("Error in compute"); // ERROR for some reason
        }
    }
}

I dont really understand the problem there. because i call the exact same function twice and i get completely different results

from_blob does not copy, yet the pointer from vec.data() can’t be relied on after vec is freed.