GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
PermMatrix.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2018 Jaroslav Hajek
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_PermMatrix_h)
24 #define octave_PermMatrix_h 1
25 
26 #include "octave-config.h"
27 
28 #include "Array.h"
29 #include "mx-defs.h"
30 
31 // Array<T> is inherited privately so that some methods, like index, don't
32 // produce unexpected results.
33 
34 class OCTAVE_API PermMatrix : protected Array<octave_idx_type>
35 {
36 public:
37 
38  PermMatrix (void) : Array<octave_idx_type> () { }
39 
41 
42  PermMatrix (const Array<octave_idx_type>& p, bool colp, bool check = true);
43 
45 
46  PermMatrix (const idx_vector& idx, bool colp, octave_idx_type n = 0);
47 
48  octave_idx_type dim1 (void) const
49  { return Array<octave_idx_type>::numel (); }
50  octave_idx_type dim2 (void) const
51  { return Array<octave_idx_type>::numel (); }
52 
53  octave_idx_type rows (void) const { return dim1 (); }
54  octave_idx_type cols (void) const { return dim2 (); }
55  octave_idx_type columns (void) const { return dim2 (); }
56 
58  { return Array<octave_idx_type>::numel (); }
59  // FIXME: a dangerous ambiguity?
60  octave_idx_type length (void) const
61  { return perm_length (); }
62 
63  OCTAVE_DEPRECATED (4.4, "use 'numel' instead")
64  octave_idx_type nelem (void) const { return numel (); }
65 
66  octave_idx_type numel (void) const { return dim1 () * dim2 (); }
67 
68  size_t byte_size (void) const
70 
71  dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); }
72 
73  bool isempty (void) const { return numel () == 0; }
74 
75  int ndims (void) const { return 2; }
76 
78  { return *this; }
79 
82  {
83  return (Array<octave_idx_type>::elem (j) == i) ? 1 : 0;
84  }
85 
88 
91  {
92  return elem (i, j);
93  }
94 
95  // These are, in fact, super-fast.
96  PermMatrix transpose (void) const;
97  PermMatrix inverse (void) const;
98 
99  // Determinant, i.e., the sign of permutation.
100  octave_idx_type determinant (void) const;
101 
102  // Efficient integer power of a permutation.
103  PermMatrix power (octave_idx_type n) const;
104 
105  bool is_col_perm (void) const { return true; }
106  bool is_row_perm (void) const { return false; }
107 
108  void print_info (std::ostream& os, const std::string& prefix) const
110 
111  static PermMatrix eye (octave_idx_type n);
112 
113 private:
114 
115  PermMatrix pos_power (octave_idx_type m) const;
116 
117  void setup (const Array<octave_idx_type>& p, bool colp, bool check);
118 
119  void setup (const idx_vector& idx, bool colp, octave_idx_type n);
120 };
121 
122 // Multiplying permutations together.
124 OCTAVE_API
125 operator * (const PermMatrix& a, const PermMatrix& b);
126 
127 #endif
octave_idx_type dim1(void) const
Definition: PermMatrix.h:48
octave_idx_type numel(void) const
Definition: PermMatrix.h:66
PermMatrix OCTAVE_API operator*(const PermMatrix &a, const PermMatrix &b)
Definition: PermMatrix.cc:208
octave_idx_type dim1(void) const
Definition: Array.h:403
octave_idx_type rows(void) const
Definition: PermMatrix.h:53
bool is_row_perm(void) const
Definition: PermMatrix.h:106
PermMatrix(void)
Definition: PermMatrix.h:38
void print_info(std::ostream &os, const std::string &prefix) const
Definition: PermMatrix.h:108
T & elem(octave_idx_type n)
Definition: Array.h:488
octave_idx_type perm_length(void) const
Definition: PermMatrix.h:57
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
size_t byte_size(void) const
Definition: PermMatrix.h:68
octave_idx_type dim2(void) const
Definition: Array.h:411
Array< T > transpose(void) const
Definition: Array.cc:1598
const Array< octave_idx_type > & col_perm_vec(void) const
Definition: PermMatrix.h:77
octave_idx_type elem(octave_idx_type i, octave_idx_type j) const
Definition: PermMatrix.h:81
octave_idx_type columns(void) const
Definition: PermMatrix.h:55
bool isempty(void) const
Definition: PermMatrix.h:73
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
void print_info(std::ostream &os, const std::string &prefix) const
Definition: Array.cc:2735
T & checkelem(octave_idx_type n)
Definition: Array.cc:191
p
Definition: lu.cc:138
T & operator()(octave_idx_type n)
Definition: Array.h:502
octave_idx_type length(void) const
Definition: PermMatrix.h:60
PermMatrix(const PermMatrix &m)
Definition: PermMatrix.h:44
octave_idx_type dim2(void) const
Definition: PermMatrix.h:50
b
Definition: cellfun.cc:400
for i
Definition: data.cc:5264
octave_idx_type cols(void) const
Definition: PermMatrix.h:54
int ndims(void) const
Definition: PermMatrix.h:75
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
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
dim_vector dims(void) const
Definition: PermMatrix.h:71
octave::stream os
Definition: file-io.cc:627
bool is_col_perm(void) const
Definition: PermMatrix.h:105