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
DiagArray2.h
Go to the documentation of this file.
1 // Template array classes
2 /*
3 
4 Copyright (C) 1996-2017 John W. Eaton
5 Copyright (C) 2008-2009 Jaroslav Hajek
6 Copyright (C) 2010 VZLU Prague
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 the
12 Free Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
14 
15 Octave is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 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 <http://www.gnu.org/licenses/>.
23 
24 */
25 
26 #if ! defined (octave_DiagArray2_h)
27 #define octave_DiagArray2_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cassert>
32 #include <cstdlib>
33 
34 #include "Array.h"
35 
36 // Array<T> is inherited privately so that some methods, like index, don't
37 // produce unexpected results.
38 
39 template <typename T>
40 class
41 DiagArray2 : protected Array<T>
42 {
43 protected:
45 
46 public:
47 
48  using typename Array<T>::element_type;
49 
50  DiagArray2 (void)
51  : Array<T> (), d1 (0), d2 (0) { }
52 
54  : Array<T> (dim_vector (std::min (r, c), 1)), d1 (r), d2 (c) { }
55 
57  : Array<T> (dim_vector (std::min (r, c), 1), val), d1 (r), d2 (c) { }
58 
59  explicit DiagArray2 (const Array<T>& a)
60  : Array<T> (a.as_column ()), d1 (a.numel ()), d2 (a.numel ()) { }
61 
63 
65  : Array<T> (a), d1 (a.d1), d2 (a.d2) { }
66 
67  template <typename U>
69  : Array<T> (a.extract_diag ()), d1 (a.dim1 ()), d2 (a.dim2 ()) { }
70 
71  ~DiagArray2 (void) { }
72 
74  {
75  if (this != &a)
76  {
78  d1 = a.d1;
79  d2 = a.d2;
80  }
81 
82  return *this;
83  }
84 
85  octave_idx_type dim1 (void) const { return d1; }
86  octave_idx_type dim2 (void) const { return d2; }
87 
88  octave_idx_type rows (void) const { return dim1 (); }
89  octave_idx_type cols (void) const { return dim2 (); }
90  octave_idx_type columns (void) const { return dim2 (); }
91 
92  octave_idx_type diag_length (void) const { return Array<T>::numel (); }
93  // FIXME: a dangerous ambiguity?
94  octave_idx_type length (void) const { return Array<T>::numel (); }
95  octave_idx_type nelem (void) const { return dim1 () * dim2 (); }
96  octave_idx_type numel (void) const { return nelem (); }
97 
98  size_t byte_size (void) const { return Array<T>::byte_size (); }
99 
100  dim_vector dims (void) const { return dim_vector (d1, d2); }
101 
102  OCTAVE_DEPRECATED ("use 'extract_diag' instead")
103  Array<T> diag (octave_idx_type k = 0) const;
104 
105  Array<T> extract_diag (octave_idx_type k = 0) const;
106  DiagArray2<T> build_diag_matrix () const
107  {
108  return DiagArray2<T> (array_value ());
109  }
110 
111  // Warning: the non-const two-index versions will silently ignore assignments
112  // to off-diagonal elements.
113 
115  {
116  return (r == c) ? Array<T>::elem (r) : T (0);
117  }
118 
120 
122  { return Array<T>::elem (i); }
123 
125  { return Array<T>::elem (i); }
126 
128  {
129  return check_idx (r, c) ? elem (r, c) : T (0);
130  }
131 
133  {
134 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
135  return checkelem (r, c);
136 #else
137  return elem (r, c);
138 #endif
139  }
140 
142 
144  {
145 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
146  return checkelem (r, c);
147 #else
148  return elem (r, c);
149 #endif
150  }
151 
152  // No checking.
153 
155  {
156  return (r == c) ? Array<T>::xelem (r) : T (0);
157  }
158 
160  { return Array<T>::xelem (i); }
161 
163  { return Array<T>::xelem (i); }
164 
165  void resize (octave_idx_type n, octave_idx_type m, const T& rfv);
167  {
169  }
170 
171  DiagArray2<T> transpose (void) const;
172  DiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const;
173 
174  Array<T> array_value (void) const;
175 
176  const T *data (void) const { return Array<T>::data (); }
177 
178  const T *fortran_vec (void) const { return Array<T>::fortran_vec (); }
179 
180  T *fortran_vec (void) { return Array<T>::fortran_vec (); }
181 
182  void print_info (std::ostream& os, const std::string& prefix) const
183  { Array<T>::print_info (os, prefix); }
184 
185 private:
186 
187  bool check_idx (octave_idx_type r, octave_idx_type c) const;
188 };
189 
190 #endif
const T * fortran_vec(void) const
Definition: DiagArray2.h:178
DiagArray2(const DiagArray2< T > &a)
Definition: DiagArray2.h:64
T elem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:114
octave_idx_type dim1(void) const
Definition: DiagArray2.h:85
dim_vector dims(void) const
Definition: DiagArray2.h:100
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
size_t byte_size(void) const
Definition: DiagArray2.h:98
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
DiagArray2(const DiagArray2< U > &a)
Definition: DiagArray2.h:68
SparseBoolMatrix & operator=(const SparseBoolMatrix &a)
Definition: boolSparse.h:82
for large enough k
Definition: lu.cc:606
DiagArray2(octave_idx_type r, octave_idx_type c)
Definition: DiagArray2.h:53
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:382
T checkelem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:127
octave_idx_type nelem(void) const
Definition: Sparse.h:263
~DiagArray2(void)
Definition: DiagArray2.h:71
octave_idx_type rows(void) const
Definition: DiagArray2.h:88
STL namespace.
const T * data(void) const
Definition: DiagArray2.h:176
T & dgelem(octave_idx_type i)
Definition: DiagArray2.h:124
octave_idx_type dim1(void) const
Definition: Sparse.h:268
DiagArray2(void)
Definition: DiagArray2.h:50
T & elem(octave_idx_type n)
Definition: Array.h:482
T * fortran_vec(void)
Definition: DiagArray2.h:180
octave_function * fcn
Definition: ov-class.cc:1743
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
T dgelem(octave_idx_type i) const
Definition: DiagArray2.h:121
size_t byte_size(void) const
Definition: Array.h:435
void resize(octave_idx_type n, octave_idx_type m)
Definition: DiagArray2.h:166
T xelem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:154
T dgxelem(octave_idx_type i) const
Definition: DiagArray2.h:162
octave_idx_type nelem(void) const
Definition: DiagArray2.h:95
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
bool & operator()(octave_idx_type n)
Definition: Sparse.h:406
void resize(octave_idx_type r, octave_idx_type c)
octave_idx_type d1
Definition: DiagArray2.h:44
void print_info(std::ostream &os, const std::string &prefix) const
Definition: Array.cc:2734
const T * data(void) const
Definition: Array.h:582
static int elem
Definition: __contourc__.cc:50
T & dgxelem(octave_idx_type i)
Definition: DiagArray2.h:159
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
DiagArray2(octave_idx_type r, octave_idx_type c, const T &val)
Definition: DiagArray2.h:56
T & xelem(octave_idx_type n)
Definition: Array.h:455
DiagArray2(const Array< T > &a)
Definition: DiagArray2.h:59
octave_idx_type cols(void) const
Definition: DiagArray2.h:89
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:126
octave_idx_type d2
Definition: DiagArray2.h:44
T::size_type numel(const T &str)
Definition: oct-string.cc:61
T element_type
Definition: Array.h:199
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
void print_info(std::ostream &os, const std::string &prefix) const
Definition: DiagArray2.h:182
bool & checkelem(octave_idx_type n)
Definition: Sparse.h:342
octave_idx_type columns(void) const
Definition: DiagArray2.h:90
octave_idx_type diag_length(void) const
Definition: DiagArray2.h:92
SparseBoolMatrix diag(octave_idx_type k=0) const
Definition: boolSparse.cc:242
const T * fortran_vec(void) const
Definition: Array.h:584
octave_idx_type dim2(void) const
Definition: Sparse.h:269
octave_idx_type dim2(void) const
Definition: DiagArray2.h:86
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_idx_type numel(void) const
Definition: DiagArray2.h:96
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
Array< T > & operator=(const Array< T > &a)
Definition: Array.h:309
octave_idx_type length(void) const
Definition: DiagArray2.h:94
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:205
Array< bool > array_value(void) const