Why does my native library behave differently when wrapped using clibgen?
Mostrar comentarios más antiguos
I have a native Windows library written in C++ and compiled with the MSVC compiler which contains one class (we'll call it MyClass since I can't provide the actual code for security reasons). MyClass has some std::vector<double> members that serve as input data to a MyClass member function (void myFun()--no input or output args) and also has some std::vector<double> members that serve as output parameters from that function.
I have also used clibgen to build a shared library so that MATLAB can use MyClass. However, I need to make sure that the outputs I get when both matlab and C++ call the function are EXACTLY the same, which I haven't been able to achieve. To test equality between matlab and c++ I am doing the following:
- Create a MyClass object in c++ (cppobj)
- Populate the input parameters of cppobj
- Run myFun() from cppobj
- Write the input and output (all elements) of cppobj to binary files
- Load the data of these binary files into two matlab objects, one with both inputs and outputs (matobj_cppout), and one with just inputs (matobj_matout)
- Run myFun() on matobj_matout
- Compare the output parameters of matobj_cppout and matobj_matout
I've calculated small differences in the output values even though they SHOULD be exactly the same, since the function is deterministic and the input parameters in matobj_cppout and matobj_matout are identical. This leads me to believe that MATLAB is doing some kind of conversion either when the binary files or read or when the values are stored to the native MyClass object using the "clib" functionality. I've verified that I'm using fp:precise both when building the native library and when running clibgen.
Any ideas of what could be causing these discrepancies?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Build MATLAB Interface to C++ Library en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!