In short, I would love any and all kind of help in expanding the following project of mine. Keeping formalities short, here’s the relevant description.
MATLAB is among the most popular softwares in existence for numerical computation. It is widely used in all manner of scientific investigations including electrical, mechanical, chemical, [you name it] engineering.
As it turns out, most newbies to MATLAB find it challenging to adapt to coding in MATLAB when they realize that the code that they write in C, C++, Java etc., as written in C, C++, Java, runs painfully slowly under MATLAB. The reason for this is MATLAB’s nature as an interpreted language where there is a significant runtime overhead to running every line of code (for e.g., the data type compatibility must be checked, indexing validity must be checked etc.). This puts the requirement on the programmer that a large amount of work is done in each statement i.e. the requirement that the code be “vectorized”.
HOWEVER, as it so happens, some algorithms simply cannot be wrtten in a vectorized manner. A simple example would be to find the cumulative sum of a given vector. Fortunately, matlab includes a function that efficiently executes the above computation. However, there are several other, less fortunate cases where the best one seems to be able to do is write a for loop and lament as MATLAB takes an eternity to execute the code.
Having recognized the above problem, MATLAB provides an interface to use C/C++ to program called MATLAB EXtensions or MEX for short. This interface is an elegant C interface that enables us to access the underlying data in existing MATLAB vectors/matrices and perform the non-vectorizable computation in the FAST C language and return data back to MATLAB in a MATLAB vector/matrix.
However, as C++ programmers, we are used to the neat functionality offered by the C++ Standard Library (e.g. std::vector), static time polymorphism, and especially RAII. These features are entirely missing if we only restrict ourselves to the C interface provided by MEX.
I Have found out that one CANNOT use the C++ standard library to manipulate memory that is returned to MATLAB due to various reasons (e.g. Alignment Requirements and compulsory deallocation at the end of scope).
Thus, I have developed a set of headers in my repository MexMemoryInterfacing which implements two classes MexVector and MexMatrix that allow me to perform a zero-cost wrapping over MATLAB Data. The Additional features are listed below.
The relevant code can be found in the repository titled MexMemoryInterfacing at the following link.
https://github.com/maharjun/MexMemoryInterfacing
The code in the following repositories uses MexMemoryInterfacing
https://github.com/maharjun/TimeDelNetSim
https://github.com/maharjun/PolychronousGroupFind
https://github.com/maharjun/Grid2D
https://github.com/maharjun/GetAttractionBasin
The features that have currently been implemented are as below.
MexVector<DataType>
can wrap any MATLAB Vector of any data type.MexMatrix<DataType>
can wrap any MATLAB Matrix of any data type.MexVector
attempts to mirror the interface offered by std::vectorMexVector
has interfaces that allow it interact with standard library iteratorsMexVector
is capable of wrapping cell arrays as MexVector<MexVector<...>>
Well, All of the skills can be learned on the job (willing to mentor). But, in order to contribute, you will need to be familiar with the following
This seems interesting. If I understand it correctly, the project allows us to utilize C++'s superior performance for the non-vectorizable work we are doing in MATLAB?
Can you expand on specific examples where you found it useful in your work?
--
--
The website for the club is http://wncc-iitb.org/
To post to this group, send email to wncc...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
The website for the club is http://wncc-iitb.org/
To post to this group, send email to wncc...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.