source: git/ntl/doc/matrix.txt @ 6ce030f

spielwiese
Last change on this file since 6ce030f was e6caf81, checked in by Hans Schönemann <hannes@…>, 20 years ago
*hannes: 5.3.2 git-svn-id: file:///usr/local/Singular/svn/trunk@7472 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.4 KB
Line 
1
2/**************************************************************************\
3
4MODULE: matrix
5
6SUMMARY:
7
8Macros are deined providing template-like classes for dynamic-sized,
9recatngular matrices.
10
11The macro NTL_matrix_decl(T,vec_T,vec_vec_T,mat_T) declares a new class
12mat_T representing matrices over T, where vec_T and vec_vec_T are
13classes representing "NTL vectors" over T and vec_T, respectively.
14
15The implementation of mat_T can be instantiated with
16NTL_matrix_impl(T,vec_T,vec_vec_T,mat_T).
17
18If T supports I/O and/or equluality testing, then mat_T
19can also be made to support these.
20
21For example, the declaration
22
23   mat_T M;
24
25creates a 0 x 0 matrix.  We can make it have 10 rows and 20 columns like this:
26
27   M.SetDims(10, 20);
28
29A row can be accessed as M[i], indexing from 0, or as M(i), indexing from 1.
30A matrix entry can be accessed as M[i][j], indexing from 0, or as
31M(i, j), indexing from 1.
32
33A matrix is represented as a vec_vec_T: a vector of rows, where
34each row is a vec_T.  Any attempt to resize one of the rows so
35as to create a non-rectangular matrix will result in a run-time
36error.
37
38The dimensions of an existing matrix may be changed.  If the number of
39columns does not change, then the matrix is just "resized" like a vector,
40and no information is lost.  Otherwise, if the number of columns changes,
41the matrix is completely destroyed, and a new matrix is created
42
43
44\**************************************************************************/
45
46class mat_T {
47   mat_T(); // initially 0 x 0
48
49   mat_T(const mat_T& a);
50   mat_T& operator=(const mat_T& a);
51   ~mat_T();
52
53   mat_T(INIT_SIZE_TYPE, long n, long m);
54   // mat_T(INIT_SIZE, n, m) initializes an n x m matrix, invoking
55   // the default constructor for T to initialize entries.
56
57   void SetDims(long n, long m);
58   // M.SetDims(n, m) makes M have dimension n x m.  If the number of
59   // columns (m) changes, previous storage is freed, and space for M
60   // is reallocated and initialized; otherwise, more rows are
61   // allocated as necessary (when number of rows increases),
62   // excess rows are retained (when number of rows decreases),
63   // and--importantly--the contents do not change.
64
65   void kill(); free storage and make 0 x 0
66
67   long NumRows() const;
68   // M.NumRows() returns the number of rows of M
69
70   long NumCols() const;
71   // M.NumCols() returns the number of columns of M
72
73   vec_T& operator[](long i);
74   const vec_T& operator[](long i) const;
75   // access row i, initial index 0.  Any attempt to change the length
76   // of this row will raise an error.
77
78   vec_T& operator()(long i);
79   const vec_T& operator()(long i) const;
80   // access row i, initial index 1.  Any attempt to change the length
81   // of this row will raise an error.
82
83   T& operator()(long i, long j);
84   const T& operator()(long i, long j) const;
85   // access element (i, j), both indices starting at 1
86
87   long position(const vec_T& a) const;
88   // returns index of a in matrix, or -1 if not present;
89   // equivalent to rep(*this).position(a).
90
91
92   long position1(const vec_T& a) const;
93   // returns index of a in matrix, or -1 if not present;
94   // equivalent to rep(*this).position1(a).
95
96
97};
98
99const vec_vec_T& rep(const mat_T& a);
100// read-only access to underlying representation
101
102void swap(mat_T& X, mat_T& Y);
103// swaps X and Y (by swapping pointers)
104
105void MakeMatrix(mat_T& x, const vec_vec_T& a);
106// copies a to x, checking that it is "rectangular"
107
108/**************************************************************************\
109
110                            Input/Output
111
112The I/O operators can be declared with
113NTL_io_matrix_decl(T,vec_T,vec_vec_T,mat_T), and
114implemented using NTL_io_matrix_impl(T,vec_T,vec_vec_T,mat_T). 
115I/O is implemented using the underlying I/O operators for vec_vec_T.
116
117\**************************************************************************/
118
119
120istream& operator>>(istream&, mat_T&);
121ostream& operator<<(ostream&, const mat_T&);
122
123/**************************************************************************\
124
125                              Equality Testing
126
127The equality testing operators == and != can be declared
128NTL_eq_matrix_decl(T,vec_T,vec_vec_T,mat_T), and
129implemented using NTL_eq_matrix_impl(T,vec_T,vec_vec_T,mat_T). 
130Equality testing is implemented using the underlying
131equality operators for vec_vec_T.
132
133
134\**************************************************************************/
135
136
137long operator==(const mat_T& a, const mat_T& b);
138long operator!=(const mat_T& a, const mat_T& b);
139
Note: See TracBrowser for help on using the repository browser.