gha3mi / forsvd

ForSVD - A Fortran library for singular value decompostion (SVD) calculation, low-rank approximation, and image compression.

Home Page:https://gha3mi.github.io/forsvd/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub Version Documentation License Build

ForSVD

ForSVD: A Fortran library for singular value decomposition (SVD) calculation, low-rank approximation, and image compression.

fpm dependency

If you want to use ForSVD as a dependency in your own fpm project, you can easily include it by adding the following line to your fpm.toml file:

[dependencies]
forsvd = {git="https://github.com/gha3mi/forsvd.git"}

How to run tests

Reuirements:

Fortran Compiler, LAPACK or MKL Libraries

Clone the repository:

You can clone the ForSVD repository from GitHub using the following command:

git clone https://github.com/gha3mi/forsvd.git
cd forsvd

Intel Fortran Compiler (ifort)

fpm @ifort-test

Intel Fortran Compiler (ifx)

fpm @ifx-test

GNU Fortran Compiler (gfortran)

fpm @gfortran-test

NVIDIA Compiler (nvfortran)

fpm @nvfortran-test

Usage (SVD)

use forsvd, only: svd

call svd(A, U,S,VT, method='gesvd') ! method='gesdd' 

Example 1

program example1

   use kinds
   use forsvd, only: svd

   implicit none

   real(rk), dimension(:, :), allocatable :: A, U, VT
   real(rk), dimension(:),    allocatable :: S
   integer                                :: m, n, i, j

   m = 4
   n = 3

   allocate(A(m,n), U(m,m), S(min(m,n)), VT(n,n))

   call random_number(A)
   A = A*10.0_rk

   call svd(A, U,S,VT)

   ! Print U
   print *, "U:"
   print "(4F10.6)", (U(:,j), j = 1, m)

   ! Print S
   print *, "S:"
   print "(3F10.6)", S

   ! Print VT
   print *, "VT:"
   print "(3F10.6)", (VT(:,j), j = 1, n)

   deallocate(A, U, S, VT)

end program example1

Usage (low-rank approximation)

use forsvd, only: tsvd

call ts%lowrank(matrix=A, rank=n)

Example 2

program example2

   use kinds
   use forsvd, only: tsvd

   implicit none

   real(rk), dimension(:,:), allocatable :: A
   type(tsvd)                            :: ts

   allocate(A(50,20))
   call random_number(A)
   A = A*100.0_rk

   call ts%lowrank(matrix=A, rank=10)

   print*, norm2(A - ts%matrix_app)/norm2(A)
   
   call ts%dlloc()

end program example2

API documentation

The most up-to-date API documentation for the master branch is available here. To generate the API documentation for ForSVD using ford run the following command:

ford ford.yml

Contributing

Contributions to ForSVD are welcome! If you find any issues or would like to suggest improvements, please open an issue.

About

ForSVD - A Fortran library for singular value decompostion (SVD) calculation, low-rank approximation, and image compression.

https://gha3mi.github.io/forsvd/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Fortran 97.2%Language:Python 2.8%