/* matdebug.c routines to help debug the mat package.
* © Copyright 1999 by John Halleck
* All rights reserved.
*/
/* Version of August 16th, 1999 */
#include <stdio.h>
/* Standard IO */
#include "errors.h"
/* Common error codes */
#include "mat.h"
/* Matrix specific stuff */
#include "matdebug.h"
/* And interfaces specific to this. */
/* --------------------- Printing ----------------------------------- */
error matprint (char *text, int rows, int cols, matrix toprint) {
double *local;
int i, j;
if (text) printf ("%s\n", text);
if (!toprint) return ERRnil;
if (rows<1 || cols<1) return ERRsize;
local = (double *) toprint;
for (i=0; i<rows; i++) {
printf ("[");
for (j=0; j<cols; j++) {
printf (" %f", *local++);
}
printf (" ]\n");
}
return NoError;
}
error matcprint (char *text, int rows, int cols, matrix one, matrix two) {
double *local1, *local2;
int i, j;
if (text) printf ("%s\n", text);
if (!one || !two) return ERRnil;
if (rows<1 || cols<1) return ERRsize;
local1 = (double *) one; local2 = (double *) two;
for (i=0; i<rows; i++) {
printf ("[");
for (j=0; j<cols; j++) {
printf (" %f", *local1++);
}
printf (" | ");
for (j=0; j<cols; j++) {
printf (" %f", *local2++);
}
printf (" ]\n");
}
return NoError;
}
/* ---------------------- Equality ------------------------------- */
error matiseq (int rows, int cols, matrix a, matrix b) {
double *one, *another; long size;
if (!a || !b) return ERRnil; /* Matrices must exist */
if (rows<1 || cols<1) return ERRsize; /* and have some size */
size = rows*cols; one = (double *) a; another = (double *) b;
while (size--) if (*one++ != *another++) return ERRfalse;
return NoError;
}
/* ----------- "Close enough" ----------------------------------- */
/* Only the matrix form has been done here, if you need the row
* form use mataeq (1, size, row) if you need the column form
* then use mataeq (size, 1, col).
*/
error matisaeq (int rows, int cols, matrix a, matrix b, double fudge) {
double *one, *another; long size;
double diff = 0;
if (!a || !b) return ERRnil; /* Matrices must exist */
if (rows<1 || cols<1) return ERRsize; /* and have some size */
size = rows*cols; one = (double *) a; another = (double *) b;
while (size--) {
diff = *one++ - *another++;
if (diff < 0) diff = -diff;
if (diff > fudge) return ERRfalse;
}
return NoError;
}
This page is http://www.cc.utah.edu/~nahaj/cave/survey/code/c/matdebug.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 11th, 2000