Annotation of OpenXM_contrib2/asir2000/builtin/mattran.c, Revision 1.2
1.2 ! saito 1: /*
! 2: * $OpenXM$
! 3: */
! 4:
1.1 saito 5: #include "ca.h"
6: #include "parse.h"
7:
1.2 ! saito 8: static void MatFund(NODE, Obj *);
! 9: static void RowMul(NODE, Obj *);
! 10: static void RowExh(NODE, Obj *);
! 11: static void RowMulAdd(NODE, Obj *);
! 12: static void BodyRowMul(MAT, int, pointer);
! 13: static void BodyRowExh(MAT, int, int);
! 14: static void BodyRowMulAdd(MAT, int, int, pointer);
! 15: static void ColMul(NODE, Obj *);
! 16: static void ColExh(NODE, Obj *);
! 17: static void ColMulAdd(NODE, Obj *);
! 18: static void BodyColMul(MAT, int, pointer);
! 19: static void BodyColExh(MAT, int, int);
! 20: static void BodyColMulAdd(MAT, int, int, pointer);
1.1 saito 21:
22: struct ftab mat_tab[] = {
1.2 ! saito 23: {"mfund",MatFund,-5},
! 24: {"rowm",RowMul,3},
! 25: {"rowx",RowExh,3},
! 26: {"rowa",RowMulAdd,4},
! 27: {"colm",ColMul,3},
! 28: {"colx",ColExh,3},
! 29: {"cola",ColMulAdd,4},
1.1 saito 30: {0,0,0},
31: };
32:
33: static void
1.2 ! saito 34: MatFund(arg, rp)
! 35: NODE arg;
! 36: Obj *rp;
! 37: {
! 38: MAT mat;
! 39: pointer *coe;
! 40: Q rowq, row2q, colq, col2q;
! 41: int sw, row, row2, col, col2;
! 42: sw = QTOS( (Q)ARG0(arg) );
! 43: mat = (MAT)ARG1(arg);
! 44: switch (sw) {
! 45: case 1:
! 46: rowq = (Q)ARG2(arg);
! 47: row = QTOS( rowq );
! 48: coe = (pointer)ARG3(arg);
! 49: BodyRowMul( mat, row, coe );
! 50: *rp = (Obj)mat;
! 51: return;
! 52: case 2:
! 53: rowq = (Q)ARG2(arg);
! 54: row = QTOS( rowq );
! 55: row2q = (Q)ARG3(arg);
! 56: row2 = QTOS( row2q );
! 57: BodyRowExh( mat, row, row2 );
! 58: *rp = (Obj)mat;
! 59: return;
! 60: case 3:
! 61: rowq = (Q)ARG2(arg);
! 62: row = QTOS( rowq );
! 63: row2q = (Q)ARG3(arg);
! 64: row2 = QTOS( row2q );
! 65: coe = (pointer)ARG3(arg);
! 66: BodyRowMulAdd( mat, row, row2, coe );
! 67: *rp = (Obj)mat;
! 68: return;
! 69: case 4:
! 70: colq = (Q)ARG2(arg);
! 71: col = QTOS( colq );
! 72: coe = (pointer)ARG3(arg);
! 73: BodyColMul( mat, col, coe );
! 74: *rp = (Obj)mat;
! 75: return;
! 76: case 5:
! 77: colq = (Q)ARG2(arg);
! 78: col = QTOS( colq );
! 79: col2q = (Q)ARG3(arg);
! 80: col2 = QTOS( col2q );
! 81: BodyColExh( mat, col, col2 );
! 82: *rp = (Obj)mat;
! 83: return;
! 84: case 6:
! 85: colq = (Q)ARG2(arg);
! 86: col = QTOS( colq );
! 87: col2q = (Q)ARG3(arg);
! 88: col2 = QTOS( col2q );
! 89: coe = (pointer)ARG3(arg);
! 90: BodyColMulAdd( mat, col, col2, coe );
! 91: *rp = (Obj)mat;
! 92: default:
! 93: return;
! 94: *rp = 0;
! 95: }
! 96: }
! 97:
! 98: static void
! 99: RowMul(arg, rp)
! 100: NODE arg;
! 101: Obj *rp;
! 102: {
! 103: MAT mat;
! 104: Q rowq;
! 105: pointer *coe;
! 106: int row;
! 107:
! 108: mat = (MAT)ARG0(arg);
! 109: rowq = (Q)ARG1(arg);
! 110: row = QTOS( rowq );
! 111: coe = (pointer)ARG2(arg);
! 112: BodyRowMul( mat, row , coe );
! 113: *rp = (Obj)mat;
! 114: }
! 115:
! 116: static void
! 117: RowExh(arg, rp)
! 118: NODE arg;
! 119: Obj *rp;
! 120: {
! 121: MAT mat;
! 122: Q QIndexA, QIndexB;
! 123: int IndexA, IndexB;
! 124:
! 125: mat = (MAT)ARG0(arg);
! 126: QIndexA = (Q)ARG1(arg);
! 127: QIndexB = (Q)ARG2(arg);
! 128: IndexA = QTOS( QIndexA );
! 129: IndexB = QTOS( QIndexB );
! 130: BodyRowExh( mat, IndexA, IndexB );
! 131: *rp = (Obj)mat;
! 132: }
! 133:
! 134: static void
! 135: RowMulAdd(arg, rp)
1.1 saito 136: NODE arg;
137: Obj *rp;
138: {
1.2 ! saito 139: MAT mat;
! 140: Q QIndexA, QIndexB;
! 141: int IndexA, IndexB;
! 142: pointer *coe;
! 143:
! 144: mat = (MAT)ARG0(arg);
! 145: QIndexA = (Q)ARG1(arg);
! 146: QIndexB = (Q)ARG2(arg);
! 147: coe = (pointer)ARG3(arg);
! 148: IndexA = QTOS( QIndexA );
! 149: IndexB = QTOS( QIndexB );
! 150: BodyRowMulAdd( mat, IndexA, IndexB, coe );
! 151: *rp = (Obj)mat;
! 152: }
1.1 saito 153:
1.2 ! saito 154: static void
! 155: ColMul(arg, rp)
! 156: NODE arg;
! 157: Obj *rp;
! 158: {
! 159: MAT mat;
! 160: Q QIndex;
! 161: pointer *coe;
! 162: int Index;
! 163:
! 164: mat = (MAT)ARG0(arg);
! 165: QIndex = (Q)ARG1(arg);
! 166: Index = QTOS( QIndex );
! 167: coe = (pointer)ARG2(arg);
! 168: BodyColMul( mat, Index , coe );
! 169: *rp = (Obj)mat;
! 170: }
1.1 saito 171:
1.2 ! saito 172: static void
! 173: ColExh(arg, rp)
! 174: NODE arg;
! 175: Obj *rp;
! 176: {
! 177: MAT mat;
! 178: Q QIndexA, QIndexB;
! 179: int IndexA, IndexB;
! 180:
! 181: mat = (MAT)ARG0(arg);
! 182: QIndexA = (Q)ARG1(arg);
! 183: QIndexB = (Q)ARG2(arg);
! 184: IndexA = QTOS( QIndexA );
! 185: IndexB = QTOS( QIndexB );
! 186: BodyColExh( mat, IndexA, IndexB );
! 187: *rp = (Obj)mat;
1.1 saito 188: }
189:
190: static void
1.2 ! saito 191: ColMulAdd(arg, rp)
1.1 saito 192: NODE arg;
193: Obj *rp;
194: {
1.2 ! saito 195: MAT mat;
! 196: Q QIndexA, QIndexB;
! 197: int IndexA, IndexB;
! 198: pointer *coe;
! 199:
! 200: mat = (MAT)ARG0(arg);
! 201: QIndexA = (Q)ARG1(arg);
! 202: QIndexB = (Q)ARG2(arg);
! 203: coe = (pointer)ARG3(arg);
! 204: IndexA = QTOS( QIndexA );
! 205: IndexB = QTOS( QIndexB );
! 206: BodyColMulAdd( mat, IndexA, IndexB, coe );
! 207: *rp = (Obj)mat;
! 208: }
! 209:
! 210: static void
! 211: BodyRowMul( mat, row, coe )
! 212: MAT mat;
! 213: int row;
! 214: pointer coe;
! 215: {
! 216: int size, i;
! 217: pointer *t, *matrow;
! 218:
! 219: size = mat->col;
! 220: matrow = BDY(mat)[row];
! 221: for ( i = 0; i < size; i++ ) {
! 222: mulr(CO,(Obj)matrow[i],(Obj)coe,(Obj *)&t);
! 223: matrow[i]=(Obj)t;
! 224: }
! 225: }
1.1 saito 226:
1.2 ! saito 227: static void
! 228: BodyRowExh( mat, IndexA, IndexB )
! 229: MAT mat;
! 230: int IndexA, IndexB;
! 231: {
! 232: int i, size;
! 233: pointer *t, *PRowA, *PRowB;
! 234:
! 235: size = mat->col;
! 236: PRowA = BDY(mat)[IndexA];
! 237: PRowB = BDY(mat)[IndexB];
1.1 saito 238: for ( i = 0; i < size; i++ ) {
1.2 ! saito 239: t = PRowA[i];
! 240: PRowA[i] = PRowB[i];
! 241: PRowB[i] = t;
1.1 saito 242: }
1.2 ! saito 243: }
! 244:
! 245: static void
! 246: BodyRowMulAdd( mat, IndexA, IndexB, coe )
! 247: MAT mat;
! 248: int IndexA, IndexB;
! 249: pointer coe;
! 250: {
! 251: int i, size;
! 252: pointer *t, *PRowA, *PRowB;
! 253:
! 254: size = mat->col;
! 255: PRowA = BDY(mat)[IndexA];
! 256: PRowB = BDY(mat)[IndexB];
1.1 saito 257:
1.2 ! saito 258: for ( i = 0; i < size; i++ ) {
! 259: mulr( CO, (Obj)PRowB[i], (Obj)coe, (Obj *)&t );
! 260: addr( CO, (Obj)PRowA[i], (Obj)t, (Obj *)&t );
! 261: PRowA[i] = t;
! 262: }
1.1 saito 263: }
264:
265: static void
1.2 ! saito 266: BodyColMul( mat, Index, coe )
! 267: MAT mat;
! 268: int Index;
! 269: pointer coe;
1.1 saito 270: {
1.2 ! saito 271: int size, i;
! 272:
! 273: size = mat->row;
! 274: for ( i = 0; i < size; i++ ) {
! 275: mulr(CO, BDY(mat)[i][Index], (Obj)coe, (Obj *)&BDY(mat)[i][Index]);
! 276: }
! 277: }
1.1 saito 278:
1.2 ! saito 279: static void
! 280: BodyColExh( mat, IndexA, IndexB )
! 281: MAT mat;
! 282: int IndexA, IndexB;
! 283: {
! 284: int i, size;
! 285: pointer *t;
1.1 saito 286:
1.2 ! saito 287: size = mat->row;
1.1 saito 288: for ( i = 0; i < size; i++ ) {
1.2 ! saito 289: t = BDY(mat)[i][IndexA];
! 290: BDY(mat)[i][IndexA] = BDY(mat)[i][IndexB];
! 291: BDY(mat)[i][IndexB] = t;
1.1 saito 292: }
1.2 ! saito 293: }
! 294:
! 295: static void
! 296: BodyColMulAdd( mat, IndexA, IndexB, coe )
! 297: MAT mat;
! 298: int IndexA, IndexB;
! 299: pointer coe;
! 300: {
! 301: int i, size;
! 302: pointer *t;
1.1 saito 303:
1.2 ! saito 304: size = mat->row;
! 305: for ( i = 0; i < size; i++ ) {
! 306: mulr( CO, BDY(mat)[i][IndexB], coe, (Obj *)&t );
! 307: addr( CO, BDY(mat)[i][IndexA], (Obj)t, (Obj *)&BDY(mat)[i][IndexA]);
! 308: }
1.1 saito 309: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>