Math::GSL::BLAS(3pm)
π NAME π
Math::GSL::BLAS β Basic Linear Algebra Subprograms, bestie. This is your Perl doc, Math::GSL::BLAS(3pm) from the User Contributed Perl Documentation collection, and she is the plug for all your linear algebra needs. π
β¨ SYNOPSIS β¨
Okay so here's the whole vibe in code, no notes:
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 πΈ
So the functions in this module are split into 3 levels, and honestly? It's giving organized. It's giving structured. The girls that know, know. Let's get into it. π
π¦ Level 1 - Vector operations
Here's the whole roster up top, so nobody gets left out:
gsl_blas_sdsdotgsl_blas_dsdotgsl_blas_sdotgsl_blas_ddot($x, $y)β bestie, this one computes the scalar productx^T yfor the vectors$xand$y. And the way she returns two values? Iconic. The first value is0if the operation succeeded,1otherwise, and the second value is the actual result of the computation. π«Άgsl_blas_cdotugsl_blas_cdotcgsl_blas_zdotu($x, $y, $dotu)β computes the complex scalar productx^T yfor the complex vectors$xand$y, and drops the result into the complex number$dotu. Returns0if the operation succeeded,1otherwise.gsl_blas_zdotc($x, $y, $dotc)β computes the complex conjugate scalar productx^H yfor the complex vectors$xand$y, returning the result in the complex number$dotc. Returns0if the operation succeeded,1otherwise.gsl_blas_snrm2gsl_blas_sasumgsl_blas_dnrm2($x)β this one computes the Euclidean norm
||x||_2 = \sqrt {\sum x_i^2}
of the vector $x. Math but make it cute. π
gsl_blas_dasum($x)β computes the absolute sum\sum |x_i|of the elements of the vector$x.gsl_blas_scnrm2gsl_blas_scasumgsl_blas_dznrm2($x)β computes the Euclidean norm of the complex vector$x, aka||x||_2 = \sqrt {\sum (\Re(x_i)^2 + \Im(x_i)^2)}.gsl_blas_dzasum($x)β computes the sum of the magnitudes of the real and imaginary parts of the complex vector$x, aka\sum |\Re(x_i)| + |\Im(x_i)|.gsl_blas_isamaxgsl_blas_idamaxgsl_blas_icamaxgsl_blas_izamaxgsl_blas_sswapgsl_blas_scopygsl_blas_saxpygsl_blas_dswap($x, $y)β exchanges the elements of the vectors$xand$y. Returns0if the operation succeeded,1otherwise.gsl_blas_dcopy($x, $y)β copies the elements of the vector$xinto the vector$y. Returns0if the operation succeeded,1otherwise.gsl_blas_daxpy($alpha, $x, $y)β computes the sum$y = $alpha * $x + $yfor the vectors$xand$y.gsl_blas_cswapgsl_blas_ccopygsl_blas_caxpygsl_blas_zswapgsl_blas_zcopygsl_blas_zaxpygsl_blas_srotggsl_blas_srotmggsl_blas_srotgsl_blas_srotmgsl_blas_drotggsl_blas_drotmggsl_blas_drot($x, $y, $c, $s)β applies a Givens rotation(x', y') = (c x + s y, -s x + c y)to the vectors$x,$y. Rotating the whole fit, honestly. πgsl_blas_drotmgsl_blas_sscalgsl_blas_dscal($alpha, $x)β rescales the vector$xby the multiplicative factor$alpha.gsl_blas_cscalgsl_blas_zscalgsl_blas_csscalgsl_blas_zdscal
π Level 2 - Matrix-vector operations
Buckle up, this is the main character section. π
gsl_blas_sgemvgsl_blas_strmvgsl_blas_strsvgsl_blas_dgemv($TransA, $alpha, $A, $x, $beta, $y)β this function computes the matrix-vector product and sumy = \alpha op(A) x + \beta y, whereop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans(those are constant values coming from the CBLAS module, iykyk).$Ais a matrix and$xand$yare vectors. Returns0if the operation succeeded,1otherwise.gsl_blas_dtrmv($Uplo, $TransA, $Diag, $A, $x)β this one computes the matrix-vector productx = op(A) xfor the triangular matrix$A, whereop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans(again, constant values from the CBLAS module). When$Uplois$CblasUpperthen the upper triangle of$Ais used, and when$Uplois$CblasLowerthen the lower triangle of$Ais used. If$Diagis$CblasNonUnitthen the diagonal of the matrix is used, but if$Diagis$CblasUnitthen the diagonal elements of the matrix$Aare taken as unity and are not referenced. Returns0if the operation succeeded,1otherwise.gsl_blas_dtrsv($Uplo, $TransA, $Diag, $A, $x)β computesinv(op(A)) xfor the vector$x, whereop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans(constant values coming from the CBLAS module). When$Uplois$CblasUpperthen the upper triangle of$Ais used, and when$Uplois$CblasLowerthen the lower triangle of$Ais used. If$Diagis$CblasNonUnitthen the diagonal of the matrix is used, but if$Diagis$CblasUnitthen the diagonal elements of the matrix$Aare taken as unity and are not referenced. Returns0if the operation succeeded,1otherwise.gsl_blas_cgemvgsl_blas_ctrmvgsl_blas_ctrsvgsl_blas_zgemvgsl_blas_ztrmvgsl_blas_ztrsvgsl_blas_ssymvgsl_blas_sgergsl_blas_ssyrgsl_blas_ssyr2gsl_blas_dsymvgsl_blas_dger($alpha, $x, $y, $A)β computes the rank-1 updateA = alpha x y^T + Aof the matrix$A.$xand$yare vectors. Returns0if the operation succeeded,1otherwise.gsl_blas_dsyr($Uplo, $alpha, $x, $A)β computes the symmetric rank-1 updateA = \alpha x x^T + Aof the symmetric matrix$Aand the vector$x. Since the matrix$Ais symmetric, only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Aare used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Aare used. Returns0if the operation succeeded,1otherwise.gsl_blas_dsyr2($Uplo, $alpha, $x, $y, $A)β computes the symmetric rank-2 updateA = \alpha x y^T + \alpha y x^T + Aof the symmetric matrix$A, the vector$xand vector$y. Since the matrix$Ais symmetric, only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Aare used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Aare used.gsl_blas_chemvgsl_blas_cgerugsl_blas_cgercgsl_blas_chergsl_blas_cher2gsl_blas_zhemvgsl_blas_zgeru($alpha, $x, $y, $A)β computes the rank-1 updateA = alpha x y^T + Aof the complex matrix$A.$alphais a complex number and$xand$yare complex vectors. Returns0if the operation succeeded,1otherwise.gsl_blas_zgercgsl_blas_zher($Uplo, $alpha, $x, $A)β computes the hermitian rank-1 updateA = \alpha x x^H + Aof the hermitian matrix$Aand of the complex vector$x. Since the matrix$Ais hermitian, only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Aare used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Aare used. The imaginary elements of the diagonal are automatically set to zero. Returns0if the operation succeeded,1otherwise.gsl_blas_zher2
β¨ Level 3 - Matrix-matrix operations β¨
okay bestie, level 3 is where matrices start doing full-on collabs and it's iconic. No cap, these are the BLAS functions for matrix-matrix tea. Let's go, fr fr. π
First, the single-precision ones that are just listed here with no extra description, exactly like the original:
gsl_blas_sgemmgsl_blas_ssymmgsl_blas_ssyrkgsl_blas_ssyr2kgsl_blas_strmmgsl_blas_strsm
Then the double-precision detailed ones:
gsl_blas_dgemm($TransA, $TransB, $alpha, $A, $B, $beta, $C)β This function computes the matrix-matrix product and sumC = \alpha op(A) op(B) + \beta Cwhereop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTransand similarly for the parameter$TransB. The function returns0if the operation succeeded,1otherwise. slay. β¨gsl_blas_dsymm($Side, $Uplo, $alpha, $A, $B, $beta, $C)β This function computes the matrix-matrix product and sumC = \alpha A B + \beta Cfor$Sideis$CblasLeftandC = \alpha B A + \beta Cfor$Sideis$CblasRight, where the matrix$Ais symmetric. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Aare used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Aare used. The function returns0if the operation succeeded,1otherwise.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 Cwhen$Transis$CblasNoTransandC = \alpha A^T A + \beta Cwhen$Transis$CblasTrans. Since the matrix$Cis symmetric only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Care used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Care used. The function returns0if the operation succeeded,1otherwise.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 Cwhen$Transis$CblasNoTransandC = \alpha A^T B + \alpha B^T A + \beta Cwhen$Transis$CblasTrans. Since the matrix$Cis symmetric only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Care used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Care used. The function returns0if the operation succeeded,1otherwise.gsl_blas_dtrmm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)β This function computes the matrix-matrix productB = \alpha op(A) Bfor$Sideis$CblasLeftandB = \alpha B op(A)for$Sideis$CblasRight. The matrix$Ais triangular andop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When$Uplois$CblasUpperthen the upper triangle of$Ais used, and when$Uplois$CblasLowerthen the lower triangle of$Ais used. If$Diagis$CblasNonUnitthen the diagonal of$Ais used, but if$Diagis$CblasUnitthen the diagonal elements of the matrix$Aare taken as unity and are not referenced. The function returns0if the operation succeeded,1otherwise.gsl_blas_dtrsm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)β This function computes the inverse-matrix matrix productB = \alpha op(inv(A))Bfor$Sideis$CblasLeftandB = \alpha B op(inv(A))for$Sideis$CblasRight. The matrix$Ais triangular andop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When$Uplois$CblasUpperthen the upper triangle of$Ais used, and when$Uplois$CblasLowerthen the lower triangle of$Ais used. If$Diagis$CblasNonUnitthen the diagonal of$Ais used, but if$Diagis$CblasUnitthen the diagonal elements of the matrix$Aare taken as unity and are not referenced. The function returns0if the operation succeeded,1otherwise.
Now the complex single-precision squad, also listed bare like the original:
gsl_blas_cgemmgsl_blas_csymmgsl_blas_csyrkgsl_blas_csyr2kgsl_blas_ctrmmgsl_blas_ctrsm
And then the complex double-precision detailed ones:
gsl_blas_zgemm($TransA, $TransB, $alpha, $A, $B, $beta, $C)β This function computes the matrix-matrix product and sumC = \alpha op(A) op(B) + \beta Cwhereop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTransand similarly for the parameter$TransB. The function returns0if the operation succeeded,1otherwise.$A,$Band$Care complex matrices.gsl_blas_zsymm($Side, $Uplo, $alpha, $A, $B, $beta, $C)β This function computes the matrix-matrix product and sumC = \alpha A B + \beta Cfor$Sideis$CblasLeftandC = \alpha B A + \beta Cfor$Sideis$CblasRight, where the matrix$Ais symmetric. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Aare used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Aare used.$A,$Band$Care complex matrices. The function returns0if the operation succeeded,1otherwise.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 Cwhen$Transis$CblasNoTransandC = \alpha A^T A + \beta Cwhen$Transis$CblasTrans. Since the matrix$Cis symmetric only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Care used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Care used. The function returns0if the operation succeeded,1otherwise.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 Cwhen$Transis$CblasNoTransandC = \alpha A^T B + \alpha B^T A + \beta Cwhen$Transis$CblasTrans. Since the matrix$Cis symmetric only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Care used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Care used. The function returns0if the operation succeeded,1otherwise.$A,$Band$Care complex matrices and$betais a complex number.gsl_blas_ztrmm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)β This function computes the matrix-matrix productB = \alpha op(A) Bfor$Sideis$CblasLeftandB = \alpha B op(A)for$Sideis$CblasRight. The matrix$Ais triangular andop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When$Uplois$CblasUpperthen the upper triangle of$Ais used, and when$Uplois$CblasLowerthen the lower triangle of$Ais used. If$Diagis$CblasNonUnitthen the diagonal of$Ais used, but if$Diagis$CblasUnitthen the diagonal elements of the matrix$Aare taken as unity and are not referenced. The function returns0if the operation succeeded,1otherwise.$Aand$Bare complex matrices and$alphais a complex number.gsl_blas_ztrsm($Side, $Uplo, $TransA, $Diag, $alpha, $A, $B)β This function computes the inverse-matrix matrix productB = \alpha op(inv(A))Bfor$Sideis$CblasLeftandB = \alpha B op(inv(A))for$Sideis$CblasRight. The matrix$Ais triangular andop(A) = A, A^T, A^Hfor$TransA = $CblasNoTrans, $CblasTrans, $CblasConjTrans. When$Uplois$CblasUpperthen the upper triangle of$Ais used, and when$Uplois$CblasLowerthen the lower triangle of$Ais used. If$Diagis$CblasNonUnitthen the diagonal of$Ais used, but if$Diagis$CblasUnitthen the diagonal elements of the matrix$Aare taken as unity and are not referenced. The function returns0if the operation succeeded,1otherwise.$Aand$Bare complex matrices and$alphais a complex number.
Then the complex hermitian single-precision bare list:
gsl_blas_chemmgsl_blas_cherkgsl_blas_cher2k
And finally the complex double-precision hermitian detailed ones:
gsl_blas_zhemm($Side, $Uplo, $alpha, $A, $B, $beta, $C)β This function computes the matrix-matrix product and sumC = \alpha A B + \beta Cfor$Sideis$CblasLeftandC = \alpha B A + \beta Cfor$Sideis$CblasRight, where the matrix$Ais hermitian. WhenUploisCblasUpperthen the upper triangle and diagonal ofAare used, and whenUploisCblasLowerthen the lower triangle and diagonal ofAare 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 Cwhen$Transis$CblasNoTransandC = \alpha A^H A + \beta Cwhen$Transis$CblasTrans. Since the matrix$Cis hermitian only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Care used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Care used. The imaginary elements of the diagonal are automatically set to zero. The function returns0if the operation succeeded,1otherwise.$A,$Band$Care complex matrices and$alphaand$betaare 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 Cwhen$Transis$CblasNoTransandC = \alpha A^H B + \alpha^* B^H A + \beta Cwhen$Transis$CblasConjTrans. Since the matrix$Cis hermitian only its upper half or lower half need to be stored. When$Uplois$CblasUpperthen the upper triangle and diagonal of$Care used, and when$Uplois$CblasLowerthen the lower triangle and diagonal of$Care used. The imaginary elements of the diagonal are automatically set to zero. The function returns0if the operation succeeded,1otherwise.
okay so to actually use these, 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:
level1level2level3
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.
That's the whole page, bestie! This slayage came from perl v5.42.3, dated 2026-08-20, and it's Math::GSL::BLAS(3pm). Now go forth and multiply those matrices. Periodt. π
β¨
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms