Git Product home page Git Product logo

cvmlib's Introduction

cvmlib

CVM Class Library.

This C++ class library encapsulates concepts of vector and different matrices including square, band, symmetric and hermitian ones in Euclidean space of real and complex numbers. It utilizes BLAS and LAPACK Fortran libraries in order to achieve the best numerical performance possible. Along with basic vector and matrix arithmetic it contains different algorithms including norm computations, elementary transformations, solving of linear systems of kind Ax=b and AX=B, singular value decomposition, matrix rank and determinant computation, non-symmetric and symmetric eigenvalue problem (including Cholesky and Bunch-Kaufman factorization), LU factorization, QR, RQ, LQ and QL factorizations, different linear least square problems solutions, square matrix polynomials, square matrix inversion, pseudo (generalized) inversion and square matrix exponent. All these algorithms are implemented for real and complex numbers. Functional classes, vectors and matrices are later additions to the library (since ver. 7.0). The library is distributed under the Boost Software License, Version 1.0. See http://cvmlib.com for binaries and more details.

Building source code

Intel toolkit is recommended (see here):

wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt update
sudo apt install intel-basekit
source /opt/intel/oneapi/compiler/latest/env/vars.sh
mkdir build
cmake -DCMAKE_Fortran_COMPILER=ifx -DMKL=ON -DILP64=ON -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -S . -B build
cd build
make -j
../lib/cvm_test

Examples

Sine integral derivative:

    cvm::rfunction f("{x} sinint(x)");
    cvm::rfunction fd = f.drv();
    std::cout << fd << std::endl;
    std::cout << fd(1.) << std::endl;

prints:

{x} sin(x)/x
0.841471

Jacobian and its value:

  std::vector<std::string> sa;
  sa.emplace_back("{x, y} log(x)");
  sa.emplace_back("{x, y} log(y)");
  sa.emplace_back("{x, y} log(x)+y");
  cvm::rfvector fv(sa);
  cvm::rfmatrix fm = fv.jacobian();
  std::cout << fm << std::endl;
  std::cout << fm(2., 2.) << std::endl;

prints

{x,y} 1/x {x,y} 0 
{x,y} 0 {x,y} 1/y 
{x,y} 1/x {x,y} 1 

0.5 0 
0 0.5 
0.5 1
#include <cvm.h>

cvm::rvector poly_regression (int size, const double *px, const double *py, int deg)
{
  cvm::rmatrix X(size, deg + 1);
  for (int i = 0; i < size; ++i) {
    double x = 1.;
    for (int j = 0;;++j) {
      X(i,j) = x;
      if (j == deg) break;
      x *= px[i];
    }
  }
  cvm::rmatrix Xt(~X);
  cvm::srsmatrix XtX(Xt * X);
  cvm::rvector av(py, size);
  return (XtX.inv() * Xt) * av;
}

int main (int argc, char* argv[]) {
  cvm::rvector x = {3., 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.};
  cvm::rvector y = {74.6297, 39.317, -105.173, -26.6447, -155.447, -136.955, -151.887, -113.365, -102.947, -50.3158, -40.1129};
  cvm::rvector p = poly_regression (x.size(), x, y, 2);
  std::cout << p;
}

prints:

8258.98 -4697.31 656.817 

cvmlib's People

Contributors

drnikolaev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

scitao sagnibak

cvmlib's Issues

make error

Hi, @drnikolaev ,

I came accross the following error:

Compiling debug: srmatrix.cpp
Compiling debug: utils.cpp
Linking: ../../lib/libcvm_ia32_debug.so
/usr/bin/ld: cannot find -lblas_ia32_debug
/usr/bin/ld: cannot find -llapack_ia32_debug
collect2: error: ld returned 1 exit status
make[1]: *** [../../lib/libcvm_ia32_debug.so] Error 1
make[1]: Leaving directory `/data/code/cvmlib/cvm/src'
make: *** [debug] Error 2
root@milton-OptiPlex-9010:/data/code/cvmlib/cvm#

It shows that "blas_ia32_debug" & "lapack_ia32_debug" cannot be found. Could you suggest me how to fix it?

My system is ubuntu 14.04 (64bit)

Thanks~
Milton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.