Skip to content

Commit

Permalink
Merge pull request #6 from gha3mi/gha3mi/issue4
Browse files Browse the repository at this point in the history
Rename pinv to inv
  • Loading branch information
gha3mi committed Aug 8, 2023
2 parents 98fa9cf + 7ebdd89 commit f61f177
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/forinv.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module forinv

!This module provides functions and subroutines for pseudoinverse calculations.
!! This module provides functions and subroutines for inverse and pseudo-inverse calculations.

use kinds
use forsvd, only: svd
Expand All @@ -12,7 +12,7 @@ module forinv
public :: pinv

!===============================================================================
interface pinv
interface inv
procedure :: pinv_rel
end interface
!===============================================================================
Expand Down
10 changes: 5 additions & 5 deletions test/test1.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
program test1

! This Fortran test code demonstrates the usage of the pinv function to calculate the matrix inverse&
! This Fortran test code demonstrates the usage of the inv function to calculate the matrix inverse&
! and verifies the results by comparing them with expected values obtained from MATLAB.

use kinds ! Import the module 'kinds' for precision types
use forinv, only: pinv ! Import only the 'pinv' function from the 'forinv' module
use forinv, only: inv ! Import only the 'inv' function from the 'forinv' module

implicit none

Expand All @@ -22,16 +22,16 @@ program test1


!===============================================================================
! Define expected matrix AinvM=pinv(A) from MATLAB results
! Define expected matrix AinvM=inv(A) from MATLAB results
AinvM(1,1) = -11.8748418966254_rk ; AinvM(1,2) = -1.88508351433968_rk; AinvM(1,3) = 1.37910840173057_rk ; AinvM(1,4) = 13.3647936345720_rk
AinvM(2,1) = -0.232262684677810_rk; AinvM(2,2) = -1.81026044323168_rk; AinvM(2,3) = 1.12793815267075_rk ; AinvM(2,4) = 1.84558847033752_rk
AinvM(3,1) = 11.2481704396877_rk ; AinvM(3,2) = 2.87726069020400_rk ; AinvM(3,3) = -1.70926059704099_rk; AinvM(3,4) = -12.6490061903496_rk
!===============================================================================


!===============================================================================
! Calculate the matrix inverse of A using the 'pinv' function
Ainv = pinv(A)
! Calculate the matrix inverse of A using the 'inv' function
Ainv = inv(A)
!===============================================================================


Expand Down
6 changes: 3 additions & 3 deletions test/test2.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
program test2

use kinds ! Import the module 'kinds' for precision types
use forinv, only: pinv ! Import only the 'pinv' function from the 'forinv' module
use forinv, only: inv ! Import only the 'inv' function from the 'forinv' module

implicit none

Expand All @@ -14,8 +14,8 @@ program test2
allocate(A(m,n),Ainv1(n,m),Ainv2(n,m)) ! Allocate memory for matrix A
call random_number(A) ! Fill matrix A with random numbers between 0 and 1

Ainv1 = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function
Ainv2 = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function
Ainv1 = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function
Ainv2 = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function

rel_err = norm2(Ainv1 - Ainv2)/norm2(Ainv1)

Expand Down
12 changes: 6 additions & 6 deletions test/test3.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
program test3

! This Fortran test code demonstrates the usage of the pinv function to calculate the matrix inverse
! This Fortran test code demonstrates the usage of the inv function to calculate the matrix inverse
! of a randomly generated matrix.

use kinds ! Import the module 'kinds' for precision types
use forinv, only: pinv ! Import only the 'pinv' function from the 'forinv' module
use forinv, only: inv ! Import only the 'inv' function from the 'forinv' module
use fortime

implicit none
Expand All @@ -20,13 +20,13 @@ program test3

call timer_start(w)

Ainv = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function
Ainv = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function

call timer_stop(w,message=' Elapsed time (2000*200 , gesvd):')

call timer_start(w)

Ainv = pinv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'pinv' function and the getrf method
Ainv = inv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'inv' function and the getrf method

call timer_stop(w,message=' Elapsed time (2000*200 , getrf):')

Expand All @@ -40,13 +40,13 @@ program test3

call timer_start(w)

Ainv = pinv(A*10) ! Calculate the matrix inverse of A using the 'pinv' function
Ainv = inv(A*10) ! Calculate the matrix inverse of A using the 'inv' function

call timer_stop(w,message=' Elapsed time (2000*1800, gesvd):')

call timer_start(w)

Ainv = pinv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'pinv' function and the getrf method
Ainv = inv(A*10, method='getrf') ! Calculate the matrix inverse of A using the 'inv' function and the getrf method

call timer_stop(w,message=' Elapsed time (2000*1800, getrf):')

Expand Down

0 comments on commit f61f177

Please sign in to comment.