sparse-matrix.h
Go to the documentation of this file.
00001 /* sparse-matrix.h 
00002 
00003    Header file for sparse-matrix.c.
00004 
00005   *****
00006   Copyright 1994-1997, Brown University
00007   Copyright 1998, 1999, Anthony R. Cassandra
00008 
00009                            All Rights Reserved
00010                            
00011   Permission to use, copy, modify, and distribute this software and its
00012   documentation for any purpose other than its incorporation into a
00013   commercial product is hereby granted without fee, provided that the
00014   above copyright notice appear in all copies and that both that
00015   copyright notice and this permission notice appear in supporting
00016   documentation.
00017   
00018   ANTHONY CASSANDRA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00019   INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00020   PARTICULAR PURPOSE.  IN NO EVENT SHALL ANTHONY CASSANDRA BE LIABLE FOR
00021   ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00022   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00023   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00024   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00025   *****
00026 
00027 */
00028 #ifndef SPARSE_MATRIX_H
00029 
00030 #define SPARSE_MATRIX_H
00031 
00032 #include "Const.h"
00033 
00034 #define POS_ZERO_TOLERANCE        0.0000000001
00035 #define NEG_ZERO_TOLERANCE        -0.0000000001
00036 
00037 #define IS_ZERO(X)   ((X < POS_ZERO_TOLERANCE) && ( X > NEG_ZERO_TOLERANCE ))
00038 
00039 /*  Each row of the intermediate form of the matrix will consist
00040     of a linked list.  This structure is for each node of those linked
00041     lists.  The pertinent information is the column number for the
00042     entry and the value.  Additionally, this linked list will be kept
00043     sorted by column so when adding an element we look for the column
00044     and insert it in place. It will be sorted from least to greatest.
00045     */ 
00046 typedef struct I_Matrix_Row_Node_Struct *I_Matrix_Row_Node;
00047 struct I_Matrix_Row_Node_Struct {
00048   int column;
00049   REAL_VALUE value;
00050   I_Matrix_Row_Node next;
00051 };
00052 
00053 /*  A matrix in intermediate form will be a linked list for each row
00054     and a count of the number of non-zero entries for each row.
00055     */
00056 struct I_Matrix_Struct {
00057   int num_rows;
00058   I_Matrix_Row_Node *row;   /* An array of pointers for the head of
00059                                each row's linked list */
00060   int *row_length;            /* An array for the current lengths of
00061                                each row. */
00062 };
00063 typedef struct I_Matrix_Struct *I_Matrix;
00064 
00065 /* A matrix will be sparsely represented by a bunch of arrays
00066    */
00067 struct Matrix_Struct {
00068   int num_rows;
00069   int num_non_zero;
00070   REAL_VALUE *mat_val;  /* The actual non-zero entries stored row by row. */
00071   int *row_start;   /* the position for the start of each row in mat_val */
00072   int *row_length;  /* The length of each row in mat_val */
00073   int *col;         /* The column number for each entry in mat_val */
00074 };
00075 typedef struct Matrix_Struct *Matrix;
00076 
00077 /**********************************************************************/
00078 /******************************  External Routines  *******************/
00079 /**********************************************************************/
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083 
00084 extern void destroyRow( I_Matrix_Row_Node row );
00085 extern I_Matrix_Row_Node addEntryToRow( I_Matrix_Row_Node row, 
00086                                 int col, REAL_VALUE value,
00087                                 int *count, int accumulate );
00088 extern void displayRow( I_Matrix_Row_Node row );
00089 
00090 extern int addEntryToIMatrix( I_Matrix i_matrix, int row, 
00091                              int col, REAL_VALUE value );
00092 extern int accumulateEntryInIMatrix( I_Matrix i_matrix, int row, 
00093                                     int col, REAL_VALUE value );
00094 extern void destroyIMatrix( I_Matrix i_matrix );
00095 extern I_Matrix newIMatrix( int num_rows );
00096 extern REAL_VALUE sumIMatrixRowValues( I_Matrix i_matrix, int row );
00097 extern Matrix newMatrix( int num_rows, int num_non_zero );
00098 extern void destroyMatrix( Matrix matrix );
00099 extern Matrix transformIMatrix( I_Matrix i_matrix );
00100 extern void displayMatrix( Matrix matrix );
00101 extern REAL_VALUE sumRowValues( Matrix matrix, int row );
00102 extern REAL_VALUE getEntryMatrix( Matrix matrix, int row, int col );
00103 
00104 #ifdef __cplusplus
00105 }  /* extern "C" */
00106 #endif
00107 
00108 #endif


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29