RE: Math.Matrix

郭雪松 <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <[email protected]>
Use attached patch to fix it.

Guo Xue Song


From: [email protected]
To: [email protected]; [email protected]
Subject: RE: Math.Matrix
Date: Wed, 19 Aug 2015 21:20:33 +0800




Has anybody reviewed and fixed this ?

Guo Xue Song


> To: [email protected]
> Subject: Re: Math.Matrix
> From: [email protected]
> Date: Mon, 15 Apr 2013 17:15:02 +0000
> 
> Yes, 
> 
> a*b 
> 
> is equivalent (at least in this case) to
> 
> a->`*(b)
> 
> (but if a doesn't support that, b->``*(a) )
>
Pike-v7.9.5-fix-matrix.patch (application/octet-stream, 1.6 KB)
--- Pike-v7.9.5/src/modules/Math/matrix_code.h	2014-07-03 07:20:15.000000000 +0800
+++ Pike-v7.9.5-fix-matrix/src/modules/Math/matrix_code.h	2015-08-20 00:45:35.138809650 +0800
@@ -687,26 +687,36 @@
 	  get_storage(Pike_sp[-1].u.object,XmatrixY(math_,_program)))))
       SIMPLE_BAD_ARG_ERROR("`*",1,"object(Math.Matrix)");
 
-   if (mx->xsize != THIS->ysize)
+   if (mx->ysize != THIS->xsize)
       math_error("`*",Pike_sp-args,args,0,
 		 "Incompatible matrices.\n");
 
-   m=THIS->xsize;
-   n=THIS->ysize; /* == mx->xsize */
-   p=mx->ysize;
+	 /* A*B=C A(m row n col) B(n row p col) C(m row p col)*/
+	 /* m row: ysize=m */
+	 /* n col: xsize=n */
+
+   m=THIS->ysize;
+   n=THIS->xsize; /* == mx->xsize */
+   p=mx->xsize;
+
+	 /*fprintf(stderr,"m=%d\n",m);
+	 fprintf(stderr,"n=%d\n",n);
+	 fprintf(stderr,"p=%d\n",p);*/
 
    dmx=matrixX(_push_new_)(p,m);
 
-   s1=mx->m;
-   s2=THIS->m;
+   s2=mx->m;
+   s1=THIS->m;
    d=dmx->m;
    for (k=0; k<p; k++)
       for (i=0; i<m; i++)
       {
 	 z=(FTYPE)0;
 	 st=s2+k*n;
-	 for (j=i; j<i+m*n; j+=m)
-	    z += s1[ j ] * *(st++);
+	 for (j=i; j<i+m*n; j+=m){
+			//fprintf(stderr,"%f * %f\n",(double)(s1[ j ]),(double)(*st));
+			z += s1[ j ] * *(st++);
+	 }
 	 *(d++)=z;
       }
 
@@ -1012,8 +1022,8 @@
 		tFunc(tOr3(tObj,tFloat,tInt), tObj), 0);
    ADD_FUNCTION("`*",matrixX(_mult),
 		tFunc(tOr3(tObj,tFloat,tInt), tObj), 0);
-   ADD_FUNCTION("``*",matrixX(_mult),
-		tFunc(tOr3(tObj,tFloat,tInt), tObj), 0);
+   //ADD_FUNCTION("``*",matrixX(_mult),
+		//tFunc(tOr3(tObj,tFloat,tInt), tObj), 0);
 
    ADD_FUNCTION("dot_product",matrixX(_dot), tFunc(tObj, tObj), 0);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.