00001 // -*- C++ -*- 00002 // $Id: SprGenMatrix.cc,v 1.2 2007/09/21 22:32:10 narsky Exp $ 00003 // --------------------------------------------------------------------------- 00004 // 00005 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 00006 // 00007 // 00008 // Copyright Cornell University 1993, 1996, All Rights Reserved. 00009 // 00010 // This software written by Nobu Katayama and Mike Smyth, Cornell University. 00011 // 00012 // Redistribution and use in source and binary forms, with or without 00013 // modification, are permitted provided that the following conditions 00014 // are met: 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice and author attribution, this list of conditions and the 00017 // following disclaimer. 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice and author attribution, this list of conditions and the 00020 // following disclaimer in the documentation and/or other materials 00021 // provided with the distribution. 00022 // 3. Neither the name of the University nor the names of its contributors 00023 // may be used to endorse or promote products derived from this software 00024 // without specific prior written permission. 00025 // 00026 // Creation of derivative forms of this software for commercial 00027 // utilization may be subject to restriction; written permission may be 00028 // obtained from Cornell University. 00029 // 00030 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way 00031 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR 00032 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT 00033 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, 00034 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS. Cornell University shall not be 00035 // held liable for any liability with respect to any claim by the user or any 00036 // other party arising from use of the program. 00037 // 00038 // This is the implementation of the SprGenMatrix class. 00039 // 00040 00041 #include <cstring> 00042 #include <cmath> 00043 #include <cstdlib> 00044 00045 #include "SprGenMatrix.hh" 00046 #include "SprSymMatrix.hh" 00047 #include "SprMatrix.hh" 00048 00049 double norm_infinity(const SprGenMatrix &m) { 00050 double max=0,sum; 00051 for(int r=1;r<=m.num_row();r++) { 00052 sum=0; 00053 for(int c=1;c<=m.num_col();c++) { 00054 sum+=fabs(m(r,c)); 00055 } 00056 if(sum>max) max=sum; 00057 } 00058 return max; 00059 } 00060 00061 double norm1(const SprGenMatrix &m) { 00062 double max=0,sum; 00063 for(int c=1;c<=m.num_col();c++) { 00064 sum=0; 00065 for(int r=1;r<=m.num_row();r++) 00066 sum+=fabs(m(r,c)); 00067 if(sum>max) max=sum; 00068 } 00069 return max; 00070 } 00071 00072 void SprGenMatrix::error(const char *s) 00073 { 00074 std::cerr << s << std::endl; 00075 std::cerr << "---Exiting to System." << std::endl; 00076 abort(); 00077 } 00078 00079 bool SprGenMatrix::operator== ( const SprGenMatrix& o) const { 00080 if(o.num_row()!=num_row() || o.num_col()!=num_col()) return false; 00081 for (int k1=1; k1<=num_row(); k1++) 00082 for (int k2=1; k2<=num_col(); k2++) 00083 if(o(k1,k2) != (*this)(k1,k2)) return false; 00084 return true; 00085 } 00086 00087 // implementation using pre-allocated data array 00088 // ----------------------------------------------------------------- 00089 00090 void SprGenMatrix::delete_m(int size, double* m) 00091 { 00092 if (m) 00093 { 00094 if(size > size_max) 00095 delete [] m; 00096 } 00097 } 00098 00099 double* SprGenMatrix::new_m(int size) 00100 { 00101 /*-ap: data_array is replaced by the std::vector<double>, 00102 * so we simply return 0 here 00103 * 00104 * if (size == 0) return 0; 00105 * else { 00106 * if ( size <= size_max ) { 00107 * memset(data_array, 0, size * sizeof(double)); 00108 * return data_array; 00109 * } else { 00110 * double * nnn = new double[size]; 00111 * memset(nnn, 0, size * sizeof(double)); 00112 * return nnn; 00113 * } 00114 * } 00115 *-ap end 00116 */ 00117 return 0; 00118 } 00119