source: git/factory/templates/ftmpl_matrix.h @ dce1e3

spielwiese
Last change on this file since dce1e3 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 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$ */
3
4#ifndef INCL_MATRIX_H
5#define INCL_MATRIX_H
6
7#include <factoryconf.h>
8
9#ifndef NOSTREAMIO
10#ifdef HAVE_IOSTREAM
11#include <iostream>
12#define OSTREAM std::ostream
13#elif defined(HAVE_IOSTREAM_H)
14#include <iostream.h>
15#define OSTREAM ostream
16#endif
17#endif /* NOSTREAMIO */
18
19template <class T>
20class SubMatrix;
21
22template <class T>
23class Matrix;
24
25#ifndef NOSTREAMIO
26template <class T>
27OSTREAM& operator<< (OSTREAM &, const Matrix<T> &);
28#endif
29
30template <class T>
31class Matrix
32{
33private:
34    int NR, NC;
35    T ** elems;
36#ifndef NOSTREAMIO
37    void printrow ( OSTREAM & s, int i ) const;
38#endif /* NOSTREAMIO */
39    typedef T* T_ptr;
40public:
41    Matrix() : NR(0), NC(0), elems(0) {}
42    Matrix( int nr, int nc );
43    Matrix( const Matrix<T>& M );
44    ~Matrix();
45    Matrix<T>& operator= ( const Matrix<T>& M );
46    int rows() const { return NR; }
47    int columns() const { return NC; }
48    SubMatrix<T> operator[] ( int i );
49    const SubMatrix<T> operator[] ( int i ) const;
50    T& operator() ( int row, int col );
51    T operator() ( int row, int col ) const;
52    SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax );
53    const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const;
54    void swapRow( int i, int j );
55    void swapColumn( int i, int j );
56#ifndef NOSTREAMIO
57    void print( OSTREAM& s ) const;
58    friend OSTREAM & operator<< <T>( OSTREAM & s, const Matrix<T>& M );
59#endif /* NOSTREAMIO */
60    friend class SubMatrix<T>;
61};
62    template <class T>
63    Matrix<T> operator+ ( const Matrix<T>& lhs, const Matrix<T>& rhs );
64    template <class T>
65    Matrix<T> operator- ( const Matrix<T>& lhs, const Matrix<T>& rhs );
66    template <class T>
67    Matrix<T> operator* ( const Matrix<T>& lhs, const Matrix<T>& rhs );
68    template <class T>
69    Matrix<T> operator* ( const Matrix<T>& lhs, const T& rhs );
70    template <class T>
71    Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs );
72
73template <class T>
74class SubMatrix
75{
76private:
77    int r_min, r_max, c_min, c_max;
78    Matrix<T>& M;
79    // we do not provide a default ctor, so nobody can declare an empty SubMatrix
80    SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m );
81public:
82    SubMatrix( const SubMatrix<T> & S );
83    SubMatrix<T>& operator= ( const SubMatrix<T>& S );
84    SubMatrix<T>& operator= ( const Matrix<T>& S );
85    operator Matrix<T>() const;
86    T operator[] ( int i ) const;
87    T& operator[] ( int i );
88    friend class Matrix<T>;
89};
90
91#ifndef NOSTREAMIO
92template <class T>
93OSTREAM & operator<< ( OSTREAM & s, const Matrix<T>& M );
94#endif /* NOSTREAMIO */
95
96#endif /* ! INCL_MATRIX_H */
Note: See TracBrowser for help on using the repository browser.