GNU Octave  4.2.1
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-2017 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 "octave-config.h"
29 
30 #include "DiagArray2.h"
31 #include "MArray.h"
32 
33 template <typename T> class MDiagArray2;
34 
35 template <typename T> MDiagArray2<T> operator + (const MDiagArray2<T>&);
36 template <typename T> MDiagArray2<T> operator - (const MDiagArray2<T>&);
37 template <typename T> MDiagArray2<T> operator * (const MDiagArray2<T>&,
38  const T&);
39 template <typename T> MDiagArray2<T> operator / (const MDiagArray2<T>&,
40  const T&);
41 template <typename T> MDiagArray2<T> operator * (const T&,
42  const MDiagArray2<T>&);
43 template <typename T> MDiagArray2<T> operator + (const MDiagArray2<T>&,
44  const MDiagArray2<T>&);
45 template <typename T> MDiagArray2<T> operator - (const MDiagArray2<T>&,
46  const MDiagArray2<T>&);
47 template <typename T> MDiagArray2<T> product (const MDiagArray2<T>&,
48  const MDiagArray2<T>&);
49 
50 //! Template for two dimensional diagonal array with math operators.
51 template <typename T>
52 class
54 {
55 public:
56 
57  MDiagArray2 (void) : DiagArray2<T> () { }
58 
60 
62  : DiagArray2<T> (r, c, val) { }
63 
64  MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { }
65 
66  MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { }
67 
68  template <typename U>
69  MDiagArray2 (const DiagArray2<U>& a) : DiagArray2<T> (a) { }
70 
71  explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { }
72 
74  : DiagArray2<T> (a, r, c) { }
75 
76  ~MDiagArray2 (void) { }
77 
79  {
81  return *this;
82  }
83 
85  {
87  }
88 
89  octave_idx_type nnz (void) const
90  {
92 
93  const T *d = this->data ();
94 
95  octave_idx_type nel = this->length ();
96 
97  for (octave_idx_type i = 0; i < nel; i++)
98  {
99  if (d[i] != T ())
100  retval++;
101  }
102 
103  return retval;
104  }
105 
107  { return DiagArray2<T>::extract_diag (k); }
108 
110  MDiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const
111  { return DiagArray2<T>::hermitian (fcn); }
112 
113  bool is_multiple_of_identity (T val) const;
114 
115  // Currently, the OPS functions don't need to be friends, but that
116  // may change.
117 
118  friend MDiagArray2<T> operator + <> (const MDiagArray2<T>&);
119  friend MDiagArray2<T> operator - <> (const MDiagArray2<T>&);
120  friend MDiagArray2<T> operator * <> (const MDiagArray2<T>&, const T&);
121  friend MDiagArray2<T> operator / <> (const MDiagArray2<T>&, const T&);
122  friend MDiagArray2<T> operator * <> (const T&, const MDiagArray2<T>&);
123  friend MDiagArray2<T> operator + <> (const MDiagArray2<T>&,
124  const MDiagArray2<T>&);
125  friend MDiagArray2<T> operator - <> (const MDiagArray2<T>&,
126  const MDiagArray2<T>&);
127  friend MDiagArray2<T> product <> (const MDiagArray2<T>&,
128  const MDiagArray2<T>&);
129 
130 };
131 
132 #define MDIAGARRAY2_FORWARD_DEFS(B, R, T) \
133  inline R \
134  operator + (const R& x) \
135  { \
136  return R (operator + (dynamic_cast<const B<T>&> (x))); \
137  } \
138  inline R \
139  operator - (const R& x) \
140  { \
141  return R (operator - (dynamic_cast<const B<T>&> (x))); \
142  } \
143  inline R \
144  operator * (const R& x, const T& y) \
145  { \
146  return R (operator * (dynamic_cast<const B<T>&> (x), (y))); \
147  } \
148  inline R \
149  operator / (const R& x, const T& y) \
150  { \
151  return R (operator / (dynamic_cast<const B<T>&> (x), (y))); \
152  } \
153  inline R \
154  operator * (const T& x, const R& y) \
155  { \
156  return R (operator * ( (x), dynamic_cast<const B<T>&> (y))); \
157  } \
158  inline R \
159  operator + (const R& x, const R& y) \
160  { \
161  return R (operator + (dynamic_cast<const B<T>&> (x), \
162  dynamic_cast<const B<T>&> (y))); \
163  } \
164  inline R \
165  operator - (const R& x, const R& y) \
166  { \
167  return R (operator - (dynamic_cast<const B<T>&> (x), \
168  dynamic_cast<const B<T>&> (y))); \
169  } \
170  inline R \
171  product (const R& x, const R& y) \
172  { \
173  return R (product (dynamic_cast<const B<T>&> (x), \
174  dynamic_cast<const B<T>&> (y))); \
175  }
176 
177 #endif
MDiagArray2< T > hermitian(T(*fcn)(const T &)=0) const
Definition: MDiagArray2.h:110
MDiagArray2< T > product(const MDiagArray2< T > &, const MDiagArray2< T > &)
Definition: MDiagArray2.cc:91
octave_idx_type nnz(void) const
Definition: MDiagArray2.h:89
MDiagArray2(const DiagArray2< U > &a)
Definition: MDiagArray2.h:69
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
MDiagArray2< T > operator*(const MDiagArray2< T > &, const T &)
Definition: MDiagArray2.cc:63
MDiagArray2< T > & operator=(const MDiagArray2< T > &a)
Definition: MDiagArray2.h:78
MDiagArray2(const Array< T > &a)
Definition: MDiagArray2.h:71
for large enough k
Definition: lu.cc:606
Array< T > extract_diag(octave_idx_type k=0) const
Definition: DiagArray2.cc:58
const T * data(void) const
Definition: DiagArray2.h:176
MDiagArray2< T > operator-(const MDiagArray2< T > &)
Definition: MDiagArray2.cc:104
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:32
DiagArray2< T > hermitian(T(*fcn)(const T &)=0) const
Definition: DiagArray2.cc:84
MDiagArray2(octave_idx_type r, octave_idx_type c, const T &val)
Definition: MDiagArray2.h:61
octave_function * fcn
Definition: ov-class.cc:1743
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
octave_value retval
Definition: data.cc:6294
Template for two dimensional diagonal array with math operators.
Definition: MDiagArray2.h:33
DiagArray2< T > & operator=(const DiagArray2< T > &a)
Definition: DiagArray2.h:73
MDiagArray2< T > operator/(const MDiagArray2< T > &, const T &)
Definition: MDiagArray2.cc:64
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
MDiagArray2(octave_idx_type r, octave_idx_type c)
Definition: MDiagArray2.h:59
MDiagArray2(void)
Definition: MDiagArray2.h:57
MArray< T > diag(octave_idx_type k=0) const
Definition: MDiagArray2.h:106
MDiagArray2(const DiagArray2< T > &a)
Definition: MDiagArray2.h:66
Array< T > array_value(void) const
Definition: DiagArray2.cc:124
MArray< T > array_value() const
Definition: MDiagArray2.h:84
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:126
bool is_multiple_of_identity(T val) const
Definition: MDiagArray2.cc:34
MDiagArray2(const Array< T > &a, octave_idx_type r, octave_idx_type c)
Definition: MDiagArray2.h:73
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
MDiagArray2< T > operator+(const MDiagArray2< T > &)
Definition: MDiagArray2.cc:97
DiagArray2< T > transpose(void) const
Definition: DiagArray2.cc:77
MDiagArray2< T > transpose(void) const
Definition: MDiagArray2.h:109
~MDiagArray2(void)
Definition: MDiagArray2.h:76
MDiagArray2(const MDiagArray2< T > &a)
Definition: MDiagArray2.h:64