#include <unsupported/Eigen/CXX11/Tensor> int main(){ // Define a tensor Eigen::Tensor<double,3> A(55,50,2); A.setRandom(); // Define the pairs of indices to multiply (i.e. index 1 on A twice) std::array<Eigen::IndexPair<long>, 1> idx = { Eigen::IndexPair<long> {1, 1} }; // Define a parallel device int num_threads = 4; Eigen::ThreadPool tpl (num_threads); Eigen::ThreadPoolDevice dev (&tpl, num_threads); // Initialize result buffer B. B will have dimensions [55,2,55,2] Eigen::Tensor<double,4> B(55,2,55,2); // Contract using the parallel device B.device(dev) = A.contract(A, idx); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter