GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
dDiagMatrix.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_dDiagMatrix_h)
27 #define octave_dDiagMatrix_h 1
28 
29 #include "octave-config.h"
30 
31 #include "DET.h"
32 #include "MDiagArray2.h"
33 #include "dColVector.h"
34 #include "dRowVector.h"
35 #include "mx-defs.h"
36 
37 class
40 {
41 public:
42 
44 
45  DiagMatrix () = default;
46 
47  DiagMatrix (const DiagMatrix& a) = default;
48 
49  DiagMatrix& operator = (const DiagMatrix& a) = default;
50 
51  ~DiagMatrix () = default;
52 
54  : MDiagArray2<double> (r, c) { }
55 
57  : MDiagArray2<double> (r, c, val) { }
58 
59  DiagMatrix (const MDiagArray2<double>& a) : MDiagArray2<double> (a) { }
60 
61  template <typename U>
62  DiagMatrix (const DiagArray2<U>& a) : MDiagArray2<double> (a) { }
63 
64  explicit DiagMatrix (const Array<double>& a) : MDiagArray2<double> (a) { }
65 
67  : MDiagArray2<double> (a, r, c) { }
68 
69  OCTAVE_API bool operator == (const DiagMatrix& a) const;
70  OCTAVE_API bool operator != (const DiagMatrix& a) const;
71 
72  OCTAVE_API DiagMatrix& fill (double val);
74  fill (double val, octave_idx_type beg, octave_idx_type end);
75  OCTAVE_API DiagMatrix& fill (const ColumnVector& a);
76  OCTAVE_API DiagMatrix& fill (const RowVector& a);
77  OCTAVE_API DiagMatrix& fill (const ColumnVector& a, octave_idx_type beg);
78  OCTAVE_API DiagMatrix& fill (const RowVector& a, octave_idx_type beg);
79 
81  { return MDiagArray2<double>::transpose (); }
82  DiagMatrix abs () const;
83 
84  friend OCTAVE_API DiagMatrix real (const ComplexDiagMatrix& a);
85  friend OCTAVE_API DiagMatrix imag (const ComplexDiagMatrix& a);
86 
87  // resize is the destructive analog for this one
88 
90  extract (octave_idx_type r1, octave_idx_type c1,
91  octave_idx_type r2, octave_idx_type c2) const;
92 
93  // extract row or column i.
94 
95  OCTAVE_API RowVector row (octave_idx_type i) const;
96  OCTAVE_API RowVector row (char *s) const;
97 
98  OCTAVE_API ColumnVector column (octave_idx_type i) const;
99  OCTAVE_API ColumnVector column (char *s) const;
100 
101  OCTAVE_API DiagMatrix inverse () const;
102  OCTAVE_API DiagMatrix inverse (octave_idx_type& info) const;
103  OCTAVE_API DiagMatrix pseudo_inverse (double tol = 0.0) const;
104 
105  // other operations
106 
108  { return MDiagArray2<double>::extract_diag (k); }
109 
110  OCTAVE_API DET determinant () const;
111  OCTAVE_API double rcond () const;
112 
113  // i/o
114 
115  friend OCTAVE_API std::ostream&
116  operator << (std::ostream& os, const DiagMatrix& a);
117 
118 };
119 
122 
123 // diagonal matrix by diagonal matrix -> diagonal matrix operations
124 
126 operator * (const DiagMatrix& a, const DiagMatrix& b);
127 
129 
130 #endif
template std::ostream & operator<<(std::ostream &, const Array< bool > &)
#define MDIAGARRAY2_FORWARD_DEFS(B, R, T)
Definition: MDiagArray2.h:132
Array< T > extract_diag(octave_idx_type k=0) const
Definition: DiagArray2.cc:50
DiagMatrix(octave_idx_type r, octave_idx_type c)
Definition: dDiagMatrix.h:53
DiagMatrix(const Array< double > &a)
Definition: dDiagMatrix.h:64
DiagMatrix(const Array< double > &a, octave_idx_type r, octave_idx_type c)
Definition: dDiagMatrix.h:66
DiagMatrix transpose() const
Definition: dDiagMatrix.h:80
DiagMatrix(const MDiagArray2< double > &a)
Definition: dDiagMatrix.h:59
DiagMatrix(const DiagMatrix &a)=default
~DiagMatrix()=default
ColumnVector extract_diag(octave_idx_type k=0) const
Definition: dDiagMatrix.h:107
DiagMatrix(octave_idx_type r, octave_idx_type c, double val)
Definition: dDiagMatrix.h:56
Matrix full_matrix_type
Definition: dDiagMatrix.h:43
DiagMatrix()=default
DiagMatrix(const DiagArray2< U > &a)
Definition: dDiagMatrix.h:62
MDiagArray2< T > transpose() const
Definition: MDiagArray2.h:106
Definition: dMatrix.h:42
Definition: DET.h:39
DiagMatrix real(const ComplexDiagMatrix &a)
Definition: dDiagMatrix.cc:134
DiagMatrix imag(const ComplexDiagMatrix &a)
Definition: dDiagMatrix.cc:140
DiagMatrix operator*(const DiagMatrix &a, const DiagMatrix &b)
Definition: dDiagMatrix.cc:304
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:536
bool operator==(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:520
#define OCTAVE_API
Definition: main.cc:55
T * r
Definition: mx-inlines.cc:781
template int8_t abs(int8_t)