wiki:hpp-valarray
Table of Contents
<valarray>
<valarray> provides std::valarray<T>, a vector-like container optimized for mathematical operations: elementwise operations, slicing, and masking. Most scientific code uses Eigen or NumPy instead.
valarray has an odd API and is rarely used in practice.
Example
This example performs elementwise addition on two valarrays, demonstrating the vectorized operations this container provides.
// compile: g++ -std=c++11 -o valarrayexample valarrayexample.cpp // run: ./valarrayexample // description: elementwise valarray operations #include <valarray> #include <iostream> int main() { std::valarray<int> a{1, 2, 3}; std::valarray<int> b{4, 5, 6}; std::valarray<int> c = a + b; std::cout << "sum: "; for (int x : c) std::cout << x << " "; std::cout << "\n"; return 0; }
wiki/hpp-valarray.md · Last modified: by 127.0.0.1
