From 060163d4c45062ef2137031936f04fcc91062159 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Sun, 21 Nov 2021 22:22:01 +0100 Subject: [PATCH] simple.h and simple.cc for algorithms independent on external libraries --- Makefile.am | 4 +- simple.cc | 28 ++++++++++++++ simple.h | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ t.cc | 2 + vecmat3.h | 61 ----------------------------- 5 files changed, 141 insertions(+), 63 deletions(-) create mode 100644 simple.cc create mode 100644 simple.h diff --git a/Makefile.am b/Makefile.am index fd65b12..8755b2d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ lib_LTLIBRARIES = libla.la -include_HEADERS = vecmat3.h quaternion.h fortran.h cuda_la.h auxstorage.h davidson.h laerror.h mat.h qsort.h vec.h bisection.h diis.h la.h noncblas.h smat.h bitvector.h fourindex.h la_traits.h nonclass.h sparsemat.h sparsesmat.h csrmat.h conjgrad.h gmres.h matexp.h permutation.h polynomial.h -libla_la_SOURCES = quaternion.cc vecmat3.cc vec.cc mat.cc smat.cc sparsemat.cc sparsesmat.cc csrmat.cc laerror.cc noncblas.cc bitvector.cc strassen.cc nonclass.cc cuda_la.cc fourindex.cc permutation.cc polynomial.cc +include_HEADERS = simple.h vecmat3.h quaternion.h fortran.h cuda_la.h auxstorage.h davidson.h laerror.h mat.h qsort.h vec.h bisection.h diis.h la.h noncblas.h smat.h bitvector.h fourindex.h la_traits.h nonclass.h sparsemat.h sparsesmat.h csrmat.h conjgrad.h gmres.h matexp.h permutation.h polynomial.h +libla_la_SOURCES = simple.cc quaternion.cc vecmat3.cc vec.cc mat.cc smat.cc sparsemat.cc sparsesmat.cc csrmat.cc laerror.cc noncblas.cc bitvector.cc strassen.cc nonclass.cc cuda_la.cc fourindex.cc permutation.cc polynomial.cc check_PROGRAMS = t test t_SOURCES = t.cc t2.cc test_SOURCES = test.cc diff --git a/simple.cc b/simple.cc new file mode 100644 index 0000000..9214da7 --- /dev/null +++ b/simple.cc @@ -0,0 +1,28 @@ +/* + LA: linear algebra C++ interface library + Copyright (C) 2021 Jiri Pittner or + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "simple.h" + +namespace LA_Simple { + + + + + +} + diff --git a/simple.h b/simple.h new file mode 100644 index 0000000..ef01db5 --- /dev/null +++ b/simple.h @@ -0,0 +1,109 @@ +/* + LA: linear algebra C++ interface library + Copyright (C) 2021 Jiri Pittner or + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +//this header defines some simple algorithms independent of external libraries +//particularly intended to embedded computers +//it should be compilable separately from LA as well as being a part of LA + +#ifndef _SIMPLE_H_ +#define _SIMPLE_H_ + +#include +#ifndef AVOID_STDSTREAM +#include +#endif +#include +#include +#include + +namespace LA_Simple { + +//a simple gauss elimination as a template also for larger-size matrices in form of C-style arrays +#define SWAP(a,b) {T temp=(a);(a)=(b);(b)=temp;} + +template +T simple_gaussj(T (&a)[n][n],T (&b)[m][n]) //returns determinant, m is number of rhs to solve +{ + int indxc[n],indxr[n],ipiv[n]; + int i,icol,irow,j,k,l,ll; + T det,big,dum,pivinv; + + det=1; + for (j=0;j= big) { + big=abs(a[j][k]); + irow=j; + icol=k; + } + } else if (ipiv[k] > 1) {return 0;} + } + ++(ipiv[icol]); + if (irow != icol) { + det = (-det); + for (l=0;l=0;l--) { + if (indxr[l] != indxc[l]) + for (k=0;k +class simple_linfit { +T mata[n][n]; +T matb[1][n]; +public: +}; + + +//stream I/O +#ifndef AVOID_STDSTREAM +#endif + + +}//namespace +#endif /* _SIMPLE_H_ */ + diff --git a/t.cc b/t.cc index bf89030..7b0d529 100644 --- a/t.cc +++ b/t.cc @@ -24,10 +24,12 @@ #include "quaternion.h" #include "permutation.h" #include "polynomial.h" +#include "simple.h" using namespace std; using namespace LA_Vecmat3; using namespace LA_Quaternion; +using namespace LA_Simple; using namespace LA; diff --git a/vecmat3.h b/vecmat3.h index 5a9b95f..7c4f50a 100644 --- a/vecmat3.h +++ b/vecmat3.h @@ -157,67 +157,6 @@ public: }; -//a simple gauss elimination as a template also for larger-size matrices in form of C-style arrays -#define SWAP(a,b) {T temp=(a);(a)=(b);(b)=temp;} - -template -T simple_gaussj(T (&a)[n][n],T (&b)[m][n]) //returns determinant, m is number of rhs to solve -{ - int indxc[n],indxr[n],ipiv[n]; - int i,icol,irow,j,k,l,ll; - T det,big,dum,pivinv; - - det=1; - for (j=0;j= big) { - big=abs(a[j][k]); - irow=j; - icol=k; - } - } else if (ipiv[k] > 1) {return 0;} - } - ++(ipiv[icol]); - if (irow != icol) { - det = (-det); - for (l=0;l=0;l--) { - if (indxr[l] != indxc[l]) - for (k=0;k