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

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