source: git/factory/templates/ftmpl_matrix.h @ 22347b6

spielwiese
Last change on this file since 22347b6 was 22347b6, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes; gcc 3.4 fixes from Dan Grayson git-svn-id: file:///usr/local/Singular/svn/trunk@7658 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: ftmpl_matrix.h,v 1.9 2005-01-13 15:10:23 Singular Exp $ */
3
4#ifndef INCL_MATRIX_H
5#define INCL_MATRIX_H
6
7#include <factoryconf.h>
8
9#ifndef NOSTREAMIO
10#include <iostream.h>
11#endif /* NOSTREAMIO */
12
13template <class T>
14class SubMatrix;
15
16template <class T>
17class Matrix;
18
19#ifndef NOSTREAMIO
20template <class T>
21std::ostream& operator<< (std::ostream &, const Matrix<T> &);
22#endif
23
24template <class T>
25class Matrix
26{
27private:
28    int NR, NC;
29    T ** elems;
30#ifndef NOSTREAMIO
31    void printrow ( ostream & s, int i ) const;
32#endif /* NOSTREAMIO */
33    typedef T* T_ptr;
34public:
35    Matrix() : NR(0), NC(0), elems(0) {}
36    Matrix( int nr, int nc );
37    Matrix( const Matrix<T>& M );
38    ~Matrix();
39    Matrix<T>& operator= ( const Matrix<T>& M );
40    int rows() const { return NR; }
41    int columns() const { return NC; }
42    SubMatrix<T> operator[] ( int i );
43    const SubMatrix<T> operator[] ( int i ) const;
44    T& operator() ( int row, int col );
45    T operator() ( int row, int col ) const;
46    SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax );
47    const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const;
48    void swapRow( int i, int j );
49    void swapColumn( int i, int j );
50#ifndef NOSTREAMIO
51    void print( ostream& s ) const;
52    friend ostream & operator<< <>( ostream & s, const Matrix<T>& M );
53#endif /* NOSTREAMIO */
54    friend class SubMatrix<T>;
55};
56    template <class T>
57    Matrix<T> operator+ ( const Matrix<T>& lhs, const Matrix<T>& rhs );
58    template <class T>
59    Matrix<T> operator- ( const Matrix<T>& lhs, const Matrix<T>& rhs );
60    template <class T>
61    Matrix<T> operator* ( const Matrix<T>& lhs, const Matrix<T>& rhs );
62    template <class T>
63    Matrix<T> operator* ( const Matrix<T>& lhs, const T& rhs );
64    template <class T>
65    Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs );
66
67template <class T>
68class SubMatrix
69{
70private:
71    int r_min, r_max, c_min, c_max;
72    Matrix<T>& M;
73    // we do not provide a default ctor, so nobody can declare an empty SubMatrix
74    SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m );
75public:
76    SubMatrix( const SubMatrix<T> & S );
77    SubMatrix<T>& operator= ( const SubMatrix<T>& S );
78    SubMatrix<T>& operator= ( const Matrix<T>& S );
79    operator Matrix<T>() const;
80    T operator[] ( int i ) const;
81    T& operator[] ( int i );
82    friend class Matrix<T>;
83};
84
85#ifndef NOSTREAMIO
86template <class T>
87ostream & operator<< ( ostream & s, const Matrix<T>& M );
88#endif /* NOSTREAMIO */
89
90#endif /* ! INCL_MATRIX_H */
Note: See TracBrowser for help on using the repository browser.