blitz/matrix.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  * blitz/matrix.h      Declaration of the Matrix<T_type, T_structure> class
00003  *
00004  * $Id: matrix.h,v 1.6 2003/12/11 03:44:22 julianc Exp $
00005  *
00006  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * Suggestions:          blitz-dev@oonumerics.org
00019  * Bugs:                 blitz-bugs@oonumerics.org
00020  *
00021  * For more information, please see the Blitz++ Home Page:
00022  *    http://oonumerics.org/blitz/
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 // Forward declarations
00044 template<typename P_numtype, typename P_structure>
00045 class _bz_MatrixRef;
00046 
00047 template<typename P_expr>
00048 class _bz_MatExpr;
00049 
00050 // Declaration of class Matrix
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     // Public Types
00063 
00064     typedef P_numtype        T_numtype;
00065     typedef P_structure      T_structure;
00066     typedef Matrix<P_numtype, P_structure>   T_matrix;
00067 
00069     // Constructors                             //
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     // Matrix(int rows, int cols, T_numtype initValue,
00083     //    T_structure structure = T_structure(rows, cols));
00084     // Matrix(int rows, int cols, Random);
00085     // Matrix(int rows, int cols, matrix-expression);
00086     // Matrix(int rows, int cols, T_numtype* data, int rowStride, int colStride);
00087     // explicit Matrix(Vector<T_numtype>& matrix);
00088     // explicit Matrix(unsigned length);
00089 
00090     // Create a vector view of an already allocated block of memory.
00091     // Note that the memory will not be freed when this vector is
00092     // destroyed.
00093     // Matrix(unsigned length, T_numtype* data, int stride = 1);
00094 
00096     // Member functions
00098 
00099     //T_iterator      begin()  const;
00100     //T_constIterator begin()  const;
00101     //T_vector        copy()   const;
00102     //T_iterator      end()    const;
00103     //T_constIterator end()    const;
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 //    void            resizeAndPreserve(unsigned newLength);
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     // Subscripting operators
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     // T_matrix      operator()(Range,Range);
00147 
00148     // T_matrixIndirect operator()(Vector<int>,Vector<int>);
00149     // T_matrixIndirect operator()(integer-placeholder-expression, Range);
00150     // T_matrix         operator()(difference-equation-expression)
00151 
00153     // Assignment operators
00155 
00156     // Scalar operand
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     // Matrix operand
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     // Matrix expression operand
00177     template<typename P_expr>
00178     T_matrix& operator=(_bz_MatExpr<P_expr>);
00179 
00180     // Integer placeholder expression operand
00181     // MatrixPick operand
00182 
00184     // Unary operators
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 // Global operators
00200 // +,-,*,/ with all possible combinations of:
00201 //    - scalar
00202 //    - matrix
00203 //    - matrix pick
00204 //    - matrix expression
00205 // Pointwise Math functions: sin, cos, etc.
00206 // Global functions
00207 
00208 BZ_NAMESPACE_END
00209 
00210 #include <blitz/matrix.cc>
00211 #include <blitz/matexpr.h>
00212 
00213 #endif // BZ_MATRIX_H

Generated on Mon Dec 3 09:22:41 2007 for blitz by  doxygen 1.5.1