GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
DiagArray2.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
4 Copyright (C) 2008-2009 Jaroslav Hajek
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
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Octave is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License 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 <https://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if ! defined (octave_DiagArray2_h)
26 #define octave_DiagArray2_h 1
27 
28 #include "octave-config.h"
29 
30 #include <cassert>
31 #include <cstdlib>
32 
33 #include "Array.h"
34 
35 // Array<T> is inherited privately so that some methods, like index, don't
36 // produce unexpected results.
37 
38 template <typename T>
39 class
40 DiagArray2 : protected Array<T>
41 {
42 protected:
44 
45 public:
46 
47  using typename Array<T>::element_type;
48 
49  DiagArray2 (void)
50  : Array<T> (), d1 (0), d2 (0) { }
51 
53  : Array<T> (dim_vector (std::min (r, c), 1)), d1 (r), d2 (c) { }
54 
56  : Array<T> (dim_vector (std::min (r, c), 1), val), d1 (r), d2 (c) { }
57 
58  explicit DiagArray2 (const Array<T>& a)
59  : Array<T> (a.as_column ()), d1 (a.numel ()), d2 (a.numel ()) { }
60 
62 
64  : Array<T> (a), d1 (a.d1), d2 (a.d2) { }
65 
66  template <typename U>
68  : Array<T> (a.extract_diag ()), d1 (a.dim1 ()), d2 (a.dim2 ()) { }
69 
70  ~DiagArray2 (void) = default;
71 
73  {
74  if (this != &a)
75  {
77  d1 = a.d1;
78  d2 = a.d2;
79  }
80 
81  return *this;
82  }
83 
84  octave_idx_type dim1 (void) const { return d1; }
85  octave_idx_type dim2 (void) const { return d2; }
86 
87  octave_idx_type rows (void) const { return dim1 (); }
88  octave_idx_type cols (void) const { return dim2 (); }
89  octave_idx_type columns (void) const { return dim2 (); }
90 
91  octave_idx_type diag_length (void) const { return Array<T>::numel (); }
92  // FIXME: a dangerous ambiguity?
93  octave_idx_type length (void) const { return Array<T>::numel (); }
94  octave_idx_type nelem (void) const { return dim1 () * dim2 (); }
95  octave_idx_type numel (void) const { return nelem (); }
96 
97  size_t byte_size (void) const { return Array<T>::byte_size (); }
98 
99  dim_vector dims (void) const { return dim_vector (d1, d2); }
100 
101  bool isempty (void) const { return numel () == 0; }
102 
103  int ndims (void) const { return 2; }
104 
105  Array<T> extract_diag (octave_idx_type k = 0) const;
106 
108  {
109  return DiagArray2<T> (array_value ());
110  }
111 
112  // Warning: the non-const two-index versions will silently ignore assignments
113  // to off-diagonal elements.
114 
116  {
117  return (r == c) ? Array<T>::elem (r) : T (0);
118  }
119 
121 
123  { return Array<T>::elem (i); }
124 
126  { return Array<T>::elem (i); }
127 
129  { return check_idx (r, c) ? elem (r, c) : T (0); }
130 
132  {
133  return elem (r, c);
134  }
135 
137 
139  {
140  return elem (r, c);
141  }
142 
143  // No checking.
144 
146  {
147  return (r == c) ? Array<T>::xelem (r) : T (0);
148  }
149 
151  { return Array<T>::xelem (i); }
152 
154  { return Array<T>::xelem (i); }
155 
156  void resize (octave_idx_type n, octave_idx_type m, const T& rfv);
158  {
160  }
161 
162  DiagArray2<T> transpose (void) const;
163  DiagArray2<T> hermitian (T (*fcn) (const T&) = nullptr) const;
164 
165  Array<T> array_value (void) const;
166 
167  const T * data (void) const { return Array<T>::data (); }
168 
169  const T * fortran_vec (void) const { return Array<T>::fortran_vec (); }
170 
171  T * fortran_vec (void) { return Array<T>::fortran_vec (); }
172 
173  void print_info (std::ostream& os, const std::string& prefix) const
174  { Array<T>::print_info (os, prefix); }
175 
176 private:
177 
178  bool check_idx (octave_idx_type r, octave_idx_type c) const;
179 };
180 
181 #endif
T xelem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:145
void resize(octave_idx_type r, octave_idx_type c)
Definition: Sparse.cc:950
T dgelem(octave_idx_type i) const
Definition: DiagArray2.h:122
DiagArray2(const DiagArray2< T > &a)
Definition: DiagArray2.h:63
T checkelem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:128
const T * data(void) const
Definition: Array.h:582
T dgxelem(octave_idx_type i) const
Definition: DiagArray2.h:153
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
DiagArray2(const DiagArray2< U > &a)
Definition: DiagArray2.h:67
SparseBoolMatrix & operator=(const SparseBoolMatrix &a)
Definition: boolSparse.h:80
for large enough k
Definition: lu.cc:617
DiagArray2(octave_idx_type r, octave_idx_type c)
Definition: DiagArray2.h:52
const T * fortran_vec(void) const
Definition: Array.h:584
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:386
const T * fortran_vec(void) const
Definition: DiagArray2.h:169
STL namespace.
T & dgelem(octave_idx_type i)
Definition: DiagArray2.h:125
DiagArray2(void)
Definition: DiagArray2.h:49
T & elem(octave_idx_type n)
Definition: Array.h:488
octave_idx_type rows(void) const
Definition: DiagArray2.h:87
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_idx_type diag_length(void) const
Definition: DiagArray2.h:91
T elem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:115
T * fortran_vec(void)
Definition: DiagArray2.h:171
octave_function * fcn
Definition: ov-class.cc:1754
DiagArray2< T > build_diag_matrix() const
Definition: DiagArray2.h:107
size_t byte_size(void) const
Definition: DiagArray2.h:97
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
void resize(octave_idx_type n, octave_idx_type m)
Definition: DiagArray2.h:157
octave_idx_type length(void) const
Definition: DiagArray2.h:93
octave_idx_type cols(void) const
Definition: DiagArray2.h:88
static int elem
Definition: __contourc__.cc:47
octave_idx_type nelem(void) const
Definition: DiagArray2.h:94
T & dgxelem(octave_idx_type i)
Definition: DiagArray2.h:150
Array< bool > array_value(void) const
Definition: Sparse.cc:2675
bool isempty(void) const
Definition: DiagArray2.h:101
DiagArray2(octave_idx_type r, octave_idx_type c, const T &val)
Definition: DiagArray2.h:55
T & xelem(octave_idx_type n)
Definition: Array.h:458
octave_idx_type numel(void) const
Definition: DiagArray2.h:95
DiagArray2(const Array< T > &a)
Definition: DiagArray2.h:58
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
octave_idx_type d2
Definition: DiagArray2.h:43
octave_idx_type dim1(void) const
Definition: Sparse.h:255
T::size_type numel(const T &str)
Definition: oct-string.cc:61
void print_info(std::ostream &os, const std::string &prefix) const
Definition: Array.cc:2735
T element_type
Definition: Array.h:201
int ndims(void) const
Definition: DiagArray2.h:103
bool & operator()(octave_idx_type n)
Definition: Sparse.h:378
dim_vector dims(void) const
Definition: DiagArray2.h:99
octave_idx_type dim2(void) const
Definition: DiagArray2.h:85
octave_idx_type columns(void) const
Definition: DiagArray2.h:89
for i
Definition: data.cc:5264
void print_info(std::ostream &os, const std::string &prefix) const
Definition: DiagArray2.h:173
bool & checkelem(octave_idx_type n)
Definition: Sparse.h:330
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_idx_type dim1(void) const
Definition: DiagArray2.h:84
size_t byte_size(void) const
Definition: Array.h:438
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:888
Array< T > & operator=(const Array< T > &a)
Definition: Array.h:311
octave_idx_type dim2(void) const
Definition: Sparse.h:256
octave::stream os
Definition: file-io.cc:627
const T * data(void) const
Definition: DiagArray2.h:167
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:204
octave_idx_type nelem(void) const
Definition: Sparse.h:250