GNU Octave  4.0.0
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-2015 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 "Array.h"
27 #include "mx-defs.h"
28 
29 // Array<T> is inherited privately so that some methods, like index, don't
30 // produce unexpected results.
31 
32 class OCTAVE_API PermMatrix : protected Array<octave_idx_type>
33 {
34 public:
35 
36  PermMatrix (void) : Array<octave_idx_type> () { }
37 
39 
40  PermMatrix (const Array<octave_idx_type>& p) GCC_ATTR_DEPRECATED;
41 
42  PermMatrix (const Array<octave_idx_type>& p, bool colp, bool check = true);
43 
45 
46  PermMatrix (const idx_vector& idx) GCC_ATTR_DEPRECATED;
47 
48  PermMatrix (const idx_vector& idx, bool colp, octave_idx_type n = 0);
49 
50  octave_idx_type dim1 (void) const
51  { return Array<octave_idx_type>::length (); }
52  octave_idx_type dim2 (void) const
53  { return Array<octave_idx_type>::length (); }
54 
55  octave_idx_type rows (void) const { return dim1 (); }
56  octave_idx_type cols (void) const { return dim2 (); }
57  octave_idx_type columns (void) const { return dim2 (); }
58 
60  { return Array<octave_idx_type>::length (); }
61  // FIXME: a dangerous ambiguity?
62  octave_idx_type length (void) const
63  { return perm_length (); }
64  octave_idx_type nelem (void) const { return dim1 () * dim2 (); }
65  octave_idx_type numel (void) const { return nelem (); }
66 
67  size_t byte_size (void) const
69 
70  dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); }
71 
73  { return *this; }
74 
77  {
78  return (Array<octave_idx_type>::elem (j) == i) ? 1 : 0;
79  }
80 
83 
86  {
87 #if defined (BOUNDS_CHECKING)
88  return checkelem (i, j);
89 #else
90  return elem (i, j);
91 #endif
92  }
93 
94  // These are, in fact, super-fast.
95  PermMatrix transpose (void) const;
96  PermMatrix inverse (void) const;
97 
98  // Determinant, i.e. the sign of permutation.
99  octave_idx_type determinant (void) const;
100 
101  // Efficient integer power of a permutation.
102  PermMatrix power (octave_idx_type n) const;
103 
104  bool is_col_perm (void) const { return true; }
105  bool is_row_perm (void) const { return false; }
106 
107  void print_info (std::ostream& os, const std::string& prefix) const
108  { Array<octave_idx_type>::print_info (os, prefix); }
109 
110  static PermMatrix eye (octave_idx_type n);
111 
112 private:
113 
114  PermMatrix pos_power (octave_idx_type m) const;
115 
116  void setup (const Array<octave_idx_type>& p, bool colp, bool check);
117 
118  void setup (const idx_vector& idx, bool colp, octave_idx_type n);
119 };
120 
121 // Multiplying permutations together.
123 OCTAVE_API
124 operator * (const PermMatrix& a, const PermMatrix& b);
125 
126 #endif
PermMatrix OCTAVE_API operator*(const PermMatrix &a, const PermMatrix &b)
Definition: PermMatrix.cc:229
octave_idx_type rows(void) const
Definition: PermMatrix.h:55
octave_idx_type perm_length(void) const
Definition: PermMatrix.h:59
octave_idx_type cols(void) const
Definition: PermMatrix.h:56
octave_idx_type dim2(void) const
Definition: Array.h:320
PermMatrix(void)
Definition: PermMatrix.h:36
dim_vector dims(void) const
Definition: PermMatrix.h:70
T & elem(octave_idx_type n)
Definition: Array.h:380
void print_info(std::ostream &os, const std::string &prefix) const
Definition: PermMatrix.h:107
octave_idx_type nelem(void) const
Definition: PermMatrix.h:64
octave_idx_type columns(void) const
Definition: PermMatrix.h:57
octave_idx_type dim1(void) const
Definition: Array.h:312
octave_idx_type nelem(void) const
Number of elements in the array.
Definition: Array.h:271
octave_idx_type dim1(void) const
Definition: PermMatrix.h:50
size_t byte_size(void) const
Definition: Array.h:333
const Array< octave_idx_type > & col_perm_vec(void) const
Definition: PermMatrix.h:72
void print_info(std::ostream &os, const std::string &prefix) const
Definition: Array.cc:2740
bool is_row_perm(void) const
Definition: PermMatrix.h:105
Array< T > transpose(void) const
Definition: Array.cc:1607
octave_idx_type length(void) const
Definition: PermMatrix.h:62
octave_idx_type elem(octave_idx_type i, octave_idx_type j) const
Definition: PermMatrix.h:76
Handles the reference counting for all the derived classes.
Definition: Array.h:45
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
T & checkelem(octave_idx_type n)
Definition: Array.cc:189
T & operator()(octave_idx_type n)
Definition: Array.h:403
PermMatrix(const PermMatrix &m)
Definition: PermMatrix.h:44
bool is_col_perm(void) const
Definition: PermMatrix.h:104
size_t byte_size(void) const
Definition: PermMatrix.h:67
octave_idx_type dim2(void) const
Definition: PermMatrix.h:52
octave_idx_type numel(void) const
Definition: PermMatrix.h:65