xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.33k stars 398 forks source link

Issue regarding cout and xstorage.hpp #1778

Open ccphysics opened 4 years ago

ccphysics commented 4 years ago

I have continuously had trouble with output streams since I started using xtensor, and I don't really understand what the problem is. For example, I have the code:

#include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xmath.hpp"
#include "xtensor/xview.hpp"
#include "xtensor/xcomplex.hpp"
#include "xtensor-blas/xlinalg.hpp"

using namespace std;
using namespace xt; 

int main()
{
    auto test = empty<double>({ 5,5 });
    auto test1 = ones_like(test);
    cout << test1;
    cout << test;
        return 0;
}

And when running, it throws an exception that states:

Exception thrown at 0x00AFF5D8 in FileName.exe: 0xC0000005: Access violation executing location 0x00AFF5D8.

and says the error lies in line 1230 of xstorage.hpp. The only way I've found to get around this is to comment out all of the output streams when this happens, run the code, and then uncomment the output streams. Then it works. (For clarity, I'm using Visual Studio)

JohanMabille commented 4 years ago

I could not reproduce on master. Which version do you use? Also do both output fail ?

wolfv commented 4 years ago

What compilation options are you using?

ccphysics commented 4 years ago

I downloaded xtensor about a month ago, but I'm not sure what version. Both outputs have failed, but not predictably. The only reason there is two is because I got the first one working by the method I mentioned, so I added in the second to see if it would fail again and it did.

I'm not sure about compilation options. On visual studio I'm using the Local Windows Debugger

JohanMabille commented 4 years ago

Could you try with the last version? We fixed a lot of issues in 0.20.9 that was released less than a month ago (so hopefully it is more recent than the one you've downloaded).

ccphysics commented 4 years ago

Sure. I'll give it a try and leave another reply in a bit.

ccphysics commented 4 years ago

Doesn't look like it changed. I am getting the message:

Exception thrown at 0x003AEBC0 in FileName.exe: 0xC0000005: Access violation executing location 0x003AEBC0.

With the line in question being line 1231 of xstorage.hpp