## File: BLAS-Examples.html

package info (click to toggle)
gsl-ref-html 2.3-1
• area: non-free
• in suites: bullseye, buster, sid
• size: 6,876 kB
• ctags: 4,574
• sloc: makefile: 35
 file content (131 lines) | stat: -rw-r--r-- 5,043 bytes parent folder | download
 `123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131` `````` GNU Scientific Library – Reference Manual: BLAS Examples

13.2 Examples

The following program computes the product of two matrices using the Level-3 BLAS function DGEMM,

[ 0.11 0.12 0.13 ]  [ 1011 1012 ]     [ 367.76 368.12 ] [ 0.21 0.22 0.23 ]  [ 1021 1022 ]  =  [ 674.06 674.72 ]                     [ 1031 1032 ]

The matrices are stored in row major order, according to the C convention for arrays.

#include <stdio.h> #include <gsl/gsl_blas.h>  int main (void) {   double a[] = { 0.11, 0.12, 0.13,                  0.21, 0.22, 0.23 };    double b[] = { 1011, 1012,                  1021, 1022,                  1031, 1032 };    double c[] = { 0.00, 0.00,                  0.00, 0.00 };    gsl_matrix_view A = gsl_matrix_view_array(a, 2, 3);   gsl_matrix_view B = gsl_matrix_view_array(b, 3, 2);   gsl_matrix_view C = gsl_matrix_view_array(c, 2, 2);    /* Compute C = A B */    gsl_blas_dgemm (CblasNoTrans, CblasNoTrans,                   1.0, &A.matrix, &B.matrix,                   0.0, &C.matrix);    printf ("[ %g, %g\n", c[0], c[1]);   printf ("  %g, %g ]\n", c[2], c[3]);    return 0;   }

Here is the output from the program,

\$ ./a.out
[ 367.76, 368.12   674.06, 674.72 ]
``````