[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra::multi_math VIGRA

Arithmetic and algebraic functions for multi-dimensional arrays. More...

Arithmetic and algebraic functions for multi-dimensional arrays.

Namespace vigra::multi_math holds VIGRA's support for efficient arithmetic and algebraic functions on multi-dimensional arrays (that is, MultiArrayView and its subclasses). All multi_math functions operate element-wise. If you need matrix multiplication, use Linear Algebra instead.

In order to avoid overload ambiguities, multi-array arithmetic must be explicitly activated by

using namespace vigra::multi_math;

(this should not be done globally, but only in the scope where the functionality is actually used).

You can then use the standard operators in the expected way:

MultiArray<2, float> i(Shape2(100, 100)), j(Shape2(100, 100));
MultiArray<2, float> h = i + 4.0 * j;
h += (i.transpose() - j) / 2.0;

etc. (supported operators are + - * / ! ~ % && || == != < <= > >= << >> & | ^ = += -= *= /=, with both scalar and array arguments).

Algebraic functions are available as well:

h = exp(-(sq(i) + sq(j)));
h *= atan2(-i, j);

The following functions are implemented: abs, erf, even, odd, sign, signi, round, roundi, sqrt, sqrti, sq, norm, squaredNorm, gamma, loggamma, exp, log, log10, sin, sin_pi, cos, cos_pi, asin, acos, tan, atan, floor, ceil, conj, real, imag, arg, atan2, pow, fmod, min, max, provided the array's element type supports the respective function.

Supported element types currently include the built-in numeric types, TinyVector, RGBValue, std::complex, and FFTWComplex.

In addition, multi_math supports a number of functions that reduce arrays to scalars:

double s = sum<double>(i); // compute the sum of the elements, using 'double' as accumulator type
double p = product<double>(abs(i)); // compute the product of the elements' absolute values
bool a = any(i < 0.0); // check if any element of i is negative
bool b = all(i > 0.0); // check if all elements of i are positive

Expressions are expanded so that no temporary arrays have to be created. To optimize cache locality, loops are executed in the stride ordering of the left-hand-side array.

#include <vigra/multi_math.hxx>

Namespace: vigra::multi_math

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1 (Fri May 19 2017)