barrowing function across c++ libraries (newbie) - c++

I would like to know how one goes about adding functionality from one open source c++ library to another. To make things concrete, here is an example. I really like the "find" function in the Armadillo library and now that i find myself using eigen more
i kinda miss it. How hard would it be to write an equivalent of "find" that would be fully integrated into eigen (i.e. using eigen objects etc...)? How does one go about doing this? Where can i find the source code of the "find" function?
thanks in advance,

You will have to write it on your own, taking into consideration differences between libraries. It may require some knowledge about the library that you are trying to extend, though.
Start from reading the code of armadillo, to understand what they do in this function. Then proceed to understand how analogous structures are implemented in eigen and modify the code. If you want to integrate it into eigen, so that you need to link against only one library (only your custom eigen, not standard eigen and your custom eigen extensions), you will need to compile eigen with your files added to a Makefile/Cmake (or whatever eigen is using).
You can find sources of armadillo in tar.gz archive here: http://arma.sourceforge.net/download.html
If you ask where is find operator in armadillo sources, check include/armadillo_bits/op_find_bones.hpp and include/armadillo_bits/op_find_meat.hpp

Related

AutoRegression Moving Average (ARMA) libraries for c++

Is there any libraries for c++ that allows for computation of ARMA for a time series? I have not been able to find any after several search attempts.
Thanks!
Cronos is an open source library written in C++ which supports ARMA models. Although it doesn't have any documentation, it seems straightforward to use.
You can also refer to this question on stackoverflow.

Eigenvalue library for c++, recommendations, how to implement, looking for something similar to dgeev from fortran

I am new to C++, with some training using fortran95. Trying to convert my knowledge into the new syntax but have run into a snag.
Many of my programs use modules with subroutines, and subroutines within subroutines and use of functions from a library described by NAG.com which are readily available and searchable.
I am currently looking for a c++ version of
http://www.nag.com/numeric/FL/manual/pdf/F08/f08naf.pdf
From what I have read so far, these libraries exist for c++ and I have used some simple ones thus far(like vector, cmath, math.h) but only ones that are already included in my Xcode package for my mac.
I haven't seen anybody mention one of these which my be included with my Xcode, and I am lacking in how to implement outside libraries I find. I am interested particularly in using:
http://www.alglib.net/download.php
Thus far I have been using subrutines as void type functions and simply including them in all of my code. But my code is becoming exceedingly cumbersome and I would like to make something similar to a fortran module to do chebyshev calculations. And I would much rather find a good library of eignevalue calculators and maybe even chebyshev calculators, . . . which I can use.
Essentially my question is, how do I implement external libraries I find and does anybody have a recommendation for a good one? How can I make my own code which contains a callable set of functions and then call it from within another piece of code?
If I understand right, the part of the NAG library you're using in Fortran is basically LAPACK. There is a C interface to LAPACK, called LAPACKE (http://www.netlib.org/lapack/lapacke.html). You can use it in a C++ program.
I didn't understand the other parts of your question.

Double Numerical Integration in C++

I am looking for a good way to compute a double integral numerically using pre-written C++ libraries. The basic integral I'm dealing with is this:
I've done some research and discovered a few libraries that might be useful, however I'm not sure which one to choose based on the problem I'm dealing with. The libraries I have looked at are
GSL - The problem here is it's written in C and so I would have to
find some kind of wrapper to make it compatible with my research
codes.
Cuba - This library seems very appropriate and well documented.
However I would like to avoid importing an entirely new library if I
can because I'm already importing Boost and Blitz and would like to
keep the hassle of compiling everything to a minimum.
Boost - From what I have read in their documentation Boost has
methods for integrating ODE's, but I could not find any libraries
for numerically integrating double integrals of functions. Am I
missing something? This would be the most convenient option as I
already use Boost in my codes and its already in C++.
So my question essentially boils down to this:
Which of these three libraries would be most useful for my purposes? Is it possible to conduct the integral I have specified using Boost? Additionally any tips on how to implement this integral using any of the above libraries would be greatly appreciated.
Take a look at these sources, calling c code from c++ is generally not problematic. It's going the other direction that can be.
How to mix C and C++
How to Call C Function in C++, C++ Function in C (Mix C and C++)

Implement matlab code in C++?

I have a certain code written in Matlab. I wanted to obtain similar results using a c++ code. I wanted to know whether a c++ library exists for matrix manipulations? My current Matlab code consists of matrix multiplications,inverse and complements.
There are dozens of linear algebra libraries for C++. Here is another one not mentioned in the other links so far:
http://www.alglib.net/
I have used Newmat in a similar situation.
Not sure if this would help you, or your company/university have licenses for it but matlabcoder can export your matlab code to c++ without much extra work.
http://www.mathworks.com/products/matlab-coder/

Call C++ code from MATLAB?

I have some code which I need to code in C++ due to heavy reliance on templates. I want to call this code from MATLAB: basically, I need to pass some parameters to the C++ code, and have the C++ code return a matrix to MATLAB. I have heard this is possible with something called a MEX file which I am still looking into. However I am not sure what is supported in these MEX files. Is all of C++ (e.g. STL and Boost) supported? How difficult is it?
EDIT: I don't need any shared libraries, just header-only stuff like shared_ptr.
Have a look at the MEX-files Guide, especially Section 25–27 for C++.
The basic STL/Boost data structures should work, but threading with Boost could be a problem.
cout will not work as expected in C++, mexPrintf has to be used instead.
It's certainly possible to write C++ MEX files which use STL and boost. In general, you should be able to do anything you please inside a C++ MEX file. The main practical restriction is that MATLAB already ships with a bunch of libraries, so if you're using one of the boost pieces that needs a shared library (some are header-only), you'll need to match the version you compile against with that shipping with MATLAB.
For instance, MATLAB R2009b ships with boost 1.36 (you can tell by looking at the names of the libraries in <matlabroot>/bin/<arch>).
The C++ files are actually compiled by an external compiler. Use mex -setup to select which one (here is a list of supported compilers). Therefore, you shouldn't have too many weird things happen, nor should you be too restricted by what you can do.
I did some MEX stuff last year, and my memory is a bit rusty, but you do need to construct MATLAB arrays using MEX functions. I found the MATLAB documentation adequate, and the whole experience not too painful.
STL is definitely supported. Boost probably yet. The point is as long you have your STL and BOOST deployed on your computer, you should be good to go.