xtensor

C++ library for multi-dimensional arrays with broadcasting and lazy evaluation.

brewmacoslinux
Try with needOr install directly
Source

About

Multi-dimensional arrays with broadcasting and lazy computing

Examples

create a multi-dimensional array in C++$ cat > example.cpp << 'EOF' #include <xtensor/xarray.hpp> int main() { xt::xarray<double> arr {{1, 2, 3}, {4, 5, 6}}; return 0; } EOF
perform element-wise operations on arrays$ cat > math.cpp << 'EOF' #include <xtensor/xarray.hpp> int main() { xt::xarray<int> a {1, 2, 3}; xt::xarray<int> b {4, 5, 6}; auto result = a + b; return 0; } EOF
use broadcasting to combine differently shaped arrays$ cat > broadcast.cpp << 'EOF' #include <xtensor/xarray.hpp> int main() { xt::xarray<double> mat {{1, 2}, {3, 4}}; xt::xarray<double> vec {10, 20}; auto result = mat + vec; return 0; } EOF
compile C++ code using xtensor headers$ clang++ -I$(brew --prefix xtensor)/include example.cpp -o example
use lazy evaluation to optimize array computations$ cat > lazy.cpp << 'EOF' #include <xtensor/xarray.hpp> int main() { xt::xarray<int> a {1, 2, 3}; xt::xarray<int> b {4, 5, 6}; auto lazy_result = a + b * 2; return 0; } EOF