annotate liboctave/array/PermMatrix.h @ 31225:3eab70385569

sparse-xpow.cc: Use faster multiplication technique, this time for complex
author Arun Giridhar <arungiridhar@gmail.com>
date Sun, 11 Sep 2022 13:53:38 -0400
parents 796f54d4ddbf
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3 // Copyright (C) 2008-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20232
diff changeset
26 #if ! defined (octave_PermMatrix_h)
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 #define octave_PermMatrix_h 1
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21229
diff changeset
30
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 #include "Array.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 #include "mx-defs.h"
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8375
diff changeset
34 // Array<T> is inherited privately so that some methods, like index, don't
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8375
diff changeset
35 // produce unexpected results.
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
36
9237
3c1762c7e787 Add missing xxx_API decoration and remove misplaced ones
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8958
diff changeset
37 class OCTAVE_API PermMatrix : protected Array<octave_idx_type>
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38 {
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39 public:
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40
27023
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
41 PermMatrix (void) = default;
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
42
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
43 PermMatrix (const PermMatrix& m) = default;
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
44
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
45 PermMatrix& operator = (const PermMatrix& m) = default;
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
46
fc256e9d882e use default ctors, dtors, and assignment ops in Matrix, intNDArray, and Cell
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
47 ~PermMatrix (void) = default;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
49 OCTAVE_API PermMatrix (octave_idx_type n);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
51 OCTAVE_API PermMatrix (const Array<octave_idx_type>& p, bool colp,
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
52 bool check = true);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
54 OCTAVE_API PermMatrix (const octave::idx_vector& idx, bool colp,
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
55 octave_idx_type n = 0);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
57 octave_idx_type dim1 (void) const
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
58 { return Array<octave_idx_type>::numel (); }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
59 octave_idx_type dim2 (void) const
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
60 { return Array<octave_idx_type>::numel (); }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
61
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
62 octave_idx_type rows (void) const { return dim1 (); }
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
63 octave_idx_type cols (void) const { return dim2 (); }
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
64 octave_idx_type columns (void) const { return dim2 (); }
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
65
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
66 octave_idx_type perm_length (void) const
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20228
diff changeset
67 { return Array<octave_idx_type>::numel (); }
9698
7c6d5d8c8d37 fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 9237
diff changeset
68 // FIXME: a dangerous ambiguity?
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
69 octave_idx_type length (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
70 { return perm_length (); }
21134
2e5c1f766ac9 provide replacement hints for deprecated C++ functions
John W. Eaton <jwe@octave.org>
parents: 21131
diff changeset
71
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
72 octave_idx_type numel (void) const { return dim1 () * dim2 (); }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
73
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
74 std::size_t byte_size (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
75 { return Array<octave_idx_type>::byte_size (); }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
76
8524
937921654627 clean up Array and DiagArray2
Jaroslav Hajek <highegg@gmail.com>
parents: 8375
diff changeset
77 dim_vector dims (void) const { return dim_vector (dim1 (), dim2 ()); }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
78
24646
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
79 bool isempty (void) const { return numel () == 0; }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
80
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
81 int ndims (void) const { return 2; }
d36e1f768bfa allow diagonal and permutation matrices to be display in variable editor
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
82
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
83 const Array<octave_idx_type>& col_perm_vec (void) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
84 { return *this; }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
85
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
86 octave_idx_type
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
87 elem (octave_idx_type i, octave_idx_type j) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
88 {
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
89 return (Array<octave_idx_type>::elem (j) == i) ? 1 : 0;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
90 }
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
91
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
92 octave_idx_type
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93 checkelem (octave_idx_type i, octave_idx_type j) const;
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
94
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
95 octave_idx_type
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
96 operator () (octave_idx_type i, octave_idx_type j) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
97 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
98 return elem (i, j);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
99 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
100
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
101 // These are, in fact, super-fast.
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
102 OCTAVE_API PermMatrix transpose (void) const;
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
103 OCTAVE_API PermMatrix inverse (void) const;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21244
diff changeset
105 // Determinant, i.e., the sign of permutation.
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
106 OCTAVE_API octave_idx_type determinant (void) const;
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107
8958
6ccc12cc65ef implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
108 // Efficient integer power of a permutation.
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
109 OCTAVE_API PermMatrix power (octave_idx_type n) const;
8958
6ccc12cc65ef implement raising a permutation matrix to integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
110
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
111 bool is_col_perm (void) const { return true; }
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
112 bool is_row_perm (void) const { return false; }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
113
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
114 void print_info (std::ostream& os, const std::string& prefix) const
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
115 { Array<octave_idx_type>::print_info (os, prefix); }
8375
e3c9102431a9 fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents: 8367
diff changeset
116
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
117 static OCTAVE_API PermMatrix eye (octave_idx_type n);
9708
6f3ffe11d926 implement luupdate
Jaroslav Hajek <highegg@gmail.com>
parents: 9698
diff changeset
118
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
119 private:
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
120
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
121 PermMatrix pos_power (octave_idx_type m) const;
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
122
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
123 void setup (const Array<octave_idx_type>& p, bool colp, bool check);
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
124
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
125 void setup (const octave::idx_vector& idx, bool colp, octave_idx_type n);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126 };
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 // Multiplying permutations together.
29646
3e8bc8bee8e9 liboctave/array: Add visibility flags to functions declared in headers (bug #60567).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29572
diff changeset
129 OCTAVE_API PermMatrix
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 17769
diff changeset
130 operator * (const PermMatrix& a, const PermMatrix& b);
8367
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131
445d27d79f4e support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132 #endif