1993
|
1 // Template array classes with like-type math ops |
1988
|
2 /* |
|
3 |
7017
|
4 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2007 |
|
5 John W. Eaton |
1988
|
6 |
|
7 This file is part of Octave. |
|
8 |
|
9 Octave is free software; you can redistribute it and/or modify it |
|
10 under the terms of the GNU General Public License as published by the |
7016
|
11 Free Software Foundation; either version 3 of the License, or (at your |
|
12 option) any later version. |
1988
|
13 |
|
14 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
17 for more details. |
|
18 |
|
19 You should have received a copy of the GNU General Public License |
7016
|
20 along with Octave; see the file COPYING. If not, see |
|
21 <http://www.gnu.org/licenses/>. |
1988
|
22 |
|
23 */ |
|
24 |
|
25 #if !defined (octave_MDiagArray2_h) |
|
26 #define octave_MDiagArray2_h 1 |
|
27 |
|
28 #include "DiagArray2.h" |
|
29 #include "MArray2.h" |
|
30 |
3580
|
31 // Two dimensional diagonal array with math ops. |
3107
|
32 |
3580
|
33 // But first, some preprocessor abuse... |
3107
|
34 |
3580
|
35 #include "MArray-defs.h" |
3107
|
36 |
6708
|
37 MDIAGARRAY2_OPS_FORWARD_DECLS (MDiagArray2, ) |
1988
|
38 |
|
39 template <class T> |
3585
|
40 class |
|
41 MDiagArray2 : public DiagArray2<T> |
1988
|
42 { |
|
43 protected: |
|
44 |
5275
|
45 MDiagArray2 (T *d, octave_idx_type r, octave_idx_type c) : DiagArray2<T> (d, r, c) { } |
1988
|
46 |
|
47 public: |
|
48 |
|
49 MDiagArray2 (void) : DiagArray2<T> () { } |
3585
|
50 |
5275
|
51 MDiagArray2 (octave_idx_type r, octave_idx_type c) : DiagArray2<T> (r, c) { } |
3585
|
52 |
5275
|
53 MDiagArray2 (octave_idx_type r, octave_idx_type c, const T& val) : DiagArray2<T> (r, c, val) { } |
3585
|
54 |
|
55 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { } |
|
56 |
1988
|
57 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { } |
3585
|
58 |
|
59 explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { } |
1988
|
60 |
|
61 ~MDiagArray2 (void) { } |
|
62 |
|
63 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) |
|
64 { |
|
65 DiagArray2<T>::operator = (a); |
|
66 return *this; |
|
67 } |
|
68 |
|
69 operator MArray2<T> () const |
|
70 { |
5275
|
71 octave_idx_type nr = DiagArray2<T>::dim1 (); |
|
72 octave_idx_type nc = DiagArray2<T>::dim2 (); |
1988
|
73 |
4513
|
74 MArray2<T> retval (nr, nc, T (0)); |
|
75 |
5275
|
76 octave_idx_type len = nr < nc ? nr : nc; |
1988
|
77 |
5275
|
78 for (octave_idx_type i = 0; i < len; i++) |
4645
|
79 retval.xelem (i, i) = this->xelem (i, i); |
1988
|
80 |
|
81 return retval; |
|
82 } |
|
83 |
4187
|
84 static MDiagArray2<T> nil_array; |
|
85 |
3580
|
86 // Currently, the OPS functions don't need to be friends, but that |
|
87 // may change. |
1988
|
88 |
3610
|
89 // MDIAGARRAY2_OPS_FRIEND_DECLS (MDiagArray2) |
3580
|
90 |
|
91 }; |
1988
|
92 |
|
93 #endif |
|
94 |
|
95 /* |
|
96 ;;; Local Variables: *** |
|
97 ;;; mode: C++ *** |
|
98 ;;; End: *** |
|
99 */ |