| 5 |
|
* General component matrix operations. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
#include <stdio.h> |
| 8 |
|
#include <stdlib.h> |
| 9 |
|
#include <errno.h> |
| 10 |
|
#include "rtio.h" |
| 139 |
|
|
| 140 |
|
if ((mleft == NULL) | (mright == NULL)) |
| 141 |
|
return(NULL); |
| 143 |
– |
|
| 142 |
|
switch (op) { |
| 143 |
|
case '.': /* concatenate */ |
| 144 |
< |
mres = rmx_multiply(mleft, mright); |
| 144 |
> |
if (mleft->ncomp != mright->ncomp) { |
| 145 |
> |
fputs(inspec, stderr); |
| 146 |
> |
fputs(": # components do not match\n", stderr); |
| 147 |
> |
} else if (mleft->ncols != mright->nrows) { |
| 148 |
> |
fputs(inspec, stderr); |
| 149 |
> |
fputs(": mismatched dimensions\n", |
| 150 |
> |
stderr); |
| 151 |
> |
} else |
| 152 |
> |
mres = rmx_multiply(mleft, mright); |
| 153 |
|
rmx_free(mleft); |
| 154 |
|
rmx_free(mright); |
| 155 |
|
if (mres == NULL) { |
| 156 |
|
fputs(inspec, stderr); |
| 157 |
< |
if (mleft->ncols != mright->nrows) |
| 152 |
< |
fputs(": mismatched dimensions for multiply\n", |
| 153 |
< |
stderr); |
| 154 |
< |
else |
| 155 |
< |
fputs(": concatenation failed\n", stderr); |
| 157 |
> |
fputs(": concatenation failed\n", stderr); |
| 158 |
|
return(NULL); |
| 159 |
|
} |
| 160 |
|
if (verbose) { |
| 231 |
|
int rpos = 0; |
| 232 |
|
/* find end of list */ |
| 233 |
|
while (mop[rpos].binop) |
| 234 |
< |
rpos++; |
| 234 |
> |
if (mop[rpos++].binop != '.') { |
| 235 |
> |
fputs( |
| 236 |
> |
"Right-to-left evaluation only for matrix multiplication!\n", |
| 237 |
> |
stderr); |
| 238 |
> |
return(NULL); |
| 239 |
> |
} |
| 240 |
|
mright = loadop(mop+rpos); |
| 241 |
|
while (rpos-- > 0) { |
| 242 |
|
if (mright == NULL) |
| 320 |
|
int i; |
| 321 |
|
/* get options and arguments */ |
| 322 |
|
for (i = 1; i < argc; i++) { |
| 316 |
– |
if (nmats >= nall) |
| 317 |
– |
mop = grow_moparray(mop, nall += 2); |
| 323 |
|
if (argv[i][0] && !argv[i][1] && |
| 324 |
|
strchr(".+*/", argv[i][0]) != NULL) { |
| 325 |
< |
if (mop[nmats].inspec == NULL || mop[nmats].binop) { |
| 326 |
< |
fprintf(stderr, "%s: missing matrix argument\n", |
| 327 |
< |
argv[0]); |
| 325 |
> |
if (!nmats || mop[nmats-1].binop) { |
| 326 |
> |
fprintf(stderr, |
| 327 |
> |
"%s: missing matrix argument before '%c' operation\n", |
| 328 |
> |
argv[0], argv[i][0]); |
| 329 |
|
return(1); |
| 330 |
|
} |
| 331 |
< |
mop[nmats++].binop = argv[i][0]; |
| 331 |
> |
mop[nmats-1].binop = argv[i][0]; |
| 332 |
|
} else if (argv[i][0] != '-' || !argv[i][1]) { |
| 333 |
|
if (argv[i][0] == '-') { |
| 334 |
|
if (stdin_used++) { |
| 347 |
|
int n = argc-1 - i; |
| 348 |
|
switch (argv[i][1]) { /* get option */ |
| 349 |
|
case 'v': |
| 350 |
< |
verbose = !verbose; |
| 350 |
> |
verbose++; |
| 351 |
|
break; |
| 352 |
|
case 'f': |
| 353 |
|
switch (argv[i][2]) { |
| 388 |
|
goto userr; |
| 389 |
|
} |
| 390 |
|
} |
| 391 |
+ |
if (nmats >= nall) |
| 392 |
+ |
mop = grow_moparray(mop, nall += 2); |
| 393 |
|
} |
| 394 |
|
if (mop[0].inspec == NULL) /* nothing to do? */ |
| 395 |
|
goto userr; |
| 396 |
+ |
if (mop[nmats-1].binop) { |
| 397 |
+ |
fprintf(stderr, |
| 398 |
+ |
"%s: missing matrix argument after '%c' operation\n", |
| 399 |
+ |
argv[0], mop[nmats-1].binop); |
| 400 |
+ |
return(1); |
| 401 |
+ |
} |
| 402 |
|
/* favor quicker concatenation */ |
| 403 |
< |
mres = prefer_right2left(mop) ? op_right2left(mop) : op_left2right(mop); |
| 404 |
< |
if (!mres) |
| 403 |
> |
mop[nmats].mtx = prefer_right2left(mop) ? op_right2left(mop) |
| 404 |
> |
: op_left2right(mop); |
| 405 |
> |
if (mop[nmats].mtx == NULL) |
| 406 |
> |
return(1); |
| 407 |
> |
/* apply trailing unary operations */ |
| 408 |
> |
mop[nmats].inspec = "trailing_ops"; |
| 409 |
> |
mres = loadop(mop+nmats); |
| 410 |
> |
if (mres == NULL) |
| 411 |
|
return(1); |
| 412 |
|
/* write result to stdout */ |
| 413 |
|
if (outfmt == DTfromHeader) |