00001 // Copyright (C) 1998--2002 Petter Urkedal 00002 // 00003 // This file is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This file is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software library without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to 00021 // produce an executable, this file does not by itself cause the 00022 // resulting executable to be covered by the GNU General Public 00023 // License. This exception does not however invalidate any other 00024 // reasons why the executable file might be covered by the GNU General 00025 // Public License. 00026 00027 // $Id: matrixtypes.h,v 1.2 2002/09/01 12:02:10 petter_urkedal Exp $ 00028 00029 00030 00031 #ifndef MORE_NUM_MATRIXTYPES_H 00032 #define MORE_NUM_MATRIXTYPES_H 00033 00034 ///\if unmaintained 00035 #include <more/bits/optype.h> 00036 00037 namespace more { 00038 namespace num { 00039 00040 // NOTE on notation. The suffix `_s' denotes that the class is a 00041 // signature. A signature is here an empty class (required to have 00042 // only static variables), which is used to identify which 00043 // requirements the class fulfills. The signatures are used as base 00044 // classes. Their function is to select an appropriate template 00045 // function. This is done by writing various versions of an 00046 // algorothm, taking dummy signature arguments, and one version which 00047 // selects one of these by duplicating its argument to the dummy 00048 // arguments. 00049 // 00050 // This signature-mechanism is thus to template algorithms as 00051 // abstract base-classes are to non-template algorithms. 00052 00053 00054 00055 /* A b s t r a c t S u b c l a s s e s o f M a t r i c e s 00056 00057 matrix_tag is the class of all matrices. The matrix cathegory are 00058 subclasses with specific symmetry and orthogonality properties. 00059 Matrix sparseness are parallel subclasses which can be combined 00060 with a matrix cathegory. 00061 00062 Matrix requirements: 00063 00064 ------------------------------------------------------------------------ 00065 C::value_type typedef the type T compile time 00066 00067 C::index_type typedef the type Q compile time 00068 00069 C::compatibility typedef a tag indicating how the compile time 00070 matrix is stored 00071 00072 u.dim(0) Q the number of columns constant 00073 00074 u.dim(1) Q the number of rows constant 00075 00076 u[i][j] T the element at column i constant 00077 and row j, counting from 0 00078 00079 u(i,j) T u[i+1][j+1] (Fortran style) constant 00080 ------------------------------------------------------------------------ 00081 00082 Additional requirements: 00083 ------------------------------------------------------------------------ 00084 C::iterator typedef an iterator type returned compile time 00085 C::diagonal_iterator by the corresponding 00086 C::row_iterator function below 00087 C::column_iterator 00088 00089 u.begin() iterator Defines the first and last constant 00090 u.end() iterator element of the sequence of 00091 all components of the matrix. 00092 00093 u.begin_diagonal() diagonal_iterator constant 00094 u.end_diagonal() diagonal_iterator 00095 Defines the first and last 00096 elements of the sequence of 00097 diagonal matrix elements. 00098 00099 u.begin_row() row_iterator constant 00100 u.end_row() row_iterator 00101 00102 u.begin_column() column_iterator constant 00103 u.end_column() column_iterator 00104 ------------------------------------------------------------------------ 00105 */ 00106 00107 00108 // Compatibility and size-hint 00109 00110 struct minimum_compatible_tag {}; 00111 struct fortran_compatible_tag : public minimum_compatible_tag {}; 00112 struct blas_upper_triangle_packed_compatible_tag 00113 : public minimum_compatible_tag {}; 00114 struct blas_band_packed_compatible_tag : public minimum_compatible_tag {}; 00115 struct MMT_compatible_tag {}; 00116 struct nonMMT_compatible_tag : public MMT_compatible_tag {}; 00117 00118 //struct anysize_size_hint {}; 00119 //struct small_size_hint {}; 00120 //struct medium_size_hint {}; // a practical size 00121 //struct big_size_hint {}; // must be sparse, diagonalize by iteration 00122 //struct huge_size_hint {}; // must be swapped between disk and memory 00123 00124 // NOTE ON THE MMT COMPATIBILITY. The nonMMT_compatible_tag 00125 // structure indicates that Mutable() does not need to be called 00126 // before modifying a matrix. Any algorithm that does not support 00127 // MMT handling, should check MMT_compatibility for this. 00128 // 00129 // Algorithms which supports MMT matrices will automatically support 00130 // non-MMT matrices, since we will supply an empty definition of 00131 // Mutable() in non-MMT matrix classes. 00132 00133 struct matrix_s {}; 00134 struct column_vector_s : virtual public matrix_s {}; // Yes, a vector is 00135 struct row_vector_s : virtual public matrix_s {}; // also a matrix. 00136 typedef column_vector_s vector_s; 00137 00138 00139 // Matix cathegory 00140 00141 struct real_s : virtual public matrix_s {}; 00142 struct symmetric_s : virtual public matrix_s {}; 00143 struct skew_symmetric_s : virtual public matrix_s {}; 00144 struct hermitian_s : virtual public matrix_s {}; 00145 struct skew_hermitian_s : virtual public matrix_s {}; 00146 struct orthogonal_s : virtual public matrix_s {}; 00147 struct unitary_s : virtual public matrix_s {}; 00148 00149 00150 //template <class S, class T> class isection_s {}; 00151 00152 #define DEF(S, T)\ 00153 struct S##_##T##_s : virtual public S##_s, virtual public T##_s {};\ 00154 typedef S##_##T##_s T##_##S##_s 00155 // struct isection<S, T> { typedef struct S##_##T##_s self; }; 00156 // struct isection<T, S> { typedef struct S##_##T##_s self; }; 00157 00158 // Double combinations 00159 DEF(real, symmetric); 00160 DEF(real, skew_symmetric); 00161 typedef real_symmetric_s real_hermitian_s; 00162 typedef real_skew_symmetric_s real_skew_hermitian_s; 00163 DEF(real, orthogonal); 00164 typedef real_orthogonal_s real_unitary_s; 00165 DEF(symmetric, orthogonal); 00166 DEF(symmetric, unitary); 00167 DEF(skew_symmetric, orthogonal); 00168 DEF(skew_symmetric, unitary); 00169 DEF(hermitian, orthogonal); 00170 DEF(hermitian, unitary); 00171 DEF(skew_hermitian, orthogonal); 00172 DEF(skew_hermitian, unitary); 00173 #undef DEF 00174 00175 00176 00177 00178 // (real)opt 00179 // (symmetric | skew_symmetric | hermitian | skew_hermitian)opt 00180 // (orthogonal | unitary)opt 00181 00182 struct symmetric_positive_definite_s : virtual public symmetric_s {}; 00183 struct symmetric_negative_definite_s : virtual public symmetric_s {}; 00184 struct hermitian_positive_definite_s : virtual public hermitian_s {}; 00185 struct hermitian_negative_definite_s : virtual public hermitian_s {}; 00186 00187 00188 // Matrix sparseness 00189 00190 struct sparse_s : virtual public matrix_s {}; 00191 00192 struct band_s : virtual public sparse_s {}; 00193 struct tridiagonal_s : virtual public band_s {}; 00194 struct symmetric_tridiagonal_s 00195 : virtual public tridiagonal_s, 00196 virtual public symmetric_s {}; 00197 struct hermitian_tridiagonal_s 00198 : virtual public tridiagonal_s, 00199 virtual public hermitian_s {}; 00200 struct upper_bidiagonal_s : virtual public tridiagonal_s {}; 00201 struct lower_bidiagonal_s : virtual public tridiagonal_s {}; 00202 00203 struct upper_Hessenberg_s : virtual public sparse_s {}; 00204 struct lower_Hessenberg_s : virtual public sparse_s {}; 00205 struct upper_triangular_s : virtual public upper_Hessenberg_s {}; 00206 struct lower_triangular_s : virtual public lower_Hessenberg_s {}; 00207 00208 struct block_diagonal_s : virtual public sparse_s {}; 00209 00210 struct diagonal_s : virtual public upper_bidiagonal_s, 00211 virtual public lower_bidiagonal_s, 00212 virtual public symmetric_s, 00213 virtual public skew_symmetric_s, 00214 virtual public hermitian_s, 00215 virtual public skew_hermitian_s {}; 00216 struct real_diagonal_s : virtual public diagonal_s, 00217 virtual public real_symmetric_s, 00218 virtual public real_skew_symmetric_s {}; 00219 // more... 00220 00221 00222 00223 00224 // S o m e U t i l i t i e s 00225 00226 00227 /* 00228 template <class T, int step> 00229 class matrix_view_constant_step_iterator { 00230 T* e; 00231 public: 00232 T& operator++() { e += step; return *e; } 00233 T& operator++(int) { T* e_ = e; e += step; return *e_; } 00234 T& operator--() { e -= step; return *e; } 00235 T& operator--(int) { T* e_ = e; e -= step; return *e_; } 00236 // etc. 00237 }; 00238 */ 00239 00240 }} 00241 00242 ///\endif 00243 #endif