GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
PermMatrix.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2008-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
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
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License 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// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_PermMatrix_h)
27#define octave_PermMatrix_h 1
28
29#include "octave-config.h"
30
31#include "Array.h"
32#include "mx-defs.h"
33
34// Array<T> is inherited privately so that some methods, like index, don't
35// produce unexpected results.
36
37class OCTAVE_API PermMatrix : protected Array<octave_idx_type>
38{
39public:
40
41 PermMatrix () = default;
42
43 PermMatrix (const PermMatrix& m) = default;
44
45 PermMatrix& operator = (const PermMatrix& m) = default;
46
47 ~PermMatrix () = default;
48
50
51 OCTAVE_API PermMatrix (const Array<octave_idx_type>& p, bool colp,
52 bool check = true);
53
54 OCTAVE_API PermMatrix (const octave::idx_vector& idx, bool colp,
55 octave_idx_type n = 0);
56
61
62 octave_idx_type rows () const { return dim1 (); }
63 octave_idx_type cols () const { return dim2 (); }
64 octave_idx_type columns () const { return dim2 (); }
65
68 // FIXME: a dangerous ambiguity?
70 { return perm_length (); }
71
72 octave_idx_type numel () const { return dim1 () * dim2 (); }
73
74 std::size_t byte_size () const
76
77 dim_vector dims () const { return dim_vector (dim1 (), dim2 ()); }
78
79 bool isempty () const { return numel () == 0; }
80
81 int ndims () const { return 2; }
82
84 { return *this; }
85
88 {
89 return (Array<octave_idx_type>::elem (j) == i) ? 1 : 0;
90 }
91
93 checkelem (octave_idx_type i, octave_idx_type j) const;
94
96 operator () (octave_idx_type i, octave_idx_type j) const
97 {
98 return elem (i, j);
99 }
100
101 // These are, in fact, super-fast.
102 OCTAVE_API PermMatrix transpose () const;
103 OCTAVE_API PermMatrix inverse () const;
104
105 // Determinant, i.e., the sign of permutation.
106 OCTAVE_API octave_idx_type determinant () const;
107
108 // Efficient integer power of a permutation.
109 OCTAVE_API PermMatrix power (octave_idx_type n) const;
110
111 bool is_col_perm () const { return true; }
112 bool is_row_perm () 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
118
119private:
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 octave::idx_vector& idx, bool colp, octave_idx_type n);
126};
127
128// Multiplying permutations together.
130operator * (const PermMatrix& a, const PermMatrix& b);
131
132#endif
PermMatrix operator*(const PermMatrix &a, const PermMatrix &b)
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
std::size_t byte_size() const
Size of the specified dimension.
Definition Array.h:503
Array< T, Alloc > & operator=(const Array< T, Alloc > &a)
Definition Array.h:365
void print_info(std::ostream &os, const std::string &prefix) const
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
Definition Array.h:418
bool isempty() const
Definition PermMatrix.h:79
bool is_row_perm() const
Definition PermMatrix.h:112
~PermMatrix()=default
octave_idx_type elem(octave_idx_type i, octave_idx_type j) const
Definition PermMatrix.h:87
octave_idx_type numel() const
Definition PermMatrix.h:72
octave_idx_type rows() const
Definition PermMatrix.h:62
void print_info(std::ostream &os, const std::string &prefix) const
Definition PermMatrix.h:114
PermMatrix(const PermMatrix &m)=default
octave_idx_type dim2() const
Definition PermMatrix.h:59
PermMatrix()=default
octave_idx_type dim1() const
Definition PermMatrix.h:57
octave_idx_type cols() const
Definition PermMatrix.h:63
octave_idx_type perm_length() const
Definition PermMatrix.h:66
bool is_col_perm() const
Definition PermMatrix.h:111
octave_idx_type columns() const
Definition PermMatrix.h:64
const Array< octave_idx_type > & col_perm_vec() const
Definition PermMatrix.h:83
int ndims() const
Definition PermMatrix.h:81
std::size_t byte_size() const
Definition PermMatrix.h:74
dim_vector dims() const
Definition PermMatrix.h:77
octave_idx_type length() const
Definition PermMatrix.h:69
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
#define OCTAVE_API
Definition main.in.cc:55
T::size_type numel(const T &str)
Definition oct-string.cc:74