This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: matrix multiplication


try to use level 3 of blas.
gsl supports blas interfaces. A simple example is attatched. gsl_gemm.c
LDFLAGS=-lgsl -lgslcblas -lm
yours
Dan, Ho-Jin

Matthew J. Doller wrote:

>someone correct me if i am wrong, but is there really no way of
>multiplying two matrices, or a matrix and a vector with gsl
>i know i can go element by element, but i'm looking for something of the
>form:
>
>return_matrix = gsl_matrix_mul_matrix_by_matrix ( matrix_one ,
>matrix_two );
>
>thanks!
>matt
>


#include <stdio.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>

int main()
{
  double A[] = { 
    1., 2., 
    3., 4. 
  };
  double B[] = {
    2., 3.,
    4., 5.
  };
  double alpha = 1., beta = 0.;

  gsl_matrix_view A_m = gsl_matrix_view_array(A, 2, 2);
  gsl_matrix_view B_m = gsl_matrix_view_array(B, 2, 2);
  gsl_matrix *C = gsl_matrix_alloc(2,2);

  gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, alpha, &A_m.matrix, 
      &B_m.matrix, beta, C);

  printf("[[\n%f\t%f\n%f\t%f]]\n", 
      gsl_matrix_get(C, 0, 0), gsl_matrix_get(C, 0, 1), 
      gsl_matrix_get(C, 1, 0), gsl_matrix_get(C, 1, 1));

  gsl_matrix_free(C);
  return 0;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]