stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

feat: add `lapack/base/dgtts2`

Open aayush0325 opened this issue 11 months ago • 8 comments

Description

What is the purpose of this pull request?

This pull request:

  • adds lapack/base/dgtts2

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

aayush0325 avatar Mar 08 '25 11:03 aayush0325

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dgtts2 $\color{green}660/660$
$\color{green}+100.00\%$
$\color{green}38/38$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}660/660$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

stdlib-bot avatar Mar 12 '25 06:03 stdlib-bot

/stdlib update-copyright-years

aayush0325 avatar Mar 12 '25 06:03 aayush0325

import numpy as np
from scipy.linalg.lapack import dgttrs

DL_T3 = np.array([0.25, 0.26666667]) 
D_T3 = np.array([4.0, 3.75, 3.73333333])
DU_T3 = np.array([1.0, 0.73333333])
DU2_T3 = np.array([0.0]) 
IPIV_T3 = np.array([1, 2, 3])

B_T3 = np.array([
    [7.0, 8.0, 7.0],  
    [2.0, 3.0, 4], 
    [1.0, 1.5, 2.0]
], dtype=np.float64)

X_T3, info = dgttrs(DL_T3, D_T3, DU_T3, DU2_T3, IPIV_T3, B_T3)

np.set_printoptions(precision=20, suppress=True)
print(X_T3.flatten(order='F'))

column-major, no transpose, nrhs > 1

aayush0325 avatar Mar 13 '25 04:03 aayush0325

import numpy as np
from scipy.linalg.lapack import dgttrs

DL_T3 = np.array([0.25, 0.26666667]) 
D_T3 = np.array([4.0, 3.75, 3.73333333])
DU_T3 = np.array([1.0, 0.73333333])
DU2_T3 = np.array([0.0]) 
IPIV_T3 = np.array([1, 2, 3])

B_T3 = np.array([
    [7.0, 8.0, 7.0],  
    [2.0, 3.0, 4], 
    [1.0, 1.5, 2.0]   
], dtype=np.float64)

X_T3, info = dgttrs(DL_T3, D_T3, DU_T3, DU2_T3, IPIV_T3, B_T3, trans='T')

np.set_printoptions(precision=20, suppress=True)
print(X_T3.flatten(order='F'))

column-major, transpose, nrhs > 1

aayush0325 avatar Mar 13 '25 04:03 aayush0325

import numpy as np
from scipy.linalg.lapack import dgttrs

DL_T3 = np.array([0.25, 0.26666667]) 
D_T3 = np.array([4.0, 3.75, 3.73333333])
DU_T3 = np.array([1.0, 0.73333333])
DU2_T3 = np.array([0.0]) 
IPIV_T3 = np.array([1, 2, 3])

B_T3 = np.array([
    [7.0, 2.0, 1.0], 
    [8.0, 3.0, 1.5],
    [7.0, 4.0, 2.0] 
], dtype=np.float64)

X_T3, info = dgttrs(DL_T3, D_T3, DU_T3, DU2_T3, IPIV_T3, B_T3)

np.set_printoptions(precision=20, suppress=True)
print(X_T3.ravel(order='C'))

row-major, no transpose, nrhs > 1

aayush0325 avatar Mar 13 '25 05:03 aayush0325

import numpy as np
from scipy.linalg.lapack import dgttrs

DL_T3 = np.array([0.25, 0.26666667]) 
D_T3 = np.array([4.0, 3.75, 3.73333333])
DU_T3 = np.array([1.0, 0.73333333])
DU2_T3 = np.array([0.0]) 
IPIV_T3 = np.array([1, 2, 3])

B_T3 = np.array([
    [7.0, 2.0, 1.0], 
    [8.0, 3.0, 1.5],  
    [7.0, 4.0, 2.0] 
], dtype=np.float64)

X_T3, info = dgttrs(DL_T3, D_T3, DU_T3, DU2_T3, IPIV_T3, B_T3, trans='T')

np.set_printoptions(precision=20, suppress=True)
print(X_T3.ravel(order='C'))

row-major, transpose, nrhs > 1

aayush0325 avatar Mar 13 '25 05:03 aayush0325

*     Determine the number of right-hand sides to solve at a time.
*
      IF( NRHS.EQ.1 ) THEN
         NB = 1
      ELSE
         NB = MAX( 1, ILAENV( 1, 'DGTTRS', TRANS, N, NRHS, -1, -1 ) )
      END IF
*
      IF( NB.GE.NRHS ) THEN
         CALL DGTTS2( ITRANS, N, NRHS, DL, D, DU, DU2, IPIV, B, LDB )
      ELSE
         DO 10 J = 1, NRHS, NB
            JB = MIN( NRHS-J+1, NB )
            CALL DGTTS2( ITRANS, N, JB, DL, D, DU, DU2, IPIV, B( 1,
     $                   J ),
     $                   LDB )
   10    CONTINUE
      END IF
*
*     End of DGTTRS

I've used dgttrs from scipy to test my implementation for dgtts2 because under the hood dgttrs is just a wrapper over dgtts2. did this because i couldn't find the scipy implementation for dgtts2

https://github.com/aayush0325/lapack/blob/master/SRC/dgttrs.f#L208

aayush0325 avatar Mar 13 '25 05:03 aayush0325

/stdlib merge

aayush0325 avatar Jun 01 '25 02:06 aayush0325