Annotation of OpenXM_contrib2/asir2018/builtin/mattran.c, Revision 1.2
1.1 noro 1: /*
1.2 ! noro 2: * $OpenXM: OpenXM_contrib2/asir2018/builtin/mattran.c,v 1.1 2018/09/19 05:45:06 noro Exp $
1.1 noro 3: */
4:
5: #include "ca.h"
6: #include "parse.h"
7:
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);
21:
22: struct ftab mat_tab[] = {
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},
30: {0,0,0},
31: };
32:
33: static void
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;
1.2 ! noro 42: sw = ZTOS( (Q)ARG0(arg) );
1.1 noro 43: mat = (MAT)ARG1(arg);
44: switch (sw) {
45: case 1:
46: rowq = (Q)ARG2(arg);
1.2 ! noro 47: row = ZTOS( rowq );
1.1 noro 48: coe = (pointer)ARG3(arg);
49: BodyRowMul( mat, row, coe );
50: *rp = (Obj)mat;
51: return;
52: case 2:
53: rowq = (Q)ARG2(arg);
1.2 ! noro 54: row = ZTOS( rowq );
1.1 noro 55: row2q = (Q)ARG3(arg);
1.2 ! noro 56: row2 = ZTOS( row2q );
1.1 noro 57: BodyRowExh( mat, row, row2 );
58: *rp = (Obj)mat;
59: return;
60: case 3:
61: rowq = (Q)ARG2(arg);
1.2 ! noro 62: row = ZTOS( rowq );
1.1 noro 63: row2q = (Q)ARG3(arg);
1.2 ! noro 64: row2 = ZTOS( row2q );
1.1 noro 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);
1.2 ! noro 71: col = ZTOS( colq );
1.1 noro 72: coe = (pointer)ARG3(arg);
73: BodyColMul( mat, col, coe );
74: *rp = (Obj)mat;
75: return;
76: case 5:
77: colq = (Q)ARG2(arg);
1.2 ! noro 78: col = ZTOS( colq );
1.1 noro 79: col2q = (Q)ARG3(arg);
1.2 ! noro 80: col2 = ZTOS( col2q );
1.1 noro 81: BodyColExh( mat, col, col2 );
82: *rp = (Obj)mat;
83: return;
84: case 6:
85: colq = (Q)ARG2(arg);
1.2 ! noro 86: col = ZTOS( colq );
1.1 noro 87: col2q = (Q)ARG3(arg);
1.2 ! noro 88: col2 = ZTOS( col2q );
1.1 noro 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);
1.2 ! noro 110: row = ZTOS( rowq );
1.1 noro 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);
1.2 ! noro 128: IndexA = ZTOS( QIndexA );
! 129: IndexB = ZTOS( QIndexB );
1.1 noro 130: BodyRowExh( mat, IndexA, IndexB );
131: *rp = (Obj)mat;
132: }
133:
134: static void
135: RowMulAdd(arg, rp)
136: NODE arg;
137: Obj *rp;
138: {
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);
1.2 ! noro 148: IndexA = ZTOS( QIndexA );
! 149: IndexB = ZTOS( QIndexB );
1.1 noro 150: BodyRowMulAdd( mat, IndexA, IndexB, coe );
151: *rp = (Obj)mat;
152: }
153:
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);
1.2 ! noro 166: Index = ZTOS( QIndex );
1.1 noro 167: coe = (pointer)ARG2(arg);
168: BodyColMul( mat, Index , coe );
169: *rp = (Obj)mat;
170: }
171:
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);
1.2 ! noro 184: IndexA = ZTOS( QIndexA );
! 185: IndexB = ZTOS( QIndexB );
1.1 noro 186: BodyColExh( mat, IndexA, IndexB );
187: *rp = (Obj)mat;
188: }
189:
190: static void
191: ColMulAdd(arg, rp)
192: NODE arg;
193: Obj *rp;
194: {
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);
1.2 ! noro 204: IndexA = ZTOS( QIndexA );
! 205: IndexB = ZTOS( QIndexB );
1.1 noro 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: }
226:
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];
238: for ( i = 0; i < size; i++ ) {
239: t = PRowA[i];
240: PRowA[i] = PRowB[i];
241: PRowB[i] = t;
242: }
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];
257:
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: }
263: }
264:
265: static void
266: BodyColMul( mat, Index, coe )
267: MAT mat;
268: int Index;
269: pointer coe;
270: {
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: }
278:
279: static void
280: BodyColExh( mat, IndexA, IndexB )
281: MAT mat;
282: int IndexA, IndexB;
283: {
284: int i, size;
285: pointer *t;
286:
287: size = mat->row;
288: for ( i = 0; i < size; i++ ) {
289: t = BDY(mat)[i][IndexA];
290: BDY(mat)[i][IndexA] = BDY(mat)[i][IndexB];
291: BDY(mat)[i][IndexB] = t;
292: }
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;
303:
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: }
309: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>