Coder Social home page Coder Social logo

widelee / mex-it Goto Github PK

View Code? Open in Web Editor NEW

This project forked from audiofilter/mex-it

0.0 2.0 0.0 99 KB

Automatically mex C/C++ functions for Matlab or Octave (with C++11 compiler)

License: MIT License

Makefile 0.35% CMake 44.64% C++ 49.86% M 0.12% C 0.08% MATLAB 4.90% Objective-C 0.06%

mex-it's Introduction

mex-it

C++ 11 code to automatically create Matlab mex function based on generic C++ functions.

###Only a single header file "mex-it.h" is required

The methodology is based on that used in the dlib library

  • supply the mex_function and let the compiler do the rest.

However, the code was completely reworked to use as many classes from std C++11 as possible and to make use of variadic templates to greatly reduce the amount of code needed.

  • Currently code to callback matlab is not part of this library.

This supports basic C++ data types. Has limited support for Eigen Matrices (Matrix type of double + ColMajor), plus Eigen Vectors (see examples)

####How does the compiler know the inputs and outputs?

  • Non-const references mean outputs
  • Everything else are inputs

Building

  • Use either Cmake or setup your own mex script
  • Works on Mac OS X, Linux & Windows (mingw32/g++ or Visual Studio 2013)

Build status

  • Linux : Travis Build Status
  • Windows/mingw32/g++/Octave 4.0 : AppVeyor Build status

Example

Create a c++ implementation file like this

void mex_function(const double &x, const double &y, const double &z, double& result) {
	result = (x + y)*z;
}
#include "mex-it.h"

Matlab driver for this

x = 3;
y = 4;
z = 5;
result = simple_example(x,y,z);

Then build with CMake or using mex within Matlab

For single file example, you can do this in matlab (for recent GCC/Clang)

mex CXXFLAGS="\$CXXFLAGS -std=c++11" simple_example.cpp

Requirements

Eigen needed for Eigen examples

  • Assumes Eigen is in either /usr/local/include/eigen3 or /usr/include/eigen3 or eigen3, please edit FindEigen.cmake for other paths

Other examples

C++ files starting with test_ are examples that can't generate mex files but do test the interfaces in pure C++ using mex header files

  • test_eig_add.cpp -> Test of adding 2 Eigen Matrices of type 'double'
  • test_eig_mult.cpp -> Test of multipling 2 Eigen Matrices of type 'double'
  • test_vector_add.cpp -> Test of adding std::vector
  • test_mex.cpp -> Uses include of 'mex_function.h' to test the function in 'mex_function.cpp'

Mex example

  • eigen_add.cpp -> For creating mex function adds 2 eigen matrices
  • simple_example.cpp -> A very basic example that returns (x+y)*z for inputs x,y, and z
  • vector_example.cpp -> An example that returns (x+y)*z for inputs x,y, and z
  • eigen_vector_example.cpp -> An example of a vector add for Eigen (double) vectors
  • eigen_example.cpp -> Same example as in test_eig_add.cpp but here can generate a mex function

Matlab/Octave Scripts to test

  • test_eigen_vector_example.m -> Test of adding 2 Eigen Vectors of type 'double' - also checks if wrong type is used
  • test_eigen_matrix_example.m -> Test of adding 2 Eigen Matrices of type 'double' - also checks if wrong type is used
  • test_vector_example.m -> Test of adding 2 std::vector - also checks if wrong type is used
  • test_types.m -> Make sure input types match expected types

mex-it's People

Contributors

audiofilter avatar widelee avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.