Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MATLAB binaries

Raphael Leiteritz edited this page Apr 3, 2020 · 9 revisions

This page explains how to install and use the binaries we provide for use with MATLAB as part of every SGpp release.

Linux

  1. Extract the SGpp archive to an arbitrary location, say /PATH_TO_BINARIES.
  2. Start MATLAB with the following environment variables:
export LD_LIBRARY_PATH="/PATH_TO_BINARIES/matsgpp:$LD_LIBRARY_PATH"
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6:$LD_PRELOAD"
matlab
  1. Add /PATH_TO_BINARIES/matsgpp to the MATLAB search path, either by changing to that directory or using pathtool.
  2. Check if it works via sgpp.Grid.createLinearGrid(2).

Windows

  1. Install MinGW using msys2:
    • Download and install msys2 (x86_x64) as described here: https://www.msys2.org/
    • After finishing updating msys2, install the toolchain by running pacman -S mingw-w64-x86_64-toolchain in the msys2 command prompt
    • Prepend C:\PATH_TO_MSYS2\mingw64\bin to the PATH environment variable.
  2. Extract the SGpp archive to an arbitrary location, say C:\PATH_TO_BINARIES.
  3. Start MATLAB.
  4. Add C:\PATH_TO_BINARIES\matsgpp to the MATLAB search path, either by changing to that directory or using pathtool.
  5. Check if it works via sgpp.Grid.createLinearGrid(2).

Generating the Binaries

The following section explains how to use a fork of SWIG to directly generate the SWIG-matlab Interface. We recommend using the provided binaries! This page is mainly intended for SGpp developers who want to create binaries for a new release.

The creator of the SWIG fork has put some info to https://github.com/RobotLocomotion/drake/issues/1267. He forked SWIG to provide bindings to his own library (see https://github.com/casadi/casadi/wiki/matlab). There is an outdated version of the fork in the SWIG repository (https://github.com/swig/swig/tree/matlab). However, it doesn't seem to have been merged yet. Therefore, you have to compile the fork yourself. See http://www.swig.org/svn.html for generic instructions and http://www.swig.org/Doc2.0/Windows.html#Windows_swig_exe for compiling on Windows.

Instructions

  1. Install MATLAB.
  2. Clone the SWIG fork from https://github.com/jaeandersson/swig and change to the extracted directory.
  3. Apply the patch below to the source of the SWIG fork. The first hunk fixes a problem that occurs when calling an overridden method that has one or more arguments. The check is not correctly done in this case. The second hunk fixes the problem that inheritance is not done correctly. Otherwise, the MATLAB correspondents of subclasses don't inherit from their superclasses.
  4. If you don't have PCRE installed, you have to download the PCRE source tarball, place it in the root folder of the SWIG fork, and run Tools/pcre-build.sh.
  5. Run ./autogen.sh.
  6. Run ./configure.
  7. Run make.
  8. The executable of the SWIG fork is now located at ./swig.
  9. Clone SG++ and change to the directory of the clone.
  10. Compile SG++ with PATH=/DIRECTORY_OF_SWIG_FORK:$PATH SWIG_LIB=/DIRECTORY_OF_SWIG_FORK/Lib scons -j 4 SG_ALL=0 SG_BASE=1 SG_MATLAB=1 MATLAB_INCLUDE_PATH=/PATH_TO_MATLAB/extern/include MATLAB_LIBRARY_PATH=/PATH_TO_MATLAB/bin/glnxa64 (for Linux, adapt the last path for other platforms).
  11. The compiled MATLAB interface can be found at lib/matsgpp. Proceed as explained above for the provided binaries.

Additional Instructions for Windows

On Windows, you have to install MSYS first:

  1. Install MinGW Installation Manager (mingw-get)
  2. Install msys-base and mingw-developer-tools (inside mingw-get)
  3. Follow the instructions at http://swig.org/Doc2.0/Windows.html#Windows_swig_exe
    1. Download PCRE source tarball from their website http://www.pcre.org/
    2. Extract SWIG-matlab ZIP (from step 1) to msys/1.0 directory
    3. Start MSYS shell, change to extracted directory
    4. Run Tools/pcre-build.sh
    5. Run ./autogen.sh, ./configure, make
    6. Move extracted directory (now contains swig.exe) to desired location

Patch

diff --git a/Source/Modules/matlab.cxx b/Source/Modules/matlab.cxx
index 11c6fb9..d2f8418 100644
--- a/Source/Modules/matlab.cxx
+++ b/Source/Modules/matlab.cxx
@@ -168,7 +168,7 @@ MATLAB::MATLAB():
   /* Add code to manage protected constructors and directors */
   director_prot_ctor_code = NewString("");
   Printv(director_prot_ctor_code,
-	 "if ( argc==1 ) { /* subclassed */\n",
+	 "if ( $comparison ) { /* subclassed */\n",
 	 "  $director_new \n",
 	 "} else {\n", "   mexErrMsgIdAndTxt(\"SWIG:RuntimeError\",\"accessing abstract class or protected constructor\"); \n", "  SWIG_fail;\n", "}\n", NIL);
 
@@ -2111,6 +2111,8 @@ int MATLAB::classHandler(Node *n) {
       if (bmodoptions) {
           bpkg = Getattr(bmodoptions, "package");
       }
+      if (!bpkg)
+          bpkg = pkg_name;
       if (!bname || !bpkg || GetFlag(b.item, "feature:ignore"))
 	continue;
       base_count++;

Clone this wiki locally