specialmatrices_bidiagonal Module


Uses

    • stdlib_linalg_constants

Interfaces

public interface Bidiagonal

This interface provides different methods to construct a Bidiagonal matrix. Only the non-zero elements of are stored, i.e.

if is lower-bidiagonal or

if is upper-bidiagonal.

Warning

By default, the matrix is lower-bidiagonal. To create an upper- bidiagonal, set A%which = "U".

Syntax

  • Construct a Bidiagonal matrix filled with zeros:
   integer, parameter :: n = 100
   type(Bidiagonal) :: A

   A = Bidiagonal(n)
  • Construct a Bidiagonal matrix from rank-1 arrays:
   integer, parameter :: n
   real(dp), allocatable :: ev(:), dv(:)
   type(Bidiagonal) :: A
   integer :: i

   dv = [(i, i=1, n)]; ev = [(2*i, i=1, n)]
   A = Bidiagonal(dv, ev)
  • Construct a Bidiagonal matrix with constant diagonals:
   integer, parameter :: n
   real(dp), parameter :: d = 1.0_dp, e = 2.0_dp
   type(Bidiagonal) :: A

   A = Bidiagonal(d, e, n)

Note

Only double precision is currently supported for this matrix type.

  • private pure module function construct(dv, ev, which) result(A)

    Construct a Bidiagonal matrix from the rank-1 arrays dv and ev.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(in) :: dv(:)

    Bidiagonal elements of the matrix.

    real(kind=dp), intent(in) :: ev(:)

    Bidiagonal elements of the matrix.

    character(len=1), intent(in), optional :: which

    Whether A is lower- or upper-diagonal.

    Return Value type(Bidiagonal)

    Bidiagonal matrix.

  • private pure module function construct_constant(d, e, n, which) result(A)

    Construct a Bidiagonal matrix with constant diagonal elements.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(in) :: d

    Bidiagonal elements of the matrix.

    real(kind=dp), intent(in) :: e

    Bidiagonal elements of the matrix.

    integer(kind=ilp), intent(in) :: n

    Dimension of the matrix.

    character(len=1), intent(in), optional :: which

    Whether A is lower- or upper-bidiagonal.

    Return Value type(Bidiagonal)

    Symmetric Bidiagonal matrix.

  • private pure module function initialize(n) result(A)

    Construct a Bidiagonal matrix filled with zeros.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=ilp), intent(in) :: n

    Dimension of the matrix.

    Return Value type(Bidiagonal)

    Symmetric Bidiagonal matrix.

public interface dense

This interface provides methods to convert a Bidiagonal matrix to a regular rank-2 array.

Syntax

   B = dense(A)

Arguments

  • A : Matrix of Bidiagonal type. It is an intent(in) argument.

  • B : Rank-2 array representation of the matrix .

  • private module function dense_rdp(A) result(B)

    Utility function to convert a Bidiagonal matrix to a rank-2 array.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input diagonal matrix.

    Return Value real(kind=dp), allocatable, (:,:)

    Output dense rank-2 array.

public interface det

This interface overloads the det interface from stdlib_linag to compute the determinant where is of type Bidiagonal.

Syntax

   d = det(A)

Arguments

  • A : Matrix of Bidiagonal type. It is in an intent(in) argument.

  • d : Determinant of the matrix.

  • private pure module function det_rdp(A) result(d)

    Compute the determinant of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp)

    Determinant of the matrix.

public interface eig

This interface overloads the eigh interface from stdlib_linalg to compute the eigenvalues and eigenvectors of a real-valued matrix whose type is Bidiagonal.

Syntax

   call eig(A, lambda [, left] [, right])

Arguments

  • A : real-valued matrix of Bidiagonal. It is an intent(in) argument.

  • lambda : Rank-1 real array returning the eigenvalues of A in increasing order. It is an intent(out) argument.

  • left (optional) : complex rank-2 array of the same kind as A returning the left eigenvectors of A. It is an intent(out) argument.

  • right (optional) : complex rank-2 array of the same kind as A returning the right eigenvectors of A. It is an intent(out) argument.

Note

No specialized eigensolvers for generic Bidiagonal matrices exist in LAPACK. This routine thus falls back to wrapping the eig procedure from stdlib_linalg which uses *geev under the hood.

  • private module subroutine eig_rdp(A, lambda, left, right)

    Utility function to compute the eigenvalues and eigenvectors of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    complex(kind=dp), intent(out) :: lambda(:)

    Eigenvalues.

    complex(kind=dp), intent(out), optional :: left(:,:)

    Eigenvectors.

    complex(kind=dp), intent(out), optional :: right(:,:)

    Eigenvectors.

public interface eigvals

This interface overloads the eigvalsh interface from stdlib_linalg to compute the eigenvalues of a real-valued matrix whose type is Bidiagonal.

Syntax

   lambda = eigvals(A)

Arguments

  • A : real-valued matrix of Bidiagonal type. It is an intent(in) argument.

  • lambda : Vector of eigenvalues in increasing order.

  • private module function eigvals_rdp(A) result(lambda)

    Utility function to compute the eigenvalues of a real Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value complex(kind=dp), allocatable, (:)

    Eigenvalues.

public interface inv

  • private pure module function inv_rdp(A) result(B)

    Utility function to compute the inverse of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp), allocatable, (:,:)

    Inverse of A.

public interface matmul

This interface overloads the Fortran intrinsic matmul for a Bidiagonal matrix, both for matrix-vector and matrix-matrix products. For a matrix-matrix product , only the matrix has to be a Bidiagonal matrix. Both and need to be standard Fortran rank-2 arrays. All the underlying functions are defined as pure.

Syntax

   y = matmul(A, x)
  • private module function spmv(A, x) result(y)

    Compute the matrix-vector product for a Bidiagonal matrix . Both x and y are rank-1 arrays with the same kind as A.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in), target :: A

    Input matrix.

    real(kind=dp), intent(in), target :: x(:)

    Input vector.

    Return Value real(kind=dp), target, allocatable, (:)

    Output vector.

  • private pure module function spmvs(A, X) result(Y)

    Compute the matrix-matrix product for a Bidiagonal matrix and a dense matrix (rank-2 array). is also a rank-2 array with the same dimensions as .

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(in) :: X(:,:)

    Input vectors.

    Return Value real(kind=dp), allocatable, (:,:)

    Output vectors.

public interface operator(*)

  • private pure module function scalar_multiplication_bis_rdp(A, alpha) result(B)

    Utility function to perform a scalar multiplication with a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A
    real(kind=dp), intent(in) :: alpha

    Return Value type(Bidiagonal)

  • private pure module function scalar_multiplication_rdp(alpha, A) result(B)

    Utility function to perform a scalar multiplication with a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(in) :: alpha
    type(Bidiagonal), intent(in) :: A

    Return Value type(Bidiagonal)

public interface shape

  • private pure module function shape_rdp(A) result(arr_shape)

    Utility function to get the shape of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value integer(kind=ilp), (2)

    Shape of the matrix.

public interface size

  • private pure module function size_rdp(A, dim) result(arr_size)

    Utility function to return the size of Bidiagonal matrix along a given dimension.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    integer(kind=ilp), intent(in), optional :: dim

    Queried dimension.

    Return Value integer(kind=ilp)

    Size of the matrix along the dimension dim.

public interface solve

This interface overloads the solve interface from stdlib_linalg for solving a linear system where is a Bidiagonal matrix. It also enables to solve a linear system with multiple right-hand sides.

Syntax

   x = solve(A, b)

Arguments

  • A : Matrix of Bidiagonal type. It is an intent(in) argument.

  • b : Rank-1 or rank-2 array defining the right-hand side(s). It is an intent(in) argument.

  • x : Solution of the linear system. It has the same type and shape as b.

  • private pure module function solve_multi_rhs(A, b) result(x)

    Solve the linear system where is of type Bidiagonal and B a standard rank-2 array. The solution matrix X has the same dimensions and kind as B.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Coefficient matrix.

    real(kind=dp), intent(in) :: b(:,:)

    Right-hand side vectors.

    Return Value real(kind=dp), allocatable, target, (:,:)

    Solution vectors.

  • private pure module function solve_single_rhs(A, b) result(x)

    Solve the linear system where is of type Bidiagonal and b a standard rank-1 array. The solution vector x has the same dimension and kind as b.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Coefficient matrix.

    real(kind=dp), intent(in) :: b(:)

    Right-hand side vector.

    Return Value real(kind=dp), allocatable, target, (:)

    Solution vector.

public interface svd

This interface overloads the svd interface from stdlib_linalg to compute the the singular value decomposition of a Bidiagonal matrix .

Syntax

   call svd(A, s [, u] [, vt])

Arguments

  • A : Matrix of Bidiagonal type. It is an intent(in) argument.

  • s : Rank-1 array real array returning the singular values of A. It is an intent(out) argument.

  • u (optional) : Rank-2 array of the same kind as A returning the left singular vectors of A as columns. Its size should be [n, n]. It is an intent(out) argument.

  • vt (optional): Rank-2 array of the same kind as A returning the right singular vectors of A as rows. Its size should be [n, n]. It is an intent(out) argument.

  • private module subroutine svd_rdp(A, s, u, vt)

    Compute the singular value decomposition of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(out) :: s(:)

    Singular values in descending order.

    real(kind=dp), intent(out), optional :: u(:,:)

    Left singular vectors as columns.

    real(kind=dp), intent(out), optional :: vt(:,:)

    Right singular vectors as rows.

public interface svdvals

This interface overloads the svdvals interface from stdlib_linalg to compute the singular values of a Bidiagonal matrix .

Syntax

   s = svdvals(A)

Arguments

  • A : Matrix of Bidiagonal type. It is an intent(in) argument.

  • s : Vector of singular values sorted in decreasing order.

  • private module function svdvals_rdp(A) result(s)

    Compute the singular values of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp), allocatable, (:)

    Singular values in descending order.

public interface trace

This interface overloads the trace interface from stdlib_linalg to compute the trace of a matrix of type Bidiagonal.

Syntax

   tr = trace(A)

Arguments

  • A : Matrix of Bidiagonal type. It is an intent(in) argument.

  • tr: Trace of the matrix.

  • private pure module function trace_rdp(A) result(tr)

    Compute the trace of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp)

    Trace of the matrix.

public interface transpose

This interface overloads the Fortran intrinsic procedure to define the transpose of a Bidiagonal matrix.

Syntax

   B = transpose(A)

Arguments

  • A : Matrix of Bidiagonal type. It is an intent(in) argument.

  • B : Resulting transposed matrix. It is of the same type as A.

  • private pure module function transpose_rdp(A) result(B)

    Utility function to compute the transpose of a Bidiagonal matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Bidiagonal), intent(in) :: A

    Input matrix.

    Return Value type(Bidiagonal)

    Transpose of the matrix.


Derived Types

type, public ::  Bidiagonal

Base type used to define a Bidiagonal matrix of size [n, n] with diagonals given by rank-1 arrays dv (size n) and ev (size n-1).

Constructor

This interface provides different methods to construct a Bidiagonal matrix. Only the non-zero elements of are stored, i.e.

Read more…
private pure, module function construct (dv, ev, which)

Construct a Bidiagonal matrix from the rank-1 arrays dv and ev.

private pure, module function construct_constant (d, e, n, which)

Construct a Bidiagonal matrix with constant diagonal elements.

private pure, module function initialize (n)

Construct a Bidiagonal matrix filled with zeros.