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
PermMatrix.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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  OCTAVE_DEPRECATED ("use 'PermMatrix (p, false, true)' instead")
44 
45  PermMatrix (const Array<octave_idx_type>& p, bool colp, bool check = true);
46 
48 
49  OCTAVE_DEPRECATED ("use 'PermVector (idx, false, 0)' instead")
50  PermMatrix (const idx_vector& idx);
51 
52  PermMatrix (const idx_vector& idx, bool colp, octave_idx_type n = 0);
53 
54  octave_idx_type dim1 (void) const
55  { return Array<octave_idx_type>::numel (); }
56  octave_idx_type dim2 (void) const
57  { return Array<octave_idx_type>::numel (); }
58 
59  octave_idx_type rows (void) const { return dim1 (); }
60  octave_idx_type cols (void) const { return dim2 (); }
61  octave_idx_type columns (void) const { return dim2 (); }
62 
64  { return Array<octave_idx_type>::numel (); }
65  // FIXME: a dangerous ambiguity?
66  octave_idx_type length (void) const
67  { return perm_length (); }
68 
69  OCTAVE_DEPRECATED ("use 'numel' instead")
70  octave_idx_type nelem (void) const { return numel (); }
71 
72  octave_idx_type numel (void) const { return dim1 () * dim2 (); }
73 
74  size_t byte_size (void) const
76 
77  dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); }
78 
80  { return *this; }
81 
84  {
85  return (Array<octave_idx_type>::elem (j) == i) ? 1 : 0;
86  }
87 
90 
93  {
94 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
95  return checkelem (i, j);
96 #else
97  return elem (i, j);
98 #endif
99  }
100 
101  // These are, in fact, super-fast.
102  PermMatrix transpose (void) const;
103  PermMatrix inverse (void) const;
104 
105  // Determinant, i.e., the sign of permutation.
106  octave_idx_type determinant (void) const;
107 
108  // Efficient integer power of a permutation.
109  PermMatrix power (octave_idx_type n) const;
110 
111  bool is_col_perm (void) const { return true; }
112  bool is_row_perm (void) const { return false; }
113 
114  void print_info (std::ostream& os, const std::string& prefix) const
115  { Array<octave_idx_type>::print_info (os, prefix); }
116 
117  static PermMatrix eye (octave_idx_type n);
118 
119 private:
120 
121  PermMatrix pos_power (octave_idx_type m) const;
122 
123  void setup (const Array<octave_idx_type>& p, bool colp, bool check);
124 
125  void setup (const idx_vector& idx, bool colp, octave_idx_type n);
126 };
127 
128 // Multiplying permutations together.
130 OCTAVE_API
131 operator * (const PermMatrix& a, const PermMatrix& b);
132 
133 #endif
PermMatrix OCTAVE_API operator*(const PermMatrix &a, const PermMatrix &b)
Definition: PermMatrix.cc:220
octave_idx_type rows(void) const
Definition: PermMatrix.h:59
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
octave_idx_type perm_length(void) const
Definition: PermMatrix.h:63
octave_idx_type cols(void) const
Definition: PermMatrix.h:60
octave_idx_type dim2(void) const
Definition: Array.h:408
PermMatrix(void)
Definition: PermMatrix.h:38
dim_vector dims(void) const
Definition: PermMatrix.h:77
T & elem(octave_idx_type n)
Definition: Array.h:482
void print_info(std::ostream &os, const std::string &prefix) const
Definition: PermMatrix.h:114
octave_idx_type columns(void) const
Definition: PermMatrix.h:61
octave_idx_type dim1(void) const
Definition: Array.h:400
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
size_t byte_size(void) const
Definition: Array.h:435
const Array< octave_idx_type > & col_perm_vec(void) const
Definition: PermMatrix.h:79
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
void print_info(std::ostream &os, const std::string &prefix) const
Definition: Array.cc:2734
bool is_row_perm(void) const
Definition: PermMatrix.h:112
Array< T > transpose(void) const
Definition: Array.cc:1616
octave_idx_type length(void) const
Definition: PermMatrix.h:66
octave_idx_type elem(octave_idx_type i, octave_idx_type j) const
Definition: PermMatrix.h:83
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:126
T & checkelem(octave_idx_type n)
Definition: Array.cc:200
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
p
Definition: lu.cc:138
T & operator()(octave_idx_type n)
Definition: Array.h:505
b
Definition: cellfun.cc:398
bool is_col_perm(void) const
Definition: PermMatrix.h:111
size_t byte_size(void) const
Definition: PermMatrix.h:74
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_idx_type dim2(void) const
Definition: PermMatrix.h:56
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
octave_idx_type numel(void) const
Definition: PermMatrix.h:72