Unit BLAS

 

Basic Linear Algebra routines for Turbo Pascal

Copyright 1991, J. W. Rider

 

 

procedures and functions compatible with the "Basic Linear

Algebra Subroutines"

 

we're only going to worry about BLAS compatibility for IEEE

operations

 

for each underlying element type, the following functions are defined:

 

  copy(n,x,incx,y,incy) -- overwrite the first "n" elements of "y"

                           with the corresponding elements of "x"

                           (Y:=X)

 

  swap(n,x,incx,y,incy) -- exchange the first "n" elements of "x" and "y"

 

  scal(n,a,x,incx)      -- (X:=a*X)

 

  axpy(n,a,x,incx,y,incy)

                        -- (Y:=a*X+Y)

 

  dot(n,x,incx,y,incy)  -- dot product of X and Y

 

  nrm2(n,x,incx)        -- sum of square of elements of X

 

  asum(n,x,incx)        -- sub of absolute value of elements of X

 

  amax(n,x,incx)        -- index of element in X with largest absolute value

 

  rotg(a,b,c,s)         -- generate a rotation

 

  rot(n,x,incx,y,incy,c,s)

                        -- apply the rotation specified by c and s

 

 

 

  Originally, these routines were defined for FORTRAN.  Under FORTRAN,

  the "type" associated with a routine is closely related to the first

  letter of the "name" of the routine itself.  In many respects, this

  shaped the naming scheme used by many numerical libraries.  While it is

  not necessary to continue this under pascal, I have chosen to do so for

  two reasons:

 

     1. It provides a different name for similar routines that vary only

        by the type of arguments or the value returned.

 

     2. It maintains name compatibility with existing numerical routines

        that depend upon BLAS (e.g., LINPACK).

 

 

 

interface

 

type

 

     complex_single = record rp,ip:single; end

     complex_double = record rp,ip:double; end

 

     pcxsng = ^complex_single

     pcxdbl = ^complex_double

 

 

Bookkeeping operations:

 

  Move contents of one vector to another:

 

    scopy(n:integer; var x; incx:integer; var y; incy:integer)

    dcopy(n:integer; var x; incx:integer; var y; incy:integer)

    ccopy(n:integer; var x; incx:integer; var y; incy:integer)

    zcopy(n:integer; var x; incx:integer; var y; incy:integer)

 

  Exchange contents of two vectors:

 

    sswap(n:integer; var x; incx:integer; var y; incy:integer)

    dswap(n:integer; var x; incx:integer; var y; incy:integer)

    cswap(n:integer; var x; incx:integer; var y; incy:integer)

    zswap(n:integer; var x; incx:integer; var y; incy:integer)

 

 

Multiplying a vector by a scalar:

 

  Real-valued scalar:

 

    sscal (n:integer; a:single; var x; incx:integer)

    dscal (n:integer; a:double; var x; incx:integer)

    csscal(n:integer; a:single; var x; incx:integer)

    zdscal(n:integer; a:double; var x; incx:integer)

 

  Complex scalar:

 

    cscal (n:integer; var a:complex_single; var x; incx:integer)

    zscal (n:integer; var a:complex_double; var x; incx:integer)

 

 

Add one scaled vector to another (for elementary matrix

row/column operations):

 

    saxpy(n:integer; a:single; var x; incx:integer; var y; incy:integer)

    daxpy(n:integer; a:double; var x; incx:integer; var y; incy:integer)

 

    caxpy(n:integer; var a:complex_single; var x; incx:integer;

                                           var y; incy:integer)

 

    zaxpy(n:integer; var a:complex_double; var x; incx:integer;

                                           var y; incy:integer)

 

 

Dot Product of two vectors:

 

    sdot (n:integer; var x; incx:integer; var y; incy:integer):single

    ddot (n:integer; var x; incx:integer; var y; incy:integer):double

 

    cdotc(n:integer; var x; incx:integer; var y; incy:integer):pcxsng

    cdotu(n:integer; var x; incx:integer; var y; incy:integer):pcxsng

    zdotc(n:integer; var x; incx:integer; var y; incy:integer):pcxdbl

    zdotu(n:integer; var x; incx:integer; var y; incy:integer):pcxdbl

 

 

Vector Norms:

 

  2-norms (Euclidean):

 

    snrm2 (n:integer; var x; incx:integer):single

    dnrm2 (n:integer; var x; incx:integer):double

    scnrm2(n:integer; var x; incx:integer):single

    dznrm2(n:integer; var x; incx:integer):double

 

  1-norms:

 

    sasum (n:integer; var x; incx:integer):single

    dasum (n:integer; var x; incx:integer):double

    scasum(n:integer; var x; incx:integer):single

    dzasum(n:integer; var x; incx:integer):double

 

  Infinity-norms:

 

    isamax(n:integer; var x; incx:integer):integer

    idamax(n:integer; var x; incx:integer):integer

    icamax(n:integer; var x; incx:integer):integer

    izamax(n:integer; var x; incx:integer):integer

 

 

Rotations of vectors:

 

  Generate:

 

    srotg(var a,b,c,s:single)

    drotg(var a,b,c,s:double)

 

  Apply:

 

    srot(n:integer; var x; incx:integer; var y; incy:integer; c,s:single)

    drot(n:integer; var x; incx:integer; var y; incy:integer; c,s:double)

 

 

 

REFERENCES:

 

  Coleman and Van Loan, Handbook for Matrix Computations, SIAM.

 

  Dongarra, Bunch, Moler, and Stewart, LINPACK User's Guide, SIAM.