This chapter is concerned with basic linear algebra routines which perform elementary algebraic operations involving scalars, vectors and matrices. Most routines for such operations conform either to the specifications of the BLAS (Basic Linear Algebra Subprograms) or to the specifications of the BLAST (Basic Linear Algebra Subprograms Technical) Forum. This chapter includes routines from the BLAST specifications. Most (BLAS) routines for such operations are available in Chapter F06.
They are called extensively by routines in other chapters of the NAG Library, especially in the linear algebra chapters. They are intended to be useful building-blocks for users of the Library who are developing their own applications. The routines fall into four main groups (following the definitions introduced by the BLAS):
Level 0: scalar operations;
Level 1: vector operations;
Level 2: matrix-vector operations and matrix operations which includes single matrix operations;
Level 3: matrix-matrix operations.
The terminology reflects the number of operations involved, so for example a Level 2 routine involves operations, for vectors and matrices of order .
Because of the overlap of functionality with Chapter F06, only a subset of BLAST routines are implemented in this chapter. A full descripion of the
3Recommendations on Choice and Use of Available Routines
Table 1 shows the naming scheme for the routines in this chapter which follows the naming scheme used in Chapter F06.
The heading ‘mixed type’ is for routines where a mixture of data types is involved, such as a routine that returns the real norm of a complex vector. In future marks of the Library, routines may be included in categories that are currently empty and further categories may be introduced.
Those routines which conform to the specifications of the BLAS may be called either by their NAG names or by their BLAS names.
In many implementations of the NAG Library, references to Chapter F06 BLAS names may be linked to an efficient machine-specific implementation of the BLAS, usually provided by the vendor of the machine; Chapter F16 BLAS routines are unlikely to be provide by a vendor. Such implementations are stringently tested before being used with the NAG Library, to ensure that they correctly meet the specifications of the BLAS, and that they return the desired accuracy. Use of BLAS names is recommended for efficiency.
References to NAG routine names (beginning F06- or F16-) are always linked to the code provided in the NAG Library and may be significantly slower (in the case of Chapter F06 routines) than the equivalent BLAS routine.
The names of the Level-2 and Level-3 BLAS follow a simple scheme (which is similar to that used for LAPACK routines in Chapters F07 and F08). Each name has the structure XYYZZZ, where the components have the following meanings:
–the initial letter X indicates the data type (real or complex) and precision:
real, single precision (in Fortran, REAL)
real, double precision (in Fortran, DOUBLE PRECISION)
complex, single precision (in Fortran, COMPLEX)
complex, double precision (in Fortran, COMPLEX*16 or DOUBLE COMPLEX)
–the second and third letters YY indicate the type of the matrix (and in some cases its storage scheme):
symmetric (packed storage)
(complex) Hermitian (packed storage)
(complex) Hermitian band
triangular (packed storage)
–the remaining , or letters ZZZ indicate the computation performed:
solve a system of linear equations
solve a system of linear equations with a matrix of right-hand sides
Thus the routine blas_daxpby performs a sum of two real, scaled vectors in double precision;
the corresponding routine for complex scalars and vectors is blas_zaxpby.
The names of the Level-1 BLAS mostly follow the same convention for the initial letter (S-, C-, D- or Z-), except for a few involving data of mixed type, where the first two characters are precision-dependent.
3.2The Level-0 Scalar Routines
The Level-0 routines perform operations on scalars or on vectors or matrices of order .
3.3The Level-1 Vector Routines
The Level-1 routines perform operations either on a single vector or on a pair of vectors.
3.4The Level-2 Matrix-vector and Matrix Routines
The Level-2 routines perform operations involving either a matrix on its own, or a matrix and one or more vectors.
3.5The Level-3 Matrix-matrix Routines
The Level-3 routines perform operations involving matrix-matrix products.
Vector arguments (except in the Level-1 Sparse BLAS) are represented by a one-dimensional array, immediately followed by an increment argument whose name consists of the three characters INC followed by the name of the array. For example, a vector is represented by the two arguments x and incx. The length of the vector, say, is passed as a separate argument,
The increment argument is the spacing (stride) in the array between the elements of the vector. For instance, if ,
then the elements of are in locations of the array
and the intermediate locations are not referenced.
When , the vector element is in the array element . When , the elements are stored in the reverse order so that the vector element is in the array element and hence, in particular, the element is in . The declared length of the array x in the calling subroutine must be at least .
Negative increments are permitted only for:
Level-1 routines which have more than one vector argument;
Level-2 BLAS routines (but not for other Level-2 routines)
Zero increments are formally permitted for Level-1 routines with more than one argument (in which case the element is accessed repeatedly), but their use is strongly discouraged since the effect may be implementation-dependent. There is usually an alternative routine in this chapter, with a simplified argument list, to achieve the required purpose. Zero increments are not permitted in the Level-2 BLAS.
3.7Matrix Arguments and Storage Schemes
In this chapter the following different storage schemes are used for matrices:
–conventional storage in a two-dimensional array;
–packed and RFP storage for symmetric, Hermitian or triangular matrices;
–band storage for band matrices;
–storage for spiked matrices.
These storage schemes are compatible with those used in
Chapters F07 and F08. (Different schemes for packed or band storage are used in a few older routines in
Chapters F01, F02, F03 and F04.)
Chapter F01 provides some utility routines for conversion between storage schemes.
In the examples, indicates an array element which need not be set and is not referenced by the routines. The examples illustrate only the relevant leading rows and columns of the arrays; array arguments may of course have additional rows or columns, according to the usual rules for passing array arguments in Fortran.
Please see Section 3.3.1 in the F07 Chapter Introduction for full details.
Please see Section 3.3.2 in the F07 Chapter Introduction for full details.
3.7.3Rectangular Full Packed (RFP) storage
Please see Section 3.3.3 in the F07 Chapter Introduction for full details.
Please see Section 3.3.4 in the F07 Chapter Introduction for full details.
3.7.5Unit triangular matrices
Please see Section 3.3.5 in the F07 Chapter Introduction for full details.
3.7.6Real diagonal elements of complex Hermitian matrices
Please see Section 3.3.6 in the F07 Chapter Introduction for full details.
Many of the routines in this chapter have one or more option arguments, of type CHARACTER. The descriptions in the routine documents refer only to upper-case values (for example
); however, in every case, the corresponding lower-case characters may be supplied (with the same meaning). Any other value is illegal.
A longer character string can be passed as the actual argument, making the calling program more readable, but only the first character is significant. (This is a feature of Fortran.) For example:
The following option arguments are used in this chapter:
If , operate with the matrix (Not transposed);
if , operate with the Transpose of the matrix;
if , operate with the Conjugate transpose of the matrix.
If , upper triangle or trapezoid of matrix;
if , lower triangle or trapezoid of matrix.
If , unit triangular;
if , nonunit triangular.
If , operate from the left-hand side;
if , operate from the right-hand side.
If or , -norm of a matrix;
if , -norm of a matrix;
if or , Frobenius or Euclidean norm of a matrix;
if , maximum absolute value of the elements of a matrix (not strictly a norm).
The option argument
specifies different matrix norms whose definitions are given here for reference (for a general matrix ):
One-norm ( or ):
Frobenius or Euclidean norm ( or ):
If is symmetric or Hermitian, .
can also be used to specify the maximum absolute value (if
but this is not a norm in the strict mathematical sense.
Routines in this chapter do not use the usual NAG Library error-handling mechanism, involving the argument IFAIL.
If one of the Level-2 or Level-3 BLAS routines is called with an invalid value of one of its arguments, then an error message is output on the error message unit (see x04aaf), giving the name of the routine and the number of the first invalid argument, and execution of the program is terminated. The following values of arguments are invalid:
–any value of the arguments
diag, whose meaning is not specified;
–a negative value of any of the arguments
–too small a value for any of the leading dimension arguments;
–a zero value for the increment arguments
Zero values for the matrix dimensions
k are considered valid.
The other routines in this chapter do not report any errors in their arguments. Normally, if called, for example, with an unspecified value for one of the option arguments, or with a negative value of one of the problem dimensions
n, they simply do nothing and return immediately.
complex matrix and vector(s),
compute a norm or the element of largest absolute value,