| 1 | /*************************************************************************** | 
|---|
| 2 | * blitz/matrix.h      Declaration of the Matrix<T_type, T_structure> class | 
|---|
| 3 | * | 
|---|
| 4 | * $Id: matrix.h,v 1.1.1.1 1999-11-26 16:37:03 ansari Exp $ | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | 
|---|
| 7 | * | 
|---|
| 8 | * This program is free software; you can redistribute it and/or | 
|---|
| 9 | * modify it under the terms of the GNU General Public License | 
|---|
| 10 | * as published by the Free Software Foundation; either version 2 | 
|---|
| 11 | * of the License, or (at your option) any later version. | 
|---|
| 12 | * | 
|---|
| 13 | * This program is distributed in the hope that it will be useful, | 
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | * GNU General Public License for more details. | 
|---|
| 17 | * | 
|---|
| 18 | * Suggestions:          blitz-suggest@cybervision.com | 
|---|
| 19 | * Bugs:                 blitz-bugs@cybervision.com | 
|---|
| 20 | * | 
|---|
| 21 | * For more information, please see the Blitz++ Home Page: | 
|---|
| 22 | *    http://seurat.uwaterloo.ca/blitz/ | 
|---|
| 23 | * | 
|---|
| 24 | *************************************************************************** | 
|---|
| 25 | * $Log: not supported by cvs2svn $ | 
|---|
| 26 | * Revision 1.1.1.1  1999/04/09  17:59:00  ansari | 
|---|
| 27 | * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99 | 
|---|
| 28 | * | 
|---|
| 29 | * Revision 1.6  1998/03/14 00:04:47  tveldhui | 
|---|
| 30 | * 0.2-alpha-05 | 
|---|
| 31 | * | 
|---|
| 32 | * Revision 1.5  1997/07/16 14:51:20  tveldhui | 
|---|
| 33 | * Update: Alpha release 0.2 (Arrays) | 
|---|
| 34 | * | 
|---|
| 35 | * Revision 1.4  1997/01/24 14:42:00  tveldhui | 
|---|
| 36 | * Periodic RCS update | 
|---|
| 37 | * | 
|---|
| 38 | * Revision 1.3  1997/01/23 03:28:28  tveldhui | 
|---|
| 39 | * Periodic RCS update | 
|---|
| 40 | * | 
|---|
| 41 | * Revision 1.2  1997/01/13 22:19:58  tveldhui | 
|---|
| 42 | * Periodic RCS update | 
|---|
| 43 | * | 
|---|
| 44 | * Revision 1.1  1996/11/11 17:29:13  tveldhui | 
|---|
| 45 | * Initial revision | 
|---|
| 46 | * | 
|---|
| 47 | * Revision 1.2  1996/10/31 21:06:54  tveldhui | 
|---|
| 48 | * Did away with multiple template parameters.  Only numeric type | 
|---|
| 49 | * and structure parameters now. | 
|---|
| 50 | * | 
|---|
| 51 | * | 
|---|
| 52 | */ | 
|---|
| 53 |  | 
|---|
| 54 | #ifndef BZ_MATRIX_H | 
|---|
| 55 | #define BZ_MATRIX_H | 
|---|
| 56 |  | 
|---|
| 57 | #ifndef BZ_BLITZ_H | 
|---|
| 58 | #include <blitz/blitz.h> | 
|---|
| 59 | #endif | 
|---|
| 60 |  | 
|---|
| 61 | #ifndef BZ_MEMBLOCK_H | 
|---|
| 62 | #include <blitz/memblock.h> | 
|---|
| 63 | #endif | 
|---|
| 64 |  | 
|---|
| 65 | #ifndef BZ_MSTRUCT_H | 
|---|
| 66 | #include <blitz/mstruct.h> | 
|---|
| 67 | #endif | 
|---|
| 68 |  | 
|---|
| 69 | BZ_NAMESPACE(blitz) | 
|---|
| 70 |  | 
|---|
| 71 | // Forward declarations | 
|---|
| 72 | template<class P_numtype, class P_structure> | 
|---|
| 73 | class _bz_MatrixRef; | 
|---|
| 74 |  | 
|---|
| 75 | template<class P_expr> | 
|---|
| 76 | class _bz_MatExpr; | 
|---|
| 77 |  | 
|---|
| 78 | // Declaration of class Matrix | 
|---|
| 79 | template<class P_numtype, class P_structure BZ_TEMPLATE_DEFAULT(RowMajor)> | 
|---|
| 80 | class Matrix : protected MemoryBlockReference<P_numtype> { | 
|---|
| 81 |  | 
|---|
| 82 | public: | 
|---|
| 83 |  | 
|---|
| 84 | ////////////////////////////////////////////// | 
|---|
| 85 | // Public Types | 
|---|
| 86 | ////////////////////////////////////////////// | 
|---|
| 87 |  | 
|---|
| 88 | typedef P_numtype        T_numtype; | 
|---|
| 89 | typedef P_structure      T_structure; | 
|---|
| 90 | typedef Matrix<P_numtype, P_structure>   T_matrix; | 
|---|
| 91 |  | 
|---|
| 92 | ////////////////////////////////////////////// | 
|---|
| 93 | // Constructors                             // | 
|---|
| 94 | ////////////////////////////////////////////// | 
|---|
| 95 |  | 
|---|
| 96 | Matrix() | 
|---|
| 97 | { } | 
|---|
| 98 |  | 
|---|
| 99 | Matrix(int rows, int cols, T_structure structure = T_structure()) | 
|---|
| 100 | : structure_(structure) | 
|---|
| 101 | { | 
|---|
| 102 | structure_.resize(rows, cols); | 
|---|
| 103 | MemoryBlockReference<T_numtype>::newBlock(structure_.numElements()); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | // Matrix(int rows, int cols, T_numtype initValue, | 
|---|
| 107 | //    T_structure structure = T_structure(rows, cols)); | 
|---|
| 108 | // Matrix(int rows, int cols, Random); | 
|---|
| 109 | // Matrix(int rows, int cols, matrix-expression); | 
|---|
| 110 | // Matrix(int rows, int cols, T_numtype* data, int rowStride, int colStride); | 
|---|
| 111 | // _bz_explicit Matrix(Vector<T_numtype>& matrix); | 
|---|
| 112 | // _bz_explicit Matrix(unsigned length); | 
|---|
| 113 |  | 
|---|
| 114 | // Create a vector view of an already allocated block of memory. | 
|---|
| 115 | // Note that the memory will not be freed when this vector is | 
|---|
| 116 | // destroyed. | 
|---|
| 117 | // Matrix(unsigned length, T_numtype* data, int stride = 1); | 
|---|
| 118 |  | 
|---|
| 119 | ////////////////////////////////////////////// | 
|---|
| 120 | // Member functions | 
|---|
| 121 | ////////////////////////////////////////////// | 
|---|
| 122 |  | 
|---|
| 123 | //T_iterator      begin()  const; | 
|---|
| 124 | //T_constIterator begin()  const; | 
|---|
| 125 | //T_vector        copy()   const; | 
|---|
| 126 | //T_iterator      end()    const; | 
|---|
| 127 | //T_constIterator end()    const; | 
|---|
| 128 |  | 
|---|
| 129 | unsigned        cols()        const | 
|---|
| 130 | { return structure_.columns(); } | 
|---|
| 131 |  | 
|---|
| 132 | unsigned        columns()     const | 
|---|
| 133 | { return structure_.columns(); } | 
|---|
| 134 |  | 
|---|
| 135 | void            makeUnique()  const; | 
|---|
| 136 |  | 
|---|
| 137 | unsigned        numElements() const | 
|---|
| 138 | { return structure_.numElements(); } | 
|---|
| 139 |  | 
|---|
| 140 | void            reference(T_matrix&); | 
|---|
| 141 |  | 
|---|
| 142 | void            resize(unsigned rows, unsigned cols) | 
|---|
| 143 | { | 
|---|
| 144 | structure_.resize(rows, cols); | 
|---|
| 145 | MemoryBlockReference<T_numtype>::newBlock(structure_.numElements()); | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | //    void            resizeAndPreserve(unsigned newLength); | 
|---|
| 149 |  | 
|---|
| 150 | unsigned        rows()   const | 
|---|
| 151 | { return structure_.rows(); } | 
|---|
| 152 |  | 
|---|
| 153 | _bz_MatrixRef<T_numtype, T_structure> _bz_getRef() const | 
|---|
| 154 | { return _bz_MatrixRef<T_numtype, T_structure>(*this); } | 
|---|
| 155 |  | 
|---|
| 156 | ////////////////////////////////////////////// | 
|---|
| 157 | // Subscripting operators | 
|---|
| 158 | ////////////////////////////////////////////// | 
|---|
| 159 |  | 
|---|
| 160 | T_numtype           operator()(unsigned i, unsigned j) const | 
|---|
| 161 | { | 
|---|
| 162 | return structure_.get(data_, i, j); | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 | T_numtype& _bz_restrict operator()(unsigned i, unsigned j) | 
|---|
| 166 | { | 
|---|
| 167 | return structure_.get(data_, i, j); | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 | // T_matrix      operator()(Range,Range); | 
|---|
| 171 |  | 
|---|
| 172 | // T_matrixIndirect operator()(Vector<int>,Vector<int>); | 
|---|
| 173 | // T_matrixIndirect operator()(integer-placeholder-expression, Range); | 
|---|
| 174 | // T_matrix         operator()(difference-equation-expression) | 
|---|
| 175 |  | 
|---|
| 176 | ////////////////////////////////////////////// | 
|---|
| 177 | // Assignment operators | 
|---|
| 178 | ////////////////////////////////////////////// | 
|---|
| 179 |  | 
|---|
| 180 | // Scalar operand | 
|---|
| 181 | T_matrix& operator=(T_numtype); | 
|---|
| 182 | T_matrix& operator+=(T_numtype); | 
|---|
| 183 | T_matrix& operator-=(T_numtype); | 
|---|
| 184 | T_matrix& operator*=(T_numtype); | 
|---|
| 185 | T_matrix& operator/=(T_numtype); | 
|---|
| 186 |  | 
|---|
| 187 | // Matrix operand | 
|---|
| 188 |  | 
|---|
| 189 | template<class P_numtype2, class P_structure2> | 
|---|
| 190 | T_matrix& operator=(const Matrix<P_numtype2, P_structure2> &); | 
|---|
| 191 | template<class P_numtype2, class P_structure2> | 
|---|
| 192 | T_matrix& operator+=(const Matrix<P_numtype2, P_structure2>&); | 
|---|
| 193 | template<class P_numtype2, class P_structure2> | 
|---|
| 194 | T_matrix& operator-=(const Matrix<P_numtype2, P_structure2> &); | 
|---|
| 195 | template<class P_numtype2, class P_structure2> | 
|---|
| 196 | T_matrix& operator*=(const Matrix<P_numtype2, P_structure2> &); | 
|---|
| 197 | template<class P_numtype2, class P_structure2> | 
|---|
| 198 | T_matrix& operator/=(const Matrix<P_numtype2, P_structure2> &); | 
|---|
| 199 |  | 
|---|
| 200 | // Matrix expression operand | 
|---|
| 201 | template<class P_expr> | 
|---|
| 202 | T_matrix& operator=(_bz_MatExpr<P_expr>); | 
|---|
| 203 |  | 
|---|
| 204 | // Integer placeholder expression operand | 
|---|
| 205 | // MatrixPick operand | 
|---|
| 206 |  | 
|---|
| 207 | ////////////////////////////////////////////// | 
|---|
| 208 | // Unary operators | 
|---|
| 209 | ////////////////////////////////////////////// | 
|---|
| 210 |  | 
|---|
| 211 | T_matrix& operator++(); | 
|---|
| 212 | void operator++(int); | 
|---|
| 213 | T_matrix& operator--(); | 
|---|
| 214 | void operator--(int); | 
|---|
| 215 |  | 
|---|
| 216 | private: | 
|---|
| 217 | T_structure structure_; | 
|---|
| 218 | }; | 
|---|
| 219 |  | 
|---|
| 220 | template<class P_numtype, class P_structure> | 
|---|
| 221 | ostream& operator<<(ostream& os, const Matrix<P_numtype, P_structure>& matrix); | 
|---|
| 222 |  | 
|---|
| 223 | // Global operators | 
|---|
| 224 | // +,-,*,/ with all possible combinations of: | 
|---|
| 225 | //    - scalar | 
|---|
| 226 | //    - matrix | 
|---|
| 227 | //    - matrix pick | 
|---|
| 228 | //    - matrix expression | 
|---|
| 229 | // Pointwise Math functions: sin, cos, etc. | 
|---|
| 230 | // Global functions | 
|---|
| 231 |  | 
|---|
| 232 | BZ_NAMESPACE_END | 
|---|
| 233 |  | 
|---|
| 234 | #include <blitz/matrix.cc> | 
|---|
| 235 | #include <blitz/matexpr.h> | 
|---|
| 236 |  | 
|---|
| 237 | #endif // BZ_MATRIX_H | 
|---|