I wrote some sample code to interface MATLAB - PyTorch/Libtorch by the use of C++ and Libtorch.
I did it because for our application it was not an option to write to binary and load it (because of performance issues).
You can find the sample code here:
As I am rather new to C++, the code is by no means clean, but it (should) work.
The CMakeLists.txt builds an arbitrary shared dummy library as well as the actual interface which will be a .mex file for the use in MATLAB.
Nice work and really useful. I had troubles on Mac OS x when using find_package(Matlab) in Cmake. I changed one line in your CmakeLists.txt and it worked flawless: