<emphasis>BLAS Support</emphasis> This 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. Types STD.BLAS.Types STD.BLAS.Types BLAS.Types Types value_t REAL8 dimension_t UNSIGNED4 matrix_t SET OF REAL8 Triangle ENUM(UNSIGNED1, Upper=1, Lower=2) Diagonal ENUM(UNSIGNED1, UnitTri=1, NotUnitTri=2) Side ENUM(UNSIGNED1, Ax=1, xA=2) Types for the Block Basic Linear Algebra Sub-programs support ICellFunc STD.BLAS.ICellFunc STD.BLAS.ICellFunc BLAS.ICellFunc ICellFunc ( v, r , c ); v The value r The row ordinal c The column ordinal Return: The updated value ICellFunc 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: Apply2Cells Apply2Cells STD.BLAS.Apply2Cells STD.BLAS.Apply2Cells BLAS.Apply2Cells Apply2Cells ( m, n , x, f ); m Number of rows n Number of columns x Matrix f Function to apply Return: The updated matrix The 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: ICellFunc dasum STD.BLAS.dasum STD.BLAS.dasum BLAS.dasum dasum ( m, x, incx, skipped); m Number of entries x The column major matrix holding the vector incxx The increment for x, 1 in the case of an actual vector skipped The number of entries stepped over. Default is zero. Return: The sum of the absolute values The 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 daxpy STD.BLAS.daxpy STD.BLAS.daxpy BLAS.dasum dasum ( N, alpha, X, incX, Y, incY, x_skipped,y_skipped); N Number of entries alpha The column major matrix holding the vector X The increment for x, 1 in the case of an actual vector incX The column major matrix holding the vector X Y The column major matrix holding the vector Y incY The increment or stride of Y x_skipped The number of entries stepped over. to get to the first X . y_skipped The number of entries stepped over. to get to the first Y . Return: The updated matrix The 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] dgemm STD.BLAS.dgemm STD.BLAS.dgemm BLAS.dgemm dgemm ( transposeA, transposeB, M, N, K, alpha, A, B, beta, C); transposeA True when transpose of A is used transposeB True when transpose of B is used M Number of rows in product N Number of columns in product K Number of columns/rows for the multiplier/multiplicand alpha Scalar used on A A Matrix A B Matrix B beta Scalar for matirx C C Matrix C (or empty) Return: The updated matrix The 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] dgetf2 STD.BLAS.dgetf2 STD.BLAS.dgetf2 BLAS.dgetf2 dgetf2 ( m, n, a); m Number of rows of matrix a n Number of columns of matrix a a Matrix a Return: 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]; dpotf2 STD.BLAS.dpotf2 STD.BLAS.dpotf2 BLAS.dpotf2 dpotf2 ( tri,, r, A, clear); tri Indicates whether upper or lower triangle is used r Number of rows/columns in the square matrix A The square matrix A clear Clears the unused triangle Return: The triangular matrix requested The 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); dscal STD.BLAS.dscal STD.BLAS.dscal BLAS.dscal dscal ( N, alpha, X, incX, skipped); N Number of elements in the vector alpha The scaling factor X The column major matrix holding the vector incX The stride to get to the next element in the vector skipped The number of elements skipped to get to the first element Return: The updated matrix The 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 dsyrk STD.BLAS.dsyrk STD.BLAS.dsyrk BLAS.dsyrk dsyrk ( tri, transposeA, N, K, alpha, A, beta, C, clear); tri Indicates whether upper or lower triangle is used transposeA Transpose the A matrix to be NxK N Number of rows K Number of columns in the update matrix or transpose alpha The alpha scalar A The update matrix, either NxK or KxN beta The beta scalar C The matrix to update clear Clear 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 matrix The 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) dtrsm STD.BLAS.dtrsm STD.BLAS.dtrsm BLAS.dsyrk dtrsm ( side, tri, transposeA, diag, M, N, lda, alpha, A, B); side Side for A, Side.Ax is op(A) X = alpha B tri Indicates whether upper or lower triangle is used transposeA Is op(A) the transpose of A diag The diagonal (an implied unit diagonal or supplied) M Number of rows N Number of columns lda The leading dimension of the A matrix, either M or N alpha The scalar multiplier for B A A triangular matrix B The matrix of values for the solve Return: The matrix of coefficients to get B The 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 MxN Example: 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_diag STD.BLAS.extract_diag STD.BLAS.extract_diag BLAS.extract_diag extract_diag ( m.n.x); m Number of rows n Number of columns x The matrix from which to extract the diagonal Return: Diagonal matrix The extract_diag function extracts the diagonal of he matrix Example: 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_tri STD.BLAS.extract_tri STD.BLAS.extract_tri BLAS.extract_tri extract_tri ( m, n, tri, dt, a ); m Number of rows n Number of columns tri Indicates whether upper or lower triangle is used dt Use Diagonal.NotUnitTri or Diagonal.UnitTri a The matrix, usually a composite from factoring Return: Triangle The 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_diag STD.BLAS.make_diag STD.BLAS.make_diag BLAS.make_diag make_diag ( m, v, X ); m Number of diagonal entries v Option value, default is 1 X Optional input of diagonal values, multiplied by v Return: A diagonal matrix The 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_vector STD.BLAS.make_vector STD.BLAS.make_vector BLAS.make_vector make_vector ( m, v ); m Number of elements v The values, default is 1 Return: The vector The make_vector function generates a vector of dimension n Example: IMPORT STD; twos_vector := STD.BLAS.make_vector(4, 2); // a vector of [2, 2, 2, 2] trace STD.BLAS.trace STD.BLAS.tracer BLAS.trace trace ( m, n, x ); m Number of rows n Number of columns x The matrix Return: The trace (sum of the diagonal entries) The trace function computes the trace of the input matrix Example: 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