=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/engine/mat.c,v retrieving revision 1.5 retrieving revision 1.10 diff -u -p -r1.5 -r1.10 --- OpenXM_contrib2/asir2000/engine/mat.c 2002/03/01 06:27:23 1.5 +++ OpenXM_contrib2/asir2000/engine/mat.c 2003/05/22 07:01:40 1.10 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/engine/mat.c,v 1.4 2002/01/04 17:08:23 saito Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/engine/mat.c,v 1.9 2003/05/20 07:19:41 noro Exp $ */ #include "ca.h" #include "../parse/parse.h" @@ -72,7 +72,7 @@ MAT a,b,*c; for ( i = 0; i < row; i++ ) for ( j = 0, ab = BDY(a)[i], bb = BDY(b)[i], tb = BDY(t)[i]; j < col; j++ ) - addr(vl,(Obj)ab[j],(Obj)bb[j],(Obj *)&tb[j]); + arf_add(vl,(Obj)ab[j],(Obj)bb[j],(Obj *)&tb[j]); *c = t; } } @@ -97,7 +97,7 @@ MAT a,b,*c; for ( i = 0; i < row; i++ ) for ( j = 0, ab = BDY(a)[i], bb = BDY(b)[i], tb = BDY(t)[i]; j < col; j++ ) - subr(vl,(Obj)ab[j],(Obj)bb[j],(Obj *)&tb[j]); + arf_sub(vl,(Obj)ab[j],(Obj)bb[j],(Obj *)&tb[j]); *c = t; } } @@ -106,11 +106,30 @@ void mulmat(vl,a,b,c) VL vl; Obj a,b,*c; { - if ( !a || !b ) + VECT vect; + MAT mat; + + if ( !a && !b ) *c = 0; - else if ( OID(a) <= O_R ) + else if ( !a || !b ) { + if ( !a ) + a = b; + switch ( OID(a) ) { + case O_VECT: + MKVECT(vect,((VECT)a)->len); + *c = (Obj)vect; + break; + case O_MAT: + MKMAT(mat,((MAT)a)->row,((MAT)a)->col); + *c = (Obj)mat; + break; + default: + *c = 0; + break; + } + } else if ( OID(a) <= O_R || OID(a) == O_DP ) mulrmat(vl,(Obj)a,(MAT)b,(MAT *)c); - else if ( OID(b) <= O_R ) + else if ( OID(b) <= O_R || OID(b) == O_DP ) mulrmat(vl,(Obj)b,(MAT)a,(MAT *)c); else switch ( OID(a) ) { @@ -150,7 +169,7 @@ Obj a,b,*c; else if ( OID(b) > O_R ) notdef(vl,a,b,c); else { - divr(vl,(Obj)ONE,b,&t); mulrmat(vl,t,(MAT)a,(MAT *)c); + arf_div(vl,(Obj)ONE,b,&t); mulrmat(vl,t,(MAT)a,(MAT *)c); } } @@ -169,7 +188,7 @@ MAT a,*b; for ( i = 0; i < row; i++ ) for ( j = 0, ab = BDY(a)[i], tb = BDY(t)[i]; j < col; j++ ) - chsgnr((Obj)ab[j],(Obj *)&tb[j]); + arf_chsgn((Obj)ab[j],(Obj *)&tb[j]); *b = t; } } @@ -180,9 +199,22 @@ MAT a; Obj r; MAT *c; { + int n,i; + MAT t; + if ( !a ) *c = 0; - else if ( !r || !NUM(r) || !RATN(r) || + else if ( !r ) { + if ( a->row != a->col ) { + *c = 0; error("pwrmat : non square matrix"); + } else { + n = a->row; + MKMAT(t,n,n); + for ( i = 0; i < n; i++ ) + t->body[i][i] = ONE; + *c = t; + } + } else if ( !NUM(r) || !RATN(r) || !INT(r) || (SGN((Q)r)<0) || (PL(NM((Q)r))>1) ) { *c = 0; error("pwrmat : invalid exponent"); } else if ( a->row != a->col ) { @@ -229,7 +261,7 @@ MAT b,*c; for ( i = 0; i < row; i++ ) for ( j = 0, bb = BDY(b)[i], tb = BDY(t)[i]; j < col; j++ ) - mulr(vl,(Obj)a,(Obj)bb[j],(Obj *)&tb[j]); + arf_mul(vl,(Obj)a,(Obj)bb[j],(Obj *)&tb[j]); *c = t; } } @@ -253,8 +285,8 @@ MAT a,b,*c; for ( i = 0; i < arow; i++ ) for ( j = 0, ab = BDY(a)[i], tb = BDY(t)[i]; j < bcol; j++ ) { for ( k = 0, s = 0; k < m; k++ ) { - mulr(vl,(Obj)ab[k],(Obj)BDY(b)[k][j],(Obj *)&u); - addr(vl,(Obj)s,(Obj)u,(Obj *)&v); + arf_mul(vl,(Obj)ab[k],(Obj)BDY(b)[k][j],(Obj *)&u); + arf_add(vl,(Obj)s,(Obj)u,(Obj *)&v); s = v; } tb[j] = s; @@ -307,8 +339,8 @@ MAT a,b,*c; for ( i = 0; i < arow; i++ ) for ( j = 0, ab = BDY(a)[i], tb = BDY(t)[i]; j < bcol; j++ ) { for ( k = 0, s = 0; k < m; k++ ) { - mulr(vl,(Obj)ab[k],(Obj)BDY(b)[k][j],(Obj *)&u); - addr(vl,(Obj)s,(Obj)u,(Obj *)&v); + arf_mul(vl,(Obj)ab[k],(Obj)BDY(b)[k][j],(Obj *)&u); + arf_add(vl,(Obj)s,(Obj)u,(Obj *)&v); s = v; } tb[j] = s; @@ -455,6 +487,34 @@ MAT a,b,*c; /* C21 = w1+u1+A22*(B21-t2) */ submat(vl, b21, t2, &ans1); mulmatmat(vl, a22, ans1, &ans2); + addmat(vl, w1, u1, &ans1); + addmat(vl, ans1, ans2, &c21); + + /* C22 = w1 + u1 + v1 */ + addmat(vl, ans1, v1, &c22); + } + + for(i =0; irow; i++) { + for ( j=0; j < c11->col; j++) { + t->body[i][j] = c11->body[i][j]; + } + } + if (pflag1 == 0) { + k = c21->row; + } else { + k = c21->row - 1; + } + for(i =0; icol; j++) { + t->body[i+c11->row][j] = c21->body[i][j]; + } + } + if (pflag2 == 0) { + h = c12->col; + } else { + h = c12->col -1; + } + for(i =0; irow; i++) { for ( j=0; j < k; j++) { t->body[i][j+c11->col] = c12->body[i][j]; } @@ -495,11 +555,14 @@ VECT *c; else if ( a->col != b->len ) { *c = 0; error("mulmatvect : size mismatch"); } else { + for ( i = 0; i < b->len; i++ ) + if ( BDY(b)[i] && OID((Obj)BDY(b)[i]) > O_R ) + error("mulmatvect : invalid argument"); arow = a->row; m = a->col; MKVECT(t,arow); for ( i = 0; i < arow; i++ ) { for ( j = 0, s = 0, ab = BDY(a)[i]; j < m; j++ ) { - mulr(vl,(Obj)ab[j],(Obj)BDY(b)[j],(Obj *)&u); addr(vl,(Obj)s,(Obj)u,(Obj *)&v); s = v; + arf_mul(vl,(Obj)ab[j],(Obj)BDY(b)[j],(Obj *)&u); arf_add(vl,(Obj)s,(Obj)u,(Obj *)&v); s = v; } BDY(t)[i] = s; } @@ -522,11 +585,14 @@ VECT *c; else if ( a->len != b->row ) { *c = 0; error("mulvectmat : size mismatch"); } else { + for ( i = 0; i < a->len; i++ ) + if ( BDY(a)[i] && OID((Obj)BDY(a)[i]) > O_R ) + error("mulvectmat : invalid argument"); bcol = b->col; m = a->len; MKVECT(t,bcol); for ( j = 0; j < bcol; j++ ) { for ( i = 0, s = 0; i < m; i++ ) { - mulr(vl,(Obj)BDY(a)[i],(Obj)BDY(b)[i][j],(Obj *)&u); addr(vl,(Obj)s,(Obj)u,(Obj *)&v); s = v; + arf_mul(vl,(Obj)BDY(a)[i],(Obj)BDY(b)[i][j],(Obj *)&u); arf_add(vl,(Obj)s,(Obj)u,(Obj *)&v); s = v; } BDY(t)[j] = s; } @@ -552,7 +618,7 @@ MAT a,b; row = a->row; col = a->col; for ( i = 0; i < row; i++ ) for ( j = 0; j < col; j++ ) - if ( t = compr(vl,(Obj)BDY(a)[i][j],(Obj)BDY(b)[i][j]) ) + if ( t = arf_comp(vl,(Obj)BDY(a)[i][j],(Obj)BDY(b)[i][j]) ) return t; return 0; }