$search
00001 /* 00002 * OpenNL: Numerical Library 00003 * Copyright (C) 2004 Bruno Levy 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 * 00019 * If you modify this software, you should include a notice giving the 00020 * name of the person performing the modification, the date of modification, 00021 * and the reason for such modification. 00022 * 00023 * Contact: Bruno Levy 00024 * 00025 * levy@loria.fr 00026 * 00027 * ISA Project 00028 * LORIA, INRIA Lorraine, 00029 * Campus Scientifique, BP 239 00030 * 54506 VANDOEUVRE LES NANCY CEDEX 00031 * FRANCE 00032 * 00033 * Note that the GNU General Public License does not permit incorporating 00034 * the Software into proprietary programs. 00035 */ 00036 00037 #include <NL/nl_private.h> 00038 00039 #ifndef __NL_MATRIX__ 00040 #define __NL_MATRIX__ 00041 00042 /************************************************************************************/ 00043 /* Dynamic arrays for sparse row/columns */ 00044 00045 typedef struct { 00046 NLuint index ; 00047 NLdouble value ; 00048 } NLCoeff ; 00049 00050 typedef struct { 00051 NLuint size ; 00052 NLuint capacity ; 00053 NLCoeff* coeff ; 00054 } NLRowColumn ; 00055 00056 void nlRowColumnConstruct(NLRowColumn* c) ; 00057 void nlRowColumnDestroy(NLRowColumn* c) ; 00058 void nlRowColumnGrow(NLRowColumn* c) ; 00059 void nlRowColumnAdd(NLRowColumn* c, NLint index, NLdouble value) ; 00060 void nlRowColumnAppend(NLRowColumn* c, NLint index, NLdouble value) ; 00061 void nlRowColumnZero(NLRowColumn* c) ; 00062 void nlRowColumnClear(NLRowColumn* c) ; 00063 void nlRowColumnSort(NLRowColumn* c) ; 00064 00065 /************************************************************************************/ 00066 /* SparseMatrix data structure */ 00067 00068 #define NL_MATRIX_STORE_ROWS 1 00069 #define NL_MATRIX_STORE_COLUMNS 2 00070 #define NL_MATRIX_STORE_SYMMETRIC 4 00071 00072 typedef struct { 00073 NLuint m ; 00074 NLuint n ; 00075 NLuint diag_size ; 00076 NLenum storage ; 00077 NLRowColumn* row ; 00078 NLRowColumn* column ; 00079 NLdouble* diag ; 00080 } NLSparseMatrix ; 00081 00082 00083 void nlSparseMatrixConstruct( 00084 NLSparseMatrix* M, NLuint m, NLuint n, NLenum storage 00085 ) ; 00086 00087 void nlSparseMatrixDestroy(NLSparseMatrix* M) ; 00088 00089 void nlSparseMatrixAdd( 00090 NLSparseMatrix* M, NLuint i, NLuint j, NLdouble value 00091 ) ; 00092 00093 void nlSparseMatrixZero( NLSparseMatrix* M) ; 00094 void nlSparseMatrixClear( NLSparseMatrix* M) ; 00095 NLuint nlSparseMatrixNNZ( NLSparseMatrix* M) ; 00096 void nlSparseMatrixSort( NLSparseMatrix* M) ; 00097 00098 /************************************************************************************/ 00099 /* SparseMatrix x Vector routine */ 00100 00101 void nlSparseMatrixMult(NLSparseMatrix* A, NLdouble* x, NLdouble* y) ; 00102 00103 #endif