1 /* ------------------------------------------------------------------------
2 * $Id: matrix.c,v 1.1 2000/04/05 10:06:36 simonmar Exp $
4 * Copyright (C) 1995-2000 University of Oxford
6 * Permission to use, copy, modify, and distribute this software,
7 * and to incorporate it, in whole or in part, into other software,
8 * is hereby granted without fee, provided that
9 * (1) the above copyright notice and this permission notice appear in
10 * all copies of the source code, and the above copyright notice
11 * appear in clearly visible form on all supporting documentation
12 * and distribution media;
13 * (2) modified versions of this software be accompanied by a complete
14 * change history describing author, date, and modifications made;
16 * (3) any redistribution of the software, in original or modified
17 * form, be without fee and subject to these same conditions.
18 * --------------------------------------------------------------------- */
20 /* Not very clever sparse representation of a matrix. However, it will do
21 * for the call graph profiler.
28 Matrix newMat(int rows,int cols, int elsize, void *zero) {
32 res.zero = malloc(elsize);
34 fprintf(stderr,"{newMat} unable to allocate storage\n");
37 memcpy(res.zero,zero,elsize);
44 void freeMat(Matrix *mat) {
45 Matrix_element *tmp_ptr, *ptr=mat->mat;
56 void *_Mat(Matrix *mat,int x, int y,int lineno, char *filename) {
57 Matrix_element *ptr= mat->mat;
58 if (x<0 || x>=mat->rows || y<0 || y>=mat->cols) {
59 fprintf(stderr,"Mat[%d,%d] out of bound index at line %d of \"%s\"\n",
64 if ((x==ptr->x) && (y==ptr->y)) {
70 ptr = (Matrix_element*) malloc(sizeof(Matrix_element));
72 fprintf(stderr,"{_Mat} failed to allocate %d bytes\n",
73 sizeof(Matrix_element));
76 ptr->data = (void*) malloc(mat->elsize);
77 if (ptr->data==NULL) {
78 fprintf(stderr,"{_Mat} failed to allocate element of size %d bytes\n",
84 memcpy(ptr->data,mat->zero,mat->elsize);
90 int Mat_dense(Matrix mat,int x,int y) {
91 Matrix_element *ptr= mat.mat;
93 if ((x==ptr->x) && (y==ptr->y)) return 1;