📄 blas.texi
字号:
@cindex linear algebra, BLAS
@cindex matrix, operations
@cindex vector, operations
@cindex BLAS
@cindex CBLAS
@cindex Basic Linear Algebra Subroutines (BLAS)
The Basic Linear Algebra Subprograms (@sc{blas}) define a set of fundamental
operations on vectors and matrices which can be used to create optimized
higher-level linear algebra functionality.
The library provides a low-level layer which corresponds directly to the
C-language @sc{blas} standard, referred to here as ``@sc{cblas}'', and a
higher-level interface for operations on GSL vectors and matrices.
Users who are interested in simple operations on GSL vector and matrix
objects should use the high-level layer, which is declared in the file
@code{gsl_blas.h}. This should satisfy the needs of most users. Note
that GSL matrices are implemented using dense-storage so the interface
only includes the corresponding dense-storage @sc{blas} functions. The full
@sc{blas} functionality for band-format and packed-format matrices is
available through the low-level @sc{cblas} interface.
The interface for the @code{gsl_cblas} layer is specified in the file
@code{gsl_cblas.h}. This interface corresponds to the @sc{blas} Technical
Forum's draft standard for the C interface to legacy @sc{blas}
implementations. Users who have access to other conforming @sc{cblas}
implementations can use these in place of the version provided by the
library. Note that users who have only a Fortran @sc{blas} library can
use a @sc{cblas} conformant wrapper to convert it into a @sc{cblas}
library. A reference @sc{cblas} wrapper for legacy Fortran
implementations exists as part of the draft @sc{cblas} standard and can
be obtained from Netlib. The complete set of @sc{cblas} functions is
listed in an appendix (@pxref{GSL CBLAS Library}).
There are three levels of @sc{blas} operations,
@table @b
@item Level 1
Vector operations, e.g. @math{y = \alpha x + y}
@item Level 2
Matrix-vector operations, e.g. @math{y = \alpha A x + \beta y}
@item Level 3
Matrix-matrix operations, e.g. @math{C = \alpha A B + C}
@end table
@noindent
Each routine has a name which specifies the operation, the type of
matrices involved and their precisions. Some of the most common
operations and their names are given below,
@table @b
@item DOT
scalar product, @math{x^T y}
@item AXPY
vector sum, @math{\alpha x + y}
@item MV
matrix-vector product, @math{A x}
@item SV
matrix-vector solve, @math{inv(A) x}
@item MM
matrix-matrix product, @math{A B}
@item SM
matrix-matrix solve, @math{inv(A) B}
@end table
@noindent
The type of matrices are,
@table @b
@item GE
general
@item GB
general band
@item SY
symmetric
@item SB
symmetric band
@item SP
symmetric packed
@item HE
hermitian
@item HB
hermitian band
@item HP
hermitian packed
@item TR
triangular
@item TB
triangular band
@item TP
triangular packed
@end table
@noindent
Each operation is defined for four precisions,
@table @b
@item S
single real
@item D
double real
@item C
single complex
@item Z
double complex
@end table
@noindent
Thus, for example, the name @sc{sgemm} stands for ``single-precision
general matrix-matrix multiply'' and @sc{zgemm} stands for
``double-precision complex matrix-matrix multiply''.
@menu
* GSL BLAS Interface::
* BLAS Examples::
* BLAS References and Further Reading::
@end menu
@node GSL BLAS Interface
@section GSL BLAS Interface
GSL provides dense vector and matrix objects, based on the relevant
built-in types. The library provides an interface to the @sc{blas}
operations which apply to these objects. The interface to this
functionality is given in the file @code{gsl_blas.h}.
@comment CblasNoTrans, CblasTrans, CblasConjTrans
@comment CblasUpper, CblasLower
@comment CblasNonUnit, CblasUnit
@comment CblasLeft, CblasRight
@menu
* Level 1 GSL BLAS Interface::
* Level 2 GSL BLAS Interface::
* Level 3 GSL BLAS Interface::
@end menu
@node Level 1 GSL BLAS Interface
@subsection Level 1
@deftypefun int gsl_blas_sdsdot (float @var{alpha}, const gsl_vector_float * @var{x}, const gsl_vector_float * @var{y}, float * @var{result})
@cindex DOT, Level-1 BLAS
This function computes the sum @math{\alpha + x^T y} for the vectors
@var{x} and @var{y}, returning the result in @var{result}.
@end deftypefun
@deftypefun int gsl_blas_sdot (const gsl_vector_float * @var{x}, const gsl_vector_float * @var{y}, float * @var{result})
@deftypefunx int gsl_blas_dsdot (const gsl_vector_float * @var{x}, const gsl_vector_float * @var{y}, double * @var{result})
@deftypefunx int gsl_blas_ddot (const gsl_vector * @var{x}, const gsl_vector * @var{y}, double * @var{result})
These functions compute the scalar product @math{x^T y} for the vectors
@var{x} and @var{y}, returning the result in @var{result}.
@end deftypefun
@deftypefun int gsl_blas_cdotu (const gsl_vector_complex_float * @var{x}, const gsl_vector_complex_float * @var{y}, gsl_complex_float * @var{dotu})
@deftypefunx int gsl_blas_zdotu (const gsl_vector_complex * @var{x}, const gsl_vector_complex * @var{y}, gsl_complex * @var{dotu})
These functions compute the complex scalar product @math{x^T y} for the
vectors @var{x} and @var{y}, returning the result in @var{result}
@end deftypefun
@deftypefun int gsl_blas_cdotc (const gsl_vector_complex_float * @var{x}, const gsl_vector_complex_float * @var{y}, gsl_complex_float * @var{dotc})
@deftypefunx int gsl_blas_zdotc (const gsl_vector_complex * @var{x}, const gsl_vector_complex * @var{y}, gsl_complex * @var{dotc})
These functions compute the complex conjugate scalar product @math{x^H
y} for the vectors @var{x} and @var{y}, returning the result in
@var{result}
@end deftypefun
@deftypefun float gsl_blas_snrm2 (const gsl_vector_float * @var{x})
@deftypefunx double gsl_blas_dnrm2 (const gsl_vector * @var{x})
@cindex NRM2, Level-1 BLAS
These functions compute the Euclidean norm
@c{$||x||_2 = \sqrt{\sum x_i^2}$}
@math{||x||_2 = \sqrt @{\sum x_i^2@}} of the vector @var{x}.
@end deftypefun
@deftypefun float gsl_blas_scnrm2 (const gsl_vector_complex_float * @var{x})
@deftypefunx double gsl_blas_dznrm2 (const gsl_vector_complex * @var{x})
These functions compute the Euclidean norm of the complex vector @var{x},
@tex
\beforedisplay
$$
||x||_2 = \sqrt{\sum (\Re(x_i)^2 + \Im(x_i)^2)}.
$$
\afterdisplay
@end tex
@ifinfo
@example
||x||_2 = \sqrt @{\sum (\Re(x_i)^2 + \Im(x_i)^2)@}.
@end example
@end ifinfo
@noindent
@end deftypefun
@deftypefun float gsl_blas_sasum (const gsl_vector_float * @var{x})
@deftypefunx double gsl_blas_dasum (const gsl_vector * @var{x})
@cindex ASUM, Level-1 BLAS
These functions compute the absolute sum @math{\sum |x_i|} of the
elements of the vector @var{x}.
@end deftypefun
@deftypefun float gsl_blas_scasum (const gsl_vector_complex_float * @var{x})
@deftypefunx double gsl_blas_dzasum (const gsl_vector_complex * @var{x})
These functions compute the sum of the magnitudes of the real and
imaginary parts of the complex vector @var{x},
@c{$\sum \left( |\Re(x_i)| + |\Im(x_i)| \right)$}
@math{\sum |\Re(x_i)| + |\Im(x_i)|}.
@end deftypefun
@deftypefun CBLAS_INDEX_t gsl_blas_isamax (const gsl_vector_float * @var{x})
@deftypefunx CBLAS_INDEX_t gsl_blas_idamax (const gsl_vector * @var{x})
@deftypefunx CBLAS_INDEX_t gsl_blas_icamax (const gsl_vector_complex_float * @var{x})
@deftypefunx CBLAS_INDEX_t gsl_blas_izamax (const gsl_vector_complex * @var{x})
@cindex AMAX, Level-1 BLAS
These functions return the index of the largest element of the vector
@var{x}. The largest element is determined by its absolute magnitude for
real vector and by the sum of the magnitudes of the real and imaginary
parts @math{|\Re(x_i)| + |\Im(x_i)|} for complex vectors. If the
largest value occurs several times then the index of the first
occurrence is returned.
@end deftypefun
@deftypefun int gsl_blas_sswap (gsl_vector_float * @var{x}, gsl_vector_float * @var{y})
@deftypefunx int gsl_blas_dswap (gsl_vector * @var{x}, gsl_vector * @var{y})
@deftypefunx int gsl_blas_cswap (gsl_vector_complex_float * @var{x}, gsl_vector_complex_float * @var{y})
@deftypefunx int gsl_blas_zswap (gsl_vector_complex * @var{x}, gsl_vector_complex * @var{y})
@cindex SWAP, Level-1 BLAS
These functions exchange the elements of the vectors @var{x} and @var{y}.
@end deftypefun
@deftypefun int gsl_blas_scopy (const gsl_vector_float * @var{x}, gsl_vector_float * @var{y})
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -