intmatmul.c

Go to the documentation of this file.
00001 #include "stack-c.h"
00002 
00003 /*--------------------------------------------------------
00004  * intmatmul: interface for matmul C-function 
00005  *     should provide C=matmul(A,B) at Scilab level 
00006  *--------------------------------------------------------*/
00007 
00008 void matmul __PARAMS((double *a, int n, int m, double *b, int l, double *c));
00009 
00010 int intmatmul(fname) 
00011      char *fname;
00012 {
00013   static int l1, m1, n1, l2, m2, n2, l3;
00014   static int minlhs=1, maxlhs=1, minrhs=2, maxrhs=2;
00015 
00016   /* Check number of inputs (rhs=2) and outputs (lhs=1) */
00017   CheckRhs(minrhs,maxrhs) ;
00018   CheckLhs(minlhs,maxlhs) ;
00019 
00020   /* Get A (#1) and B (#2) and create C (#3) as double ("d") matrices */
00021   GetRhsVar(1, "d", &m1, &n1, &l1);   /* m1, n1 (and l1) are output parameters */
00022   GetRhsVar(2, "d", &m2, &n2, &l2);   /* m1, n1 (and l1) are output parameters */
00023   CreateVar(3, "d", &m1, &n2, &l3);   /* m1 and n2 are input parameters */
00024 
00025   /* Check dimensions    */
00026   if (!(n1==m2)) { sciprint("%s: Incompatible inputs \r\n", "matmul");
00027     Error(999);
00028     return 0;}
00029 
00030   /* Call multiplication function 
00031    * inputs:stk(l1)->A, stk(l2)->B 
00032    *  output:stk(l3)->C               
00033    */
00034   matmul(stk(l1), m1, n1, stk(l2), n2, stk(l3));
00035 
00036   /*  Return C (3)  */
00037   LhsVar(1) = 3;
00038   return 0;
00039 }
00040 
00041 /*--------------------------------------------------------
00042  *  Matrix multiplication C= A*B, (A,B,C stored columnwise) 
00043  *  C function
00044  *--------------------------------------------------------*/
00045 
00046 
00047 #define A(i,k) a[i + k*n]
00048 #define B(k,j) b[k + j*m]
00049 #define C(i,j) c[i + j*n]
00050 
00051 void matmul(a,n,m,b,l,c)
00052      double a[],b[],c[];
00053      int n,m,l;
00054 {
00055   int i,j,k;
00056   double s;
00057   for( i=0 ; i < n; i++){
00058     for( j=0; j < l; j++){
00059       s = 0.;
00060       for( k=0; k< m; k++){
00061         s += A(i,k)*B(k,j);
00062       }
00063       C(i,j) = s;
00064     }
00065   }
00066 }
00067 
00068 
00069 
00070 
00071 

Generated on Sun Mar 4 15:03:57 2007 for Scilab [trunk] by  doxygen 1.5.1