#include #include #include "gematrix.h" template T init_value(Index i, Index j, Index m, Index n) { return T(j)*T(n) + T(i) + T(1); } template std::complex init_complex_value(Index i, Index j, Index m, Index n) { return std::complex(T(i), T(j)); } void print_value(double value) { std::printf(" %10.1lf", value); } void print_value(std::complex value) { std::printf(" (%4.1lf, %4.1lf)", value.real(), value.imag()); } template void print_matrix(const Matrix& A) { for (std::size_t i = 0; i < A.m; ++i) { std::printf(" "); for (std::size_t j = 0; j < A.n; ++j) { print_value(A(i, j)); } std::printf("\n"); } } template struct RandomValues { std::mt19937 mt; std::uniform_real_distribution uniform; RandomValues() : mt(std::random_device()()), uniform(-100, 100) { } RandomValues(unsigned int seed) : mt(seed), uniform(-100, 100) { } T operator()(Index i, Index j) { return uniform(mt); } }; template struct IncreasingRandomValues { std::mt19937 mt; std::uniform_real_distribution uniform; T last_value; IncreasingRandomValues() : mt(std::random_device()()), uniform(0, 1<<16), last_value(0) { } IncreasingRandomValues(unsigned int seed) : mt(seed), uniform(1, 1<<16) { } T operator()(Index i, Index j) { last_value += uniform(mt); return last_value; } }; int main() { using namespace matvec; GeMatrix A(3, 7, StorageOrder::ColMajor); initGeMatrix(A, RandomValues(42)); printf("A:\n"); print_matrix(A); GeMatrix B(2, 8, StorageOrder::ColMajor); initGeMatrix(B, RandomValues(42)); printf("B:\n"); print_matrix(B); GeMatrix C(3, 7, StorageOrder::ColMajor); initGeMatrix(C, IncreasingRandomValues()); printf("C:\n"); print_matrix(C); }