152 lines
3.4 KiB
C++
152 lines
3.4 KiB
C++
#include <blaze/Math.h>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
using namespace blaze;
|
|
|
|
void static_vector()
|
|
{
|
|
StaticVector<int, 3, rowVector> vec_row{ 1, 2, 3 };
|
|
StaticVector<int, 3, columnVector> vec_col{ 4, 5, 6 };
|
|
StaticMatrix<int,1,3> mat_row{{1, 2, 3}};
|
|
StaticMatrix<int,3,1> 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<int, rowVector> vec_row{ 1, 2, 3 };
|
|
DynamicVector<int, columnVector> vec_col{ 4, 5, 6 };
|
|
DynamicMatrix<int> mat_row{{1, 2, 3}};
|
|
DynamicMatrix<int> 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<int, 8, rowVector> 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<int> 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<int> 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<int, 8> 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<int, 8> 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<int> idx = {1, 2, 3, 4, 5, 6, 7, 0};
|
|
StaticMatrix<int, 8, 8> 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<int, 8, rowVector> vec = coeff * mat;
|
|
cout << "vec:" << endl;
|
|
cout << vec;
|
|
|
|
// StaticMatrix receives dot product n * M
|
|
StaticMatrix<int, 1, 8> mat2;
|
|
row(mat2,0) = coeff * mat;
|
|
cout << "mat2:" << endl;
|
|
cout << mat2;
|
|
|
|
// Extend Dynamic Matrix with reserve()
|
|
DynamicMatrix<int> 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<int, rowVector> asc = coeff << 2;
|
|
cout << "asc" << endl << asc << endl;
|
|
}
|