BLAS SupportThis section provides support tor Basic Linear Algebra Subprogram
support.The BLAS functions use the column major mapping for the storage of a
matrix. This is the mapping used in Fortran, and has the entries of the
first column followed by the entries of the second column. This is the
transpose of the row major form commonly used in the C language where the
entries of the first row are followed by the entries of the second
row.TypesSTD.BLAS.TypesSTD.BLAS.TypesBLAS.TypesTypesvalue_tREAL8dimension_tUNSIGNED4matrix_tSET OF REAL8TriangleENUM(UNSIGNED1, Upper=1, Lower=2)DiagonalENUM(UNSIGNED1, UnitTri=1, NotUnitTri=2)SideENUM(UNSIGNED1, Ax=1, xA=2)Types for the Block Basic Linear Algebra Sub-programs supportICellFuncSTD.BLAS.ICellFuncSTD.BLAS.ICellFuncBLAS.ICellFuncICellFunc(v, r,c);vThe valuerThe row ordinalcThe column ordinalReturn:The updated valueICellFunc is the function prototype
for Apply2Cells.Example:IMPORT STD;
REAL8 my_func(STD.BLAS.Types.value_t v, STD.BLAS.Types.dimension_t x, STD.BLAS.Types.dimension_t y)
:= 1/v; //set element to the reciprocal value
See Also: Apply2CellsApply2CellsSTD.BLAS.Apply2CellsSTD.BLAS.Apply2CellsBLAS.Apply2CellsApply2Cells(m, n,x, f);mNumber of rowsnNumber of columnsxMatrixfFunction to applyReturn:The updated matrixThe Apply2Cells function iterates a
matrix and applies a function to each cell.Example:IMPORT STD;
STD.BLAS.Types.value_t example_1(STD.BLAS.Types.value_t v,
STD.BLAS.Types.dimensiopn_t x,
STD.BLAS.Types.dimension_t y) := FUNCTION
RETURN IF(x=y, 1.0, 1/v);
END;
init_mat := [1, 2, 4, 4, 5, 10, 2, 5, 2];
new_mat := STD.BLAS.Apply2Cells(3, 3, init_mat, example_1);
// The new_mat matrix will be [1, .5, .25, .25, 1, .1, .5, .2, 1]
See Also: ICellFuncdasumSTD.BLAS.dasumSTD.BLAS.dasumBLAS.dasumdasum(m, x, incx,
skipped);mNumber of entriesxThe column major matrix holding the vectorincxxThe increment for x, 1 in the case of an actual
vectorskippedThe number of entries stepped over. Default is
zero.Return:The sum of the absolute valuesThe dasum function gets the
absolute sum, the 1 norm of a vector.Example:IMPORT STD;
STD.BLAS.Types.matrix_t test_data := [2, -2, -3, 3, 1, 3, -1, -1, 1];
STD.BLAS.dasum(9, test_data, 1); //sums the absolute values of the matrix, and returns 17
daxpySTD.BLAS.daxpySTD.BLAS.daxpyBLAS.dasumdasum(N, alpha, X, incX, Y, incY,
x_skipped,y_skipped);NNumber of entriesalphaThe column major matrix holding the vectorXThe increment for x, 1 in the case of an actual
vectorincXThe column major matrix holding the vector XYThe column major matrix holding the vector YincYThe increment or stride of Yx_skippedThe number of entries stepped over. to get to the first X
.y_skippedThe number of entries stepped over. to get to the first Y
.Return:The updated matrixThe daxpy function is used to sum
two vectors or matrices with a scalar multiplier applied during the sum
operation..Example:IMPORT STD;
STD.BLAS.Types.t_matrix term_1 := [1, 2, 3];
STD.BLAS.Types.t_matrix term_2 := [3, 2, 1].
STD.BLAS.daxpy(3, 2, term_1, 1, term_2, 1); // result is [5, 6, 7]
dgemmSTD.BLAS.dgemmSTD.BLAS.dgemmBLAS.dgemmdgemm(transposeA, transposeB, M, N, K,
alpha, A, B, beta, C);transposeATrue when transpose of A is usedtransposeBTrue when transpose of B is usedMNumber of rows in productNNumber of columns in productKNumber of columns/rows for the
multiplier/multiplicandalphaScalar used on AAMatrix ABMatrix BbetaScalar for matirx CCMatrix C (or empty)Return:The updated matrixThe dgemm function is used to
multiply two matrices and optionally add that product to another
matrix.Example:IMPORT STD;
STD.BLAS.Types.t_matrix term_a := [2, 4, 8];
STD.BLAS.Types.t_matrix term_c := [2, 1, 1];
STD.BLAS.dgemm(TRUE, FALSE, 3, 3, 1, 1, term_a, term_b);
//the outer product of the term_a and term_b vectors
//result is [4,8, 16, 2, 4, 8, 2, 4, 8]
dgetf2STD.BLAS.dgetf2STD.BLAS.dgetf2BLAS.dgetf2dgetf2(m, n, a);mNumber of rows of matrix anNumber of columns of matrix aaMatrix aReturn:Composite matrix of factors, lower triangle has an implied
diagonal of ones. Upper triangle has the diagonal of the
composite.The dgetf2 function produces a
combine lower and upper triangular factorization.Example:IMPORT STD;
STD.BLAS.Types.t_matrix test := [2,4,6,3,10,25, 9,34,100];
STD.BLAS.dgetf2(3, 3, test); //result is [2,2,3,3,4,4,9,16,25];
dpotf2STD.BLAS.dpotf2STD.BLAS.dpotf2BLAS.dpotf2dpotf2(tri,, r, A, clear);triIndicates whether upper or lower triangle is usedrNumber of rows/columns in the square matrixAThe square matrix AclearClears the unused triangleReturn:The triangular matrix requestedThe dpotf2 function computes the
Cholesky factorization of a real symmetric positive definite matrix A. The
factorization has the form A = U**T*U if the tri
parameter is Triangle.Upper, or A = L * L**T if the
tri parameter is Triangle.Lower. This is the
unblocked version of the algorithm, calling Level 2 BLAS.Example:IMPORT STD;
STD.BLAS.Types.matrix_t symmetric_pos_def := [4, 6, 8, 6, 13, 18, 8, 18, 29];
Lower_Triangle := BLAS.dpotf2(STD.BLAS.Types.Triangle.lower, 3, symmetric_pos_def); dscalSTD.BLAS.dscalSTD.BLAS.dscalBLAS.dscaldscal(N, alpha, X, incX,
skipped);NNumber of elements in the vectoralphaThe scaling factorXThe column major matrix holding the vectorincXThe stride to get to the next element in the vectorskippedThe number of elements skipped to get to the first
elementReturn:The updated matrixThe dscal function scales a vector
alpha.Example:IMPORT STD;
STD.BLAS.Types.matrix_t test := [1, 1, 1, 2, 2, 2, 3, 3, 3];
result := STD.BLAS.dscal(9, 2.0, test, 1); // multiply each element by 2
dsyrkSTD.BLAS.dsyrkSTD.BLAS.dsyrkBLAS.dsyrkdsyrk(tri, transposeA, N, K, alpha, A,
beta, C, clear);triIndicates whether upper or lower triangle is usedtransposeATranspose the A matrix to be NxKNNumber of rowsKNumber of columns in the update matrix or transposealphaThe alpha scalarAThe update matrix, either NxK or KxNbetaThe beta scalarCThe matrix to updateclearClear the triangle that is not updated. BLAS assumes that
symmetric matrices have only one of the triangles and this option
lets you make that true.Return:The updated matrixThe dsyrk function implements a
symmetric rank update C <- alpha A**T A + beta C or c <- alpha A
A**T + beta C. C is N x N.Example:IMPORT STD;
STD.BLAS.Types.matrix_t initC := [1, 1, 1, 2, 2, 2, 3, 3, 3];
STD.BLAS.Types.matrix_t initA := [1, 1, 1];
Test1_mat := STD.BLAS.dsyrk(STD.BLAS.Types.Triangle.upper, FALSE, 3, 1, 1, initA, 1, initC, TRUE)
dtrsmSTD.BLAS.dtrsmSTD.BLAS.dtrsmBLAS.dsyrkdtrsm(side, tri, transposeA, diag, M, N,
lda, alpha, A, B);sideSide for A, Side.Ax is op(A) X = alpha BtriIndicates whether upper or lower triangle is usedtransposeAIs op(A) the transpose of AdiagThe diagonal (an implied unit diagonal or supplied)MNumber of rowsNNumber of columnslda The leading dimension of the A matrix, either M or
NalphaThe scalar multiplier for BAA triangular matrixBThe matrix of values for the solveReturn:The matrix of coefficients to get BThe dtrsm function is a triangular
matrix solver. op(A) X = alpha B or X op(A) = alpha B * where op is
Transpose, X and B is MxNExample:IMPORT STD;
Side := STD.BLAS.Types.Side;
Diagonal := STD.BLAS.Types.Diagonal;
Triangle := STD.BLAS.Types.Triangle;
STD.BLAS.Types.matrix_t left_a0 := [2, 3, 4, 0, 2, 3, 0, 0, 2];
STD.BLAS.Types.matrix_t mat_b := [4, 6, 8, 6, 13, 18, 8, 18, 29];
Test1_mat := STD.BLAS.dtrsm(Side.Ax, Triangle.Lower, FALSE, Diagonal.NotUnitTri,
3, 3, 3, 1.0, left_a0, mat_b);
extract_diagSTD.BLAS.extract_diag STD.BLAS.extract_diagBLAS.extract_diagextract_diag(m.n.x);mNumber of rowsnNumber of columnsxThe matrix from which to extract the diagonalReturn:Diagonal matrixThe extract_diag function extracts
the diagonal of he matrixExample:IMPORT STD;
STD.BLAS.Types.matrix_t x := [1.0, 2.0, 3.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0];
diagonal_only := := STD.BLAS.extract_diag(3, 3, x);
extract_triSTD.BLAS.extract_tri STD.BLAS.extract_triBLAS.extract_triextract_tri(m, n, tri, dt, a );mNumber of rowsnNumber of columnstriIndicates whether upper or lower triangle is useddtUse Diagonal.NotUnitTri or Diagonal.UnitTriaThe matrix, usually a composite from factoringReturn:TriangleThe extract_tri function extracts
the upper or lower triangle. The diagonal can be the actual or implied
unit diagonal.Example:IMPORT STD;
Diagonal := STD.BLAS.Types.Diagonal;
Triangle := STD.BLAS.Types.Triangle;
STD.BLAS.Types.matrix_t x := [1.0, 2.0, 3.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0];
triangle := STD.BLAS.extract_tri(3, 3, Triangle.upper, Diagonal.NotUnitTri, x);
make_diagSTD.BLAS.make_diag STD.BLAS.make_diagBLAS.make_diagmake_diag(m, v, X );mNumber of diagonal entriesvOption value, default is 1XOptional input of diagonal values, multiplied by vReturn:A diagonal matrixThe make_diag function generates a
diagonal matrix.Example:IMPORT STD;
STD.BLAS.Types.matrix_t init1 := [1.0, 2.0, 3.0, 4.0];
Square := STD.BLAS.make_diag(4, 1, init1); //4x4 with diagonal 1, 2, 3, 4
make_vectorSTD.BLAS.make_vector STD.BLAS.make_vectorBLAS.make_vectormake_vector(m, v );mNumber of elementsvThe values, default is 1Return:The vectorThe make_vector function generates
a vector of dimension nExample:IMPORT STD;
twos_vector := STD.BLAS.make_vector(4, 2); // a vector of [2, 2, 2, 2]
traceSTD.BLAS.trace STD.BLAS.tracerBLAS.tracetrace(m, n, x );mNumber of rowsnNumber of columnsxThe matrixReturn:The trace (sum of the diagonal entries)The trace function computes the
trace of the input matrixExample:IMPORT STD;
STD.BLAS.Types.matrix_t x := [1.0, 2.0, 3.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0];
trace_of_x := STD.BLAS.trace(3,3,x); // the trace is 7