#include #include using namespace std; using namespace blaze; void static_vector() { StaticVector vec_row{ 1, 2, 3 }; StaticVector vec_col{ 4, 5, 6 }; StaticMatrix mat_row{{1, 2, 3}}; StaticMatrix mat_col{{4}, {5}, {6}}; cout << "Static" << endl; cout << "vec_row" << endl << vec_row; cout << "vec_col" << endl << vec_col; cout << "mat_row" << endl << mat_row; cout << "mat_col" << endl << mat_col; } void dynamic_vector() { DynamicVector vec_row{ 1, 2, 3 }; DynamicVector vec_col{ 4, 5, 6 }; DynamicMatrix mat_row{{1, 2, 3}}; DynamicMatrix mat_col{{4}, {5}, {6}}; cout << "Dynamic" << endl; cout << "vec_row" << endl << vec_row; cout << "vec_col" << endl << vec_col; cout << "mat_row" << endl << mat_row; cout << "mat_col" << endl << mat_col; } void slicing_vector() { StaticVector coeff{ 1, 2, 3, 4, 5, 6, 7, 8 }; cout << "coeff" << endl << coeff; for (auto& c : coeff) { cout << c; cout << endl; c *= 2; } cout << "coeff" << endl << coeff; // Subvector auto sv = subvector<2,6>(coeff); cout << "sv" << endl << sv; // Elements elements(coeff, {0,7}) += 8; cout << "coeff" << endl << coeff; // Element Shifter with initializer_list { coeff = { 0, 0, 0, 0, 0, 0, 0, 1 }; const initializer_list idx = {1, 2, 3, 4, 5, 6, 7, 0}; cout << "coeff 1:" << endl; for (int i=0; i < idx.size(); i++) { cout << coeff; coeff = elements(coeff, idx); } } // Element Shifter with vector { coeff = { 0, 0, 0, 0, 0, 0, 0, 1 }; const vector idx = {1, 2, 3, 4, 5, 6, 7, 0}; cout << "coeff 2:" << endl; for (int i=0; i < idx.size(); i++) { cout << coeff; coeff = elements(coeff, idx); } } // Element Shifter with fixed array { coeff = { 0, 0, 0, 0, 0, 0, 0, 1 }; const array idx = {1, 2, 3, 4, 5, 6, 7, 0}; cout << "coeff 3:" << endl; for (int i=0; i < idx.size(); i++) { cout << coeff; coeff = elements(coeff, idx); } } // Element Shifter with procedural array { coeff = { 0, 0, 0, 0, 0, 0, 0, 1 }; array idx = {0}; for (int i=0; i < idx.size()-1; i++) { idx[i] = i+1; } cout << "coeff 4:" << endl; for (int i=0; i < idx.size(); i++) { cout << coeff; coeff = elements(coeff, idx); } } // Element Shifter with initializer_list and mat { // Rotate coeff using indexes and fill matrix with rotated coeffs coeff = { 1, 2, 3, 4, 5, 6, 7, 8 }; const initializer_list idx = {1, 2, 3, 4, 5, 6, 7, 0}; StaticMatrix mat; for (int i=0; i < idx.size(); i++) { cout << coeff; row(mat, i) = coeff; coeff = elements(coeff, idx); } cout << "mat:" << endl; cout << mat; // StaticVector receives dot product n * M StaticVector vec = coeff * mat; cout << "vec:" << endl; cout << vec; // StaticMatrix receives dot product n * M StaticMatrix mat2; row(mat2,0) = coeff * mat; cout << "mat2:" << endl; cout << mat2; // Extend Dynamic Matrix with reserve() DynamicMatrix mat3; mat3.reserve(idx.size()); for (int i=0; i < idx.size(); i++) { cout << coeff; mat3.resize(rows(mat3)+1, coeff.size()); row(mat3, i) = coeff; coeff = elements(coeff, idx); } cout << "mat3:" << endl; cout << mat3; } // Shift DynamicVector asc = coeff << 2; cout << "asc" << endl << asc << endl; }