GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
MDiagArray2.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
4 Copyright (C) 2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_MDiagArray2_h)
25 #define octave_MDiagArray2_h 1
26 
27 #include "octave-config.h"
28 
29 #include "DiagArray2.h"
30 #include "MArray.h"
31 
32 template <typename T> class MDiagArray2;
33 
34 template <typename T> MDiagArray2<T> operator + (const MDiagArray2<T>&);
35 template <typename T> MDiagArray2<T> operator - (const MDiagArray2<T>&);
36 template <typename T> MDiagArray2<T> operator * (const MDiagArray2<T>&,
37  const T&);
38 template <typename T> MDiagArray2<T> operator / (const MDiagArray2<T>&,
39  const T&);
40 template <typename T> MDiagArray2<T> operator * (const T&,
41  const MDiagArray2<T>&);
42 template <typename T> MDiagArray2<T> operator + (const MDiagArray2<T>&,
43  const MDiagArray2<T>&);
44 template <typename T> MDiagArray2<T> operator - (const MDiagArray2<T>&,
45  const MDiagArray2<T>&);
46 template <typename T> MDiagArray2<T> product (const MDiagArray2<T>&,
47  const MDiagArray2<T>&);
48 
49 //! Template for two dimensional diagonal array with math operators.
50 template <typename T>
51 class
53 {
54 public:
55 
56  MDiagArray2 (void) : DiagArray2<T> () { }
57 
59 
61  : DiagArray2<T> (r, c, val) { }
62 
63  MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { }
64 
65  MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { }
66 
67  template <typename U>
68  MDiagArray2 (const DiagArray2<U>& a) : DiagArray2<T> (a) { }
69 
70  explicit MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { }
71 
73  : DiagArray2<T> (a, r, c) { }
74 
75  ~MDiagArray2 (void) = default;
76 
78  {
80  return *this;
81  }
82 
84  {
86  }
87 
88  octave_idx_type nnz (void) const
89  {
90  const T *d = this->data ();
91 
92  octave_idx_type nel = this->length ();
93 
94  const T zero = T ();
95 
96  return std::count_if (d, d + nel,
97  [zero] (T elem) { return elem != zero; });
98  }
99 
101  { return DiagArray2<T>::extract_diag (k); }
102 
104  MDiagArray2<T> hermitian (T (*fcn) (const T&) = nullptr) const
105  { return DiagArray2<T>::hermitian (fcn); }
106 
107  bool is_multiple_of_identity (T val) const;
108 
109  // Currently, the OPS functions don't need to be friends, but that
110  // may change.
111 
112  friend MDiagArray2<T> operator + <> (const MDiagArray2<T>&);
113  friend MDiagArray2<T> operator - <> (const MDiagArray2<T>&);
114  friend MDiagArray2<T> operator * <> (const MDiagArray2<T>&, const T&);
115  friend MDiagArray2<T> operator / <> (const MDiagArray2<T>&, const T&);
116  friend MDiagArray2<T> operator * <> (const T&, const MDiagArray2<T>&);
117  friend MDiagArray2<T> operator + <> (const MDiagArray2<T>&,
118  const MDiagArray2<T>&);
119  friend MDiagArray2<T> operator - <> (const MDiagArray2<T>&,
120  const MDiagArray2<T>&);
121  friend MDiagArray2<T> product <> (const MDiagArray2<T>&,
122  const MDiagArray2<T>&);
123 
124 };
125 
126 #define MDIAGARRAY2_FORWARD_DEFS(B, R, T) \
127  inline R \
128  operator + (const R& x) \
129  { \
130  return R (operator + (dynamic_cast<const B<T>&> (x))); \
131  } \
132  inline R \
133  operator - (const R& x) \
134  { \
135  return R (operator - (dynamic_cast<const B<T>&> (x))); \
136  } \
137  inline R \
138  operator * (const R& x, const T& y) \
139  { \
140  return R (operator * (dynamic_cast<const B<T>&> (x), (y))); \
141  } \
142  inline R \
143  operator / (const R& x, const T& y) \
144  { \
145  return R (operator / (dynamic_cast<const B<T>&> (x), (y))); \
146  } \
147  inline R \
148  operator * (const T& x, const R& y) \
149  { \
150  return R (operator * ( (x), dynamic_cast<const B<T>&> (y))); \
151  } \
152  inline R \
153  operator + (const R& x, const R& y) \
154  { \
155  return R (operator + (dynamic_cast<const B<T>&> (x), \
156  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  product (const R& x, const R& y) \
166  { \
167  return R (product (dynamic_cast<const B<T>&> (x), \
168  dynamic_cast<const B<T>&> (y))); \
169  }
170 
171 #endif
MDiagArray2< T > product(const MDiagArray2< T > &, const MDiagArray2< T > &)
Definition: MDiagArray2.cc:91
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:32
MDiagArray2(octave_idx_type r, octave_idx_type c)
Definition: MDiagArray2.h:58
MDiagArray2(octave_idx_type r, octave_idx_type c, const T &val)
Definition: MDiagArray2.h:60
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
MDiagArray2< T > operator*(const MDiagArray2< T > &, const T &)
Definition: MDiagArray2.cc:63
~MDiagArray2(void)=default
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by zero($0/0$)
for large enough k
Definition: lu.cc:617
DiagArray2< T > transpose(void) const
Definition: DiagArray2.cc:69
bool is_multiple_of_identity(T val) const
Definition: MDiagArray2.cc:34
MDiagArray2< T > operator-(const MDiagArray2< T > &)
Definition: MDiagArray2.cc:104
octave_idx_type nnz(void) const
Definition: MDiagArray2.h:88
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
octave_function * fcn
Definition: ov-class.cc:1754
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
DiagArray2< T > hermitian(T(*fcn)(const T &)=nullptr) const
Definition: DiagArray2.cc:76
Template for two dimensional diagonal array with math operators.
Definition: MDiagArray2.h:32
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:400
static int elem
Definition: __contourc__.cc:47
MArray< T > diag(octave_idx_type k=0) const
Definition: MDiagArray2.h:100
DiagArray2< T > & operator=(const DiagArray2< T > &a)
Definition: DiagArray2.h:72
MDiagArray2< T > operator/(const MDiagArray2< T > &, const T &)
Definition: MDiagArray2.cc:64
MDiagArray2< T > & operator=(const MDiagArray2< T > &a)
Definition: MDiagArray2.h:77
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
MDiagArray2< T > transpose(void) const
Definition: MDiagArray2.h:103
MDiagArray2(const Array< T > &a)
Definition: MDiagArray2.h:70
Array< T > extract_diag(octave_idx_type k=0) const
Definition: DiagArray2.cc:50
MArray< T > array_value() const
Definition: MDiagArray2.h:83
MDiagArray2(const DiagArray2< T > &a)
Definition: MDiagArray2.h:65
MDiagArray2(void)
Definition: MDiagArray2.h:56
MDiagArray2(const MDiagArray2< T > &a)
Definition: MDiagArray2.h:63
MDiagArray2< T > operator+(const MDiagArray2< T > &)
Definition: MDiagArray2.cc:97
MDiagArray2< T > hermitian(T(*fcn)(const T &)=nullptr) const
Definition: MDiagArray2.h:104
Array< T > array_value(void) const
Definition: DiagArray2.cc:116
MDiagArray2(const Array< T > &a, octave_idx_type r, octave_idx_type c)
Definition: MDiagArray2.h:72
const T * data(void) const
Definition: DiagArray2.h:167
MDiagArray2(const DiagArray2< U > &a)
Definition: MDiagArray2.h:68