3

I'd like to ask about mathematical operations of arrays. I am mainly interested in carrying out operations such as:

vector products:

C=A+B
C=A*B

where A and B are arrays (or vectors), and

matrix products:

D=E*F; 

where D[m][n], E[m][p], F[p][n];

Could anyone tell me what is the most efficient way to manipulate large quantities of numbers? Is it only possible by looping through the elements of an array or is there another way? Can vectors be used and how?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Adam Gosztolai
  • 242
  • 1
  • 3
  • 14
  • By the way, the D programming language, influenced by C++, has this functionality out of the box :) – vines Jan 20 '12 at 21:45
  • See e.g. [Blitz++](http://www.oonumerics.org/blitz/) – Paul R Jan 20 '12 at 21:46
  • Depends on how platform specific you want to get. On the low speed end you have just writing a loop, on the high end you have writing GPGPU code. – Billy ONeal Jan 20 '12 at 21:48

3 Answers3

4

The C++ spec does not have mathematical constructs as you describe. The language surely provides all the features necessary for people to implement them. There are a lot of libraries out there, so its just up to you to choose one that fits your requirements.

Searching through stack overflow questions might give you an idea of where to start identifying those requirements if you don't know them already.

Community
  • 1
  • 1
Tom Kerr
  • 10,444
  • 2
  • 30
  • 46
2

Check out Armadillo, it provides lots of matrix functionality in a C++ interface. And it supports LAPACK, which is what MATLAB uses for linear algebra calculations.

Jonathan
  • 616
  • 4
  • 7
1

C++ does not come with any "number aggregate" handling functionality out of the box, which the possible exception of std::valarray. (Compiler vendors could make valarray use vectorized operations, but generally speaking they don't)

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552