blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/matrix.h Declaration of the Matrix<T_type, T_structure> class 00004 * 00005 * $Id: matrix.h,v 1.8 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_MATRIX_H 00033 #define BZ_MATRIX_H 00034 00035 #ifndef BZ_BLITZ_H 00036 #include <blitz/blitz.h> 00037 #endif 00038 00039 #ifndef BZ_MEMBLOCK_H 00040 #include <blitz/memblock.h> 00041 #endif 00042 00043 #ifndef BZ_MSTRUCT_H 00044 #include <blitz/mstruct.h> 00045 #endif 00046 00047 BZ_NAMESPACE(blitz) 00048 00049 // Forward declarations 00050 template<typename P_numtype, typename P_structure> 00051 class _bz_MatrixRef; 00052 00053 template<typename P_expr> 00054 class _bz_MatExpr; 00055 00056 // Declaration of class Matrix 00057 template<typename P_numtype, typename P_structure BZ_TEMPLATE_DEFAULT(RowMajor)> 00058 class Matrix : protected MemoryBlockReference<P_numtype> { 00059 00060 private: 00061 typedef MemoryBlockReference<P_numtype> T_base; 00062 using T_base::data_; 00063 00064 public: 00065 00067 // Public Types 00069 00070 typedef P_numtype T_numtype; 00071 typedef P_structure T_structure; 00072 typedef Matrix<P_numtype, P_structure> T_matrix; 00073 00075 // Constructors // 00077 00078 Matrix() 00079 { } 00080 00081 Matrix(int rows, int cols, T_structure structure = T_structure()) 00082 : structure_(structure) 00083 { 00084 structure_.resize(rows, cols); 00085 MemoryBlockReference<T_numtype>::newBlock(structure_.numElements()); 00086 } 00087 00088 // Matrix(int rows, int cols, T_numtype initValue, 00089 // T_structure structure = T_structure(rows, cols)); 00090 // Matrix(int rows, int cols, Random); 00091 // Matrix(int rows, int cols, matrix-expression); 00092 // Matrix(int rows, int cols, T_numtype* data, int rowStride, int colStride); 00093 // explicit Matrix(Vector<T_numtype>& matrix); 00094 // explicit Matrix(unsigned length); 00095 00096 // Create a vector view of an already allocated block of memory. 00097 // Note that the memory will not be freed when this vector is 00098 // destroyed. 00099 // Matrix(unsigned length, T_numtype* data, int stride = 1); 00100 00102 // Member functions 00104 00105 //T_iterator begin() const; 00106 //T_constIterator begin() const; 00107 //T_vector copy() const; 00108 //T_iterator end() const; 00109 //T_constIterator end() const; 00110 00111 unsigned cols() const 00112 { return structure_.columns(); } 00113 00114 unsigned columns() const 00115 { return structure_.columns(); } 00116 00117 void makeUnique() const; 00118 00119 unsigned numElements() const 00120 { return structure_.numElements(); } 00121 00122 void reference(T_matrix&); 00123 00124 void resize(unsigned rows, unsigned cols) 00125 { 00126 structure_.resize(rows, cols); 00127 MemoryBlockReference<T_numtype>::newBlock(structure_.numElements()); 00128 } 00129 00130 // void resizeAndPreserve(unsigned newLength); 00131 00132 unsigned rows() const 00133 { return structure_.rows(); } 00134 00135 _bz_MatrixRef<T_numtype, T_structure> _bz_getRef() const 00136 { return _bz_MatrixRef<T_numtype, T_structure>(*this); } 00137 00139 // Subscripting operators 00141 00142 T_numtype operator()(unsigned i, unsigned j) const 00143 { 00144 return structure_.get(data_, i, j); 00145 } 00146 00147 T_numtype& restrict operator()(unsigned i, unsigned j) 00148 { 00149 return structure_.get(data_, i, j); 00150 } 00151 00152 // T_matrix operator()(Range,Range); 00153 00154 // T_matrixIndirect operator()(Vector<int>,Vector<int>); 00155 // T_matrixIndirect operator()(integer-placeholder-expression, Range); 00156 // T_matrix operator()(difference-equation-expression) 00157 00159 // Assignment operators 00161 00162 // Scalar operand 00163 T_matrix& operator=(T_numtype); 00164 T_matrix& operator+=(T_numtype); 00165 T_matrix& operator-=(T_numtype); 00166 T_matrix& operator*=(T_numtype); 00167 T_matrix& operator/=(T_numtype); 00168 00169 // Matrix operand 00170 00171 template<typename P_numtype2, typename P_structure2> 00172 T_matrix& operator=(const Matrix<P_numtype2, P_structure2> &); 00173 template<typename P_numtype2, typename P_structure2> 00174 T_matrix& operator+=(const Matrix<P_numtype2, P_structure2>&); 00175 template<typename P_numtype2, typename P_structure2> 00176 T_matrix& operator-=(const Matrix<P_numtype2, P_structure2> &); 00177 template<typename P_numtype2, typename P_structure2> 00178 T_matrix& operator*=(const Matrix<P_numtype2, P_structure2> &); 00179 template<typename P_numtype2, typename P_structure2> 00180 T_matrix& operator/=(const Matrix<P_numtype2, P_structure2> &); 00181 00182 // Matrix expression operand 00183 template<typename P_expr> 00184 T_matrix& operator=(_bz_MatExpr<P_expr>); 00185 00186 // Integer placeholder expression operand 00187 // MatrixPick operand 00188 00190 // Unary operators 00192 00193 T_matrix& operator++(); 00194 void operator++(int); 00195 T_matrix& operator--(); 00196 void operator--(int); 00197 00198 private: 00199 T_structure structure_; 00200 }; 00201 00202 template<typename P_numtype, typename P_structure> 00203 ostream& operator<<(ostream& os, const Matrix<P_numtype, P_structure>& matrix); 00204 00205 template<typename P_numtype, typename P_structure> 00206 istream& operator>>(istream& is, Matrix<P_numtype, P_structure>& matrix); 00207 00208 // Global operators 00209 // +,-,*,/ with all possible combinations of: 00210 // - scalar 00211 // - matrix 00212 // - matrix pick 00213 // - matrix expression 00214 // Pointwise Math functions: sin, cos, etc. 00215 // Global functions 00216 00217 BZ_NAMESPACE_END 00218 00219 #include <blitz/matrix.cc> 00220 #include <blitz/matexpr.h> 00221 00222 #endif // BZ_MATRIX_H