1 /* ------------------------------------------------------------------------
2 * $Id: matrix.c,v 1.3 2006/01/09 14:32:31 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.
29 Matrix newMat(int rows,int cols, int elsize, void *zero) {
33 res.zero = malloc(elsize);
35 fprintf(stderr,"{newMat} unable to allocate storage\n");
38 memcpy(res.zero,zero,elsize);
45 void freeMat(Matrix *mat) {
46 Matrix_element *tmp_ptr, *ptr=mat->mat;
57 void *_Mat(Matrix *mat,int x, int y,int lineno, char *filename) {
58 Matrix_element *ptr= mat->mat;
59 if (x<0 || x>=mat->rows || y<0 || y>=mat->cols) {
60 fprintf(stderr,"Mat[%d,%d] out of bound index at line %d of \"%s\"\n",
65 if ((x==ptr->x) && (y==ptr->y)) {
71 ptr = (Matrix_element*) malloc(sizeof(Matrix_element));
73 fprintf(stderr,"{_Mat} failed to allocate %zd bytes\n",
74 sizeof(Matrix_element));
77 ptr->data = (void*) malloc(mat->elsize);
78 if (ptr->data==NULL) {
79 fprintf(stderr,"{_Mat} failed to allocate element of size %d bytes\n",
85 memcpy(ptr->data,mat->zero,mat->elsize);
91 int Mat_dense(Matrix mat,int x,int y) {
92 Matrix_element *ptr= mat.mat;
94 if ((x==ptr->x) && (y==ptr->y)) return 1;