GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MDiagArray2.h
Go to the documentation of this file.
1 // Template array classes with like-type math ops
2 /*
3 
4 Copyright (C) 1996-2013 John W. Eaton
5 Copyright (C) 2010 VZLU Prague
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
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
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
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if !defined (octave_MDiagArray2_h)
26 #define octave_MDiagArray2_h 1
27 
28 #include "DiagArray2.h"
29 #include "MArray.h"
30 
31 // Two dimensional diagonal array with math ops.
32 
33 // But first, some preprocessor abuse...
34 
35 #include "MArray-decl.h"
36 
38 
39 template <class T>
40 class
41 MDiagArray2 : public DiagArray2<T>
42 {
43 public:
44 
45  MDiagArray2 (void) : DiagArray2<T> () { }
46 
48 
50  : DiagArray2<T> (r, c, val) { }
51 
52  MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { }
53 
54  MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { }
55 
56  template <class U>
57  MDiagArray2 (const DiagArray2<U>& a) : DiagArray2<T> (a) { }
58 
59  explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { }
60 
62  : DiagArray2<T> (a, r, c) { }
63 
64  ~MDiagArray2 (void) { }
65 
67  {
69  return *this;
70  }
71 
73  {
75  }
76 
77  octave_idx_type nnz (void) const
78  {
79  octave_idx_type retval = 0;
80 
81  const T *d = this->data ();
82 
83  octave_idx_type nel = this->length ();
84 
85  for (octave_idx_type i = 0; i < nel; i++)
86  {
87  if (d[i] != T ())
88  retval++;
89  }
90 
91  return retval;
92  }
93 
95  { return DiagArray2<T>::extract_diag (k); }
96 
98  MDiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const
99  { return DiagArray2<T>::hermitian (fcn); }
100 
101  bool is_multiple_of_identity (T val) const;
102 
103  // Currently, the OPS functions don't need to be friends, but that
104  // may change.
105 
107 
108 };
109 
110 #endif