Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting Matlab arrays to C/C++

I am porting a matlab program to C/C++. I have several problems with it but one of the most important ones is here: Matlab treats arrays with any dimension the same. Assume we have a function like this,

function result = f(A, B, C)
result = A + 2 * B + C;

A, B, and C can be arrays of any dimensions/size. I am not a C/C++ pro, but I guess it is not a simple & clean job in C. One idea is to use void pointers to pass the arrays to the function. What should I do with the dimensions and array operations (+/*) then? The other idea is to use C++ classes. I might be able to write a template class with all the required array operations such as (*, +, <<, >>, ...). But I am sure it's going to be an exhausting job. Does anybody have a better idea? Any simple/multidimensional/single header file/opensource array class that supports + and * operators?

like image 812
Helium Avatar asked Jan 20 '23 07:01

Helium


1 Answers

You could have a look at the boost::ublas library. It supports vectors, matrices, linear algebra etc.

like image 175
Darren Engwirda Avatar answered Jan 28 '23 05:01

Darren Engwirda