移植Matlab的阵列C / C ++ [英] Porting Matlab arrays to C/C++

查看:210
本文介绍了移植Matlab的阵列C / C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植MATLAB程序,以C / C ++。我有几个问题,但最重要的问题之一是在这里:Matlab的对待阵列,任何尺寸相同。假设我们有这样的功能,

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 的和的 C 的可以是任意尺寸/大小的数组。我不是一个C / C ++亲,但我想这不是一个简单的&安培;在C.一个想法的清洁工作是使用空指针数组传递给函数。我应该怎么做的尺寸和数组操作(+ / *)呢?
另一个想法是使用C ++类。我也许可以写一个模板类的所有必需的数组操作,如(*,+,LT;&LT ;, >> ...)。但我相信这将是一个辛苦的工作。没有任何人有一个更好的主意吗?支持+和*操作?任何简单/多维/单头文件/开源数组类

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?

推荐答案

我会建议你使用C ++类。当然,没有实现自己的这些类。还有人在那里这样的任务做了出色的工作。 @Darrem建议嘘声:: uBLAS库。我会建议。它更多的功能,的差别的,这是很好的维护,它支持编译器的宽量,其性能是接近,有时不是像英特尔MKL专有库更好。

I would recommend you to use C++ classes. Of course do not implement those classes yourself. There are people out there doing an excellent job in such a task. @Darrem suggested boos::ublas. I would recommend eigen. It much more functionality that ublas, it is well maintained, it supports a wide amount of compilers and its performance it is close and sometimes better than proprietary libraries like Intel MKL.

这篇关于移植Matlab的阵列C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆