00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef BZ_MATRIX_H
00027 #define BZ_MATRIX_H
00028
00029 #ifndef BZ_BLITZ_H
00030 #include <blitz/blitz.h>
00031 #endif
00032
00033 #ifndef BZ_MEMBLOCK_H
00034 #include <blitz/memblock.h>
00035 #endif
00036
00037 #ifndef BZ_MSTRUCT_H
00038 #include <blitz/mstruct.h>
00039 #endif
00040
00041 BZ_NAMESPACE(blitz)
00042
00043
00044 template<typename P_numtype, typename P_structure>
00045 class _bz_MatrixRef;
00046
00047 template<typename P_expr>
00048 class _bz_MatExpr;
00049
00050
00051 template<typename P_numtype, typename P_structure BZ_TEMPLATE_DEFAULT(RowMajor)>
00052 class Matrix : protected MemoryBlockReference<P_numtype> {
00053
00054 private:
00055 typedef MemoryBlockReference<P_numtype> T_base;
00056 using T_base::data_;
00057
00058 public:
00059
00061
00063
00064 typedef P_numtype T_numtype;
00065 typedef P_structure T_structure;
00066 typedef Matrix<P_numtype, P_structure> T_matrix;
00067
00069
00071
00072 Matrix()
00073 { }
00074
00075 Matrix(int rows, int cols, T_structure structure = T_structure())
00076 : structure_(structure)
00077 {
00078 structure_.resize(rows, cols);
00079 MemoryBlockReference<T_numtype>::newBlock(structure_.numElements());
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00096
00098
00099
00100
00101
00102
00103
00104
00105 unsigned cols() const
00106 { return structure_.columns(); }
00107
00108 unsigned columns() const
00109 { return structure_.columns(); }
00110
00111 void makeUnique() const;
00112
00113 unsigned numElements() const
00114 { return structure_.numElements(); }
00115
00116 void reference(T_matrix&);
00117
00118 void resize(unsigned rows, unsigned cols)
00119 {
00120 structure_.resize(rows, cols);
00121 MemoryBlockReference<T_numtype>::newBlock(structure_.numElements());
00122 }
00123
00124
00125
00126 unsigned rows() const
00127 { return structure_.rows(); }
00128
00129 _bz_MatrixRef<T_numtype, T_structure> _bz_getRef() const
00130 { return _bz_MatrixRef<T_numtype, T_structure>(*this); }
00131
00133
00135
00136 T_numtype operator()(unsigned i, unsigned j) const
00137 {
00138 return structure_.get(data_, i, j);
00139 }
00140
00141 T_numtype& restrict operator()(unsigned i, unsigned j)
00142 {
00143 return structure_.get(data_, i, j);
00144 }
00145
00146
00147
00148
00149
00150
00151
00153
00155
00156
00157 T_matrix& operator=(T_numtype);
00158 T_matrix& operator+=(T_numtype);
00159 T_matrix& operator-=(T_numtype);
00160 T_matrix& operator*=(T_numtype);
00161 T_matrix& operator/=(T_numtype);
00162
00163
00164
00165 template<typename P_numtype2, typename P_structure2>
00166 T_matrix& operator=(const Matrix<P_numtype2, P_structure2> &);
00167 template<typename P_numtype2, typename P_structure2>
00168 T_matrix& operator+=(const Matrix<P_numtype2, P_structure2>&);
00169 template<typename P_numtype2, typename P_structure2>
00170 T_matrix& operator-=(const Matrix<P_numtype2, P_structure2> &);
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
00176
00177 template<typename P_expr>
00178 T_matrix& operator=(_bz_MatExpr<P_expr>);
00179
00180
00181
00182
00184
00186
00187 T_matrix& operator++();
00188 void operator++(int);
00189 T_matrix& operator--();
00190 void operator--(int);
00191
00192 private:
00193 T_structure structure_;
00194 };
00195
00196 template<typename P_numtype, typename P_structure>
00197 ostream& operator<<(ostream& os, const Matrix<P_numtype, P_structure>& matrix);
00198
00199 template<typename P_numtype, typename P_structure>
00200 istream& operator>>(istream& is, Matrix<P_numtype, P_structure>& matrix);
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 BZ_NAMESPACE_END
00212
00213 #include <blitz/matrix.cc>
00214 #include <blitz/matexpr.h>
00215
00216 #endif // BZ_MATRIX_H