---
name: "Math::GSL::BLAS"
section: "3pm"
platform: "linux"
package: "libmath-gsl-perl"
version: "0.45-2+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Math::GSL::BLAS"
---

# Math::GSL::BLAS(3pm)

Basic Linear Algebra Subprograms

## NAME

Math::GSL::BLAS - Basic Linear Algebra Subprograms

## SYNOPSIS

```
    use Math::GSL::BLAS qw/:all/;
    use Math::GSL::Matrix qw/:all/;
    # matrix-matrix product of double numbers
    my $A = Math::GSL::Matrix->new(2,2);
    $A->set_row(0, [1, 4]);
      ->set_row(1, [3, 2]);
    my $B = Math::GSL::Matrix->new(2,2);
    $B->set_row(0, [2, 1]);
      ->set_row(1, [5,3]);
    my $C = Math::GSL::Matrix->new(2,2);
    gsl_matrix_set_zero($C->raw);
    gsl_blas_dgemm($CblasNoTrans, $CblasNoTrans, 1, $A->raw, $B->raw, 1, $C->raw);
    my @got = $C->row(0)->as_list;
    print "The resulting matrix is: \n[";
    print "$got[0]  $got[1]\n";
    @got = $C->row(1)->as_list;
    print "$got[0]  $got[1] ]\n";
    # compute the scalar product of two vectors :
    use Math::GSL::Vector qw/:all/;
    use Math::GSL::CBLAS qw/:all/;
    my $vec1 = Math::GSL::Vector->new([1,2,3,4,5]);
    my $vec2 = Math::GSL::Vector->new([5,4,3,2,1]);
    my ($status, $result) = gsl_blas_ddot($vec1->raw, $vec2->raw);
    if($status == 0) {
        print "The function has succeeded. \n";
    }
    print "The result of the vector multiplication is $result.\n";
```

## DESCRIPTION

The functions of this module are divised into 3 levels:

### Level 1 - Vector operations

- "gsl\_blas\_sdsdot"

  - "gsl\_blas\_dsdot"

  - "gsl\_blas\_sdot"

  - "gsl\_blas\_ddot($x, $y)"

  This function computes the scalar product x^T y for the vectors `$x` and `$y`. The function returns two values, the first is 0 if the operation succeeded, 1 otherwise and the second value is the result of the computation.

- "gsl\_blas\_cdotu"

  - "gsl\_blas\_cdotc"

  - "gsl\_blas\_zdotu($x, $y, $dotu)"

  This function computes the complex scalar product x^T y for the complex vectors `$x` and `$y`, returning the result in the complex number `$dotu`. The function returns 0 if the operation succeeded, 1 otherwise.

- "gsl\_blas\_zdotc($x, $y, $dotc)"

  This function computes the complex conjugate scalar product x^H y for the complex vectors `$x` and `$y`, returning the result in the complex number `$dotc`. The function returns 0 if the operation succeeded, 1 otherwise.

- "gsl\_blas\_snrm2" =item "gsl\_blas\_sasum"

  - gsl\_blas\_dnrm2($x)

  This function computes the Euclidean norm

  ```
      ||x||_2 = \sqrt {\sum x_i^2}
  ```

  of the vector `$x`.

- gsl\_blas\_dasum($x)

  This function computes the absolute sum \\sum \|x\_i\| of the elements of the vector `$x`.

- "gsl\_blas\_scnrm2"

  - "gsl\_blas\_scasum"

  - gsl\_blas\_dznrm2($x)

  This function computes the Euclidean norm of the complex vector `$x`, \|\|x\|\|\_2 = \\sqrt {\\sum (\\Re(x\_i)^2 + \\Im(x\_i)^2)}.

- gsl\_blas\_dzasum($x)

  This function computes the sum of the magnitudes of the real and imaginary parts of the complex vector `$x`, \\sum \|\\Re(x\_i)\| + \|\\Im(x\_i)\|.

- "gsl\_blas\_isamax"

  - "gsl\_blas\_idamax"

  - "gsl\_blas\_icamax"

  - "gsl\_blas\_izamax "

  - "gsl\_blas\_sswap"

  - "gsl\_blas\_scopy"

  - "gsl\_blas\_saxpy"

  - "gsl\_blas\_dswap($x, $y)"

  This function exchanges the elements of the vectors `$x` and `$y`. The function returns 0 if the operation succeeded, 1 otherwise.

- "gsl\_blas\_dcopy($x, $y)"

  This function copies the elements of the vector `$x` into the vector `$y`. The function returns 0 if the operation succeeded, 1 otherwise.

- "gsl\_blas\_daxpy($alpha, $x, $y)"

  These functions compute the sum `$y` = `$alpha` \* `$x` + `$y` for the vectors `$x` and `$y`.

- "gsl\_blas\_cswap"

  - "gsl\_blas\_ccopy "

  - "gsl\_blas\_caxpy"

  - "gsl\_blas\_zswap"

  - "gsl\_blas\_zcopy"

  - "gsl\_blas\_zaxpy "

  - "gsl\_blas\_srotg"

  - "gsl\_blas\_srotmg"

  - "gsl\_blas\_srot"

  - "gsl\_blas\_srotm "

  - "gsl\_blas\_drotg"

  - "gsl\_blas\_drotmg"

  - "gsl\_blas\_drot($x, $y, $c, $s)"

  This function applies a Givens rotation (x', y') = (c x + s y, -s x + c y) to the vectors `$x`, `$y`.

- "gsl\_blas\_drotm "

  - "gsl\_blas\_sscal"

  - "gsl\_blas\_dscal($alpha, $x)"

  This function rescales the vector `$x` by the multiplicative factor `$alpha`.

- "gsl\_blas\_cscal"

  - "gsl\_blas\_zscal "

  - "gsl\_blas\_csscal"

  - "gsl\_blas\_zdscal"

  ### Level 2 - Matrix-vector operations

- "gsl\_blas\_sgemv"

  - "gsl\_blas\_strmv "

  - "gsl\_blas\_strsv"

  - "gsl\_blas\_dgemv($TransA, $alpha, $A, $x, $beta, $y)" - This function computes the matrix-vector product and sum y = \\alpha op(A) x + \\beta y, where op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans (constant values coming from the CBLAS module). $A is a matrix and $x and $y are vectors. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dtrmv($Uplo, $TransA, $Diag, $A, $x)" - This function computes the matrix-vector product x = op(A) x for the triangular matrix $A, where op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans (constant values coming from the CBLAS module). When $Uplo is $CblasUpper then the upper triangle of $A is used, and when $Uplo is $CblasLower then the lower triangle of $A is used. If $Diag is $CblasNonUnit then the diagonal of the matrix is used, but if $Diag is $CblasUnit then the diagonal elements of the matrix $A are taken as unity and are not referenced. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dtrsv($Uplo, $TransA, $Diag, $A, $x)" - This function computes inv(op(A)) x for the vector $x, where op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans (constant values coming from the CBLAS module). When $Uplo is $CblasUpper then the upper triangle of $A is used, and when $Uplo is $CblasLower then the lower triangle of $A is used. If $Diag is $CblasNonUnit then the diagonal of the matrix is used, but if $Diag is $CblasUnit then the diagonal elements of the matrix $A are taken as unity and are not referenced. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_cgemv "

  - "gsl\_blas\_ctrmv"

  - "gsl\_blas\_ctrsv"

  - "gsl\_blas\_zgemv "

  - "gsl\_blas\_ztrmv"

  - "gsl\_blas\_ztrsv"

  - "gsl\_blas\_ssymv"

  - "gsl\_blas\_sger "

  - "gsl\_blas\_ssyr"

  - "gsl\_blas\_ssyr2"

  - "gsl\_blas\_dsymv"

  - "gsl\_blas\_dger($alpha, $x, $y, $A)" - This function computes the rank-1 update A = alpha x y^T + A of the matrix $A. $x and $y are vectors. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dsyr($Uplo, $alpha, $x, $A)" - This function computes the symmetric rank-1 update A = \\alpha x x^T + A of the symmetric matrix $A and the vector $x. Since the matrix $A is symmetric only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $A are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $A are used. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dsyr2($Uplo, $alpha, $x, $y, $A)" - This function computes the symmetric rank-2 update A = \\alpha x y^T + \\alpha y x^T + A of the symmetric matrix $A, the vector $x and vector $y. Since the matrix $A is symmetric only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $A are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $A are used.

  - "gsl\_blas\_chemv"

  - "gsl\_blas\_cgeru "

  - "gsl\_blas\_cgerc"

  - "gsl\_blas\_cher"

  - "gsl\_blas\_cher2"

  - "gsl\_blas\_zhemv "

  - "gsl\_blas\_zgeru($alpha, $x, $y, $A)" - This function computes the rank-1 update A = alpha x y^T + A of the complex matrix $A. $alpha is a complex number and $x and $y are complex vectors. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_zgerc"

  - "gsl\_blas\_zher($Uplo, $alpha, $x, $A)" - This function computes the hermitian rank-1 update A = \\alpha x x^H + A of the hermitian matrix $A and of the complex vector $x. Since the matrix $A is hermitian only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $A are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $A are used. The imaginary elements of the diagonal are automatically set to zero. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_zher2 "

  ### Level 3 - Matrix-matrix operations

- "gsl\_blas\_sgemm"

  - "gsl\_blas\_ssymm"

  - "gsl\_blas\_ssyrk"

  - "gsl\_blas\_ssyr2k "

  - "gsl\_blas\_strmm"

  - "gsl\_blas\_strsm"

  - "gsl\_blas\_dgemm($TransA, $TransB, $alpha, $A, $B, $beta, $C)" - This function computes the matrix-matrix product and sum C = \\alpha op(A) op(B) + \\beta C where op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans and similarly for the parameter $TransB. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dsymm($Side, $Uplo, $alpha, $A, $B, $beta, $C)" - This function computes the matrix-matrix product and sum C = \\alpha A B + \\beta C for $Side is $CblasLeft and C = \\alpha B A + \\beta C for $Side is $CblasRight, where the matrix $A is symmetric. When $Uplo is $CblasUpper then the upper triangle and diagonal of $A are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $A are used. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dsyrk($Uplo, $Trans, $alpha, $A, $beta, $C)" - This function computes a rank-k update of the symmetric matrix $C, C = \\alpha A A^T + \\beta C when $Trans is $CblasNoTrans and C = \\alpha A^T A + \\beta C when $Trans is $CblasTrans. Since the matrix $C is symmetric only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $C are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $C are used. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dsyr2k($Uplo, $Trans, $alpha, $A, $B, $beta, $C)" - This function computes a rank-2k update of the symmetric matrix $C, C = \\alpha A B^T + \\alpha B A^T + \\beta C when $Trans is $CblasNoTrans and C = \\alpha A^T B + \\alpha B^T A + \\beta C when $Trans is $CblasTrans. Since the matrix $C is symmetric only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $C are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $C are used. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dtrmm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)" - This function computes the matrix-matrix product B = \\alpha op(A) B for $Side is $CblasLeft and B = \\alpha B op(A) for $Side is $CblasRight. The matrix $A is triangular and op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When $Uplo is $CblasUpper then the upper triangle of $A is used, and when $Uplo is $CblasLower then the lower triangle of $A is used. If $Diag is $CblasNonUnit then the diagonal of $A is used, but if $Diag is $CblasUnit then the diagonal elements of the matrix $A are taken as unity and are not referenced. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_dtrsm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)" - This function computes the inverse-matrix matrix product B = \\alpha op(inv(A))B for $Side is $CblasLeft and B = \\alpha B op(inv(A)) for $Side is $CblasRight. The matrix $A is triangular and op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When $Uplo is $CblasUpper then the upper triangle of $A is used, and when $Uplo is $CblasLower then the lower triangle of $A is used. If $Diag is $CblasNonUnit then the diagonal of $A is used, but if $Diag is $CblasUnit then the diagonal elements of the matrix $A are taken as unity and are not referenced. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_cgemm"

  - "gsl\_blas\_csymm"

  - "gsl\_blas\_csyrk"

  - "gsl\_blas\_csyr2k "

  - "gsl\_blas\_ctrmm"

  - "gsl\_blas\_ctrsm"

  - "gsl\_blas\_zgemm($TransA, $TransB, $alpha, $A, $B, $beta, $C)" - This function computes the matrix-matrix product and sum C = \\alpha op(A) op(B) + \\beta C where op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans and similarly for the parameter $TransB. The function returns 0 if the operation succeeded, 1 otherwise. $A, $B and $C are complex matrices

  - "gsl\_blas\_zsymm($Side, $Uplo, $alpha, $A, $B, $beta, $C)" - This function computes the matrix-matrix product and sum C = \\alpha A B + \\beta C for $Side is $CblasLeft and C = \\alpha B A + \\beta C for $Side is $CblasRight, where the matrix $A is symmetric. When $Uplo is $CblasUpper then the upper triangle and diagonal of $A are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $A are used. $A, $B and $C are complex matrices. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_zsyrk($Uplo, $Trans, $alpha, $A, $beta, $C)" - This function computes a rank-k update of the symmetric complex matrix $C, C = \\alpha A A^T + \\beta C when $Trans is $CblasNoTrans and C = \\alpha A^T A + \\beta C when $Trans is $CblasTrans. Since the matrix $C is symmetric only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $C are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $C are used. The function returns 0 if the operation succeeded, 1 otherwise.

  - "gsl\_blas\_zsyr2k($Uplo, $Trans, $alpha, $A, $B, $beta, $C)" - This function computes a rank-2k update of the symmetric matrix $C, C = \\alpha A B^T + \\alpha B A^T + \\beta C when $Trans is $CblasNoTrans and C = \\alpha A^T B + \\alpha B^T A + \\beta C when $Trans is $CblasTrans. Since the matrix $C is symmetric only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $C are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $C are used. The function returns 0 if the operation succeeded, 1 otherwise. $A, $B and $C are complex matrices and $beta is a complex number.

  - "gsl\_blas\_ztrmm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)" - This function computes the matrix-matrix product B = \\alpha op(A) B for $Side is $CblasLeft and B = \\alpha B op(A) for $Side is $CblasRight. The matrix $A is triangular and op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When $Uplo is $CblasUpper then the upper triangle of $A is used, and when $Uplo is $CblasLower then the lower triangle of $A is used. If $Diag is $CblasNonUnit then the diagonal of $A is used, but if $Diag is $CblasUnit then the diagonal elements of the matrix $A are taken as unity and are not referenced. The function returns 0 if the operation succeeded, 1 otherwise. $A and $B are complex matrices and $alpha is a complex number.

  - "gsl\_blas\_ztrsm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)" - This function computes the inverse-matrix matrix product B = \\alpha op(inv(A))B for $Side is $CblasLeft and B = \\alpha B op(inv(A)) for $Side is $CblasRight. The matrix $A is triangular and op(A) = A, A^T, A^H for $TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When $Uplo is $CblasUpper then the upper triangle of $A is used, and when $Uplo is $CblasLower then the lower triangle of $A is used. If $Diag is $CblasNonUnit then the diagonal of $A is used, but if $Diag is $CblasUnit then the diagonal elements of the matrix $A are taken as unity and are not referenced. The function returns 0 if the operation succeeded, 1 otherwise. $A and $B are complex matrices and $alpha is a complex number.

  - "gsl\_blas\_chemm"

  - "gsl\_blas\_cherk"

  - "gsl\_blas\_cher2k"

  - "gsl\_blas\_zhemm($Side, $Uplo, $alpha, $A, $B, $beta, $C)" - This function computes the matrix-matrix product and sum C = \\alpha A B + \\beta C for $Side is $CblasLeft and C = \\alpha B A + \\beta C for $Side is $CblasRight, where the matrix $A is hermitian. When Uplo is CblasUpper then the upper triangle and diagonal of A are used, and when Uplo is CblasLower then the lower triangle and diagonal of A are used. The imaginary elements of the diagonal are automatically set to zero.

  - "gsl\_blas\_zherk($Uplo, $Trans, $alpha, $A, $beta, $C)" - This function computes a rank-k update of the hermitian matrix $C, C = \\alpha A A^H + \\beta C when $Trans is $CblasNoTrans and C = \\alpha A^H A + \\beta C when $Trans is $CblasTrans. Since the matrix $C is hermitian only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $C are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $C are used. The imaginary elements of the diagonal are automatically set to zero. The function returns 0 if the operation succeeded, 1 otherwise. $A, $B and $C are complex matrices and $alpha and $beta are complex numbers.

  - "gsl\_blas\_zher2k($Uplo, $Trans, $alpha, $A, $B, $beta, $C)" - This function computes a rank-2k update of the hermitian matrix $C, C = \\alpha A B^H + \\alpha^\* B A^H + \\beta C when $Trans is $CblasNoTrans and C = \\alpha A^H B + \\alpha^\* B^H A + \\beta C when $Trans is $CblasConjTrans. Since the matrix $C is hermitian only its upper half or lower half need to be stored. When $Uplo is $CblasUpper then the upper triangle and diagonal of $C are used, and when $Uplo is $CblasLower then the lower triangle and diagonal of $C are used. The imaginary elements of the diagonal are automatically set to zero. The function returns 0 if the operation succeeded, 1 otherwise.

  You have to add the functions you want to use inside the qw /put\_function\_here /. You can also write use Math::GSL::BLAS qw/:all/ to use all available functions of the module. Other tags are also available, here is a complete list of all tags for this module :

- "level1"

  - "level2"

  - "level3"

  For more information on the functions, we refer you to the GSL official documentation: \<http://www.gnu.org/software/gsl/manual/html\_node/\>

## AUTHORS

Jonathan "Duke" Leto \<jonathan@leto.net\> and Thierry Moisan \<thierry.moisan@gmail.com\>

## COPYRIGHT AND LICENSE

Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
