/********************************************************
* ██████╗ ██████╗████████╗██╗
* ██╔════╝ ██╔════╝╚══██╔══╝██║
* ██║ ███╗██║ ██║ ██║
* ██║ ██║██║ ██║ ██║
* ╚██████╔╝╚██████╗ ██║ ███████╗
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see .
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#include "gctl/core.h"
int main(int argc, char const *argv[])
{
gctl::spmat M(6, 5, 0.0);
M.insert(3, 3, 0.1);
M.insert(2, 3, 0.2);
M.insert(2, 0, 0.3);
M.insert(1, 4, 0.4);
M.insert(0, 1, 0.5);
M.insert(4, 2, 0.6);
M.insert(5, 1, 0.7);
std::cout << "M = " << std::endl;
M.show_matrix();
gctl::spmat N(5, 6, 0.0);
N.insert(3, 3, 0.1);
N.insert(3, 2, 0.2);
N.insert(0, 2, 0.3);
N.insert(4, 1, 0.4);
N.insert(1, 0, 0.5);
N.insert(2, 4, 0.6);
N.insert(1, 5, 0.7);
std::cout << "N = " << std::endl;
N.show_matrix();
gctl::spmat Product;
M.multiply_sparse_matrix(N, Product);
std::cout << "M*N = " << std::endl;
Product.show_matrix();
std::cout << "N (list) = " << std::endl;
Product.show_list();
gctl::array V(6, 1.0);
V[3] = 2.0;
std::cout << "V = " << std::endl;
for (int i = 0; i < V.size(); i++)
{
std::cout << V.at(i) << " ";
}
std::cout << std::endl;
gctl::array MxV;
M.multiply_vector(V, MxV, gctl::Trans);
std::cout << "M^T*V = " << std::endl;
for (int i = 0; i < MxV.size(); i++)
{
std::cout << MxV.at(i) << " ";
}
std::cout << std::endl;
gctl::spmat L;
M.transpose(L);
std::cout << "L = M^T = " << std::endl;
L.show_matrix();
gctl::matrix P(5, 6);
std::cout << "P = " << std::endl;
for (int i = 0; i < P.row_size(); i++)
{
for (int j = 0; j < P.col_size(); j++)
{
P.at(i, j) = i + 0.1*j;
std::cout << P.at(i, j) << " ";
}
std::cout << std::endl;
}
gctl::matrix Product2;
M.multiply_matrix(P, Product2);
std::cout << "M*P = " << std::endl;
for (int i = 0; i < Product2.row_size(); i++)
{
for (int j = 0; j < Product2.col_size(); j++)
{
std::cout << Product2.at(i, j) << " ";
}
std::cout << std::endl;
}
return 0;
}