GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
liboctave
array
PermMatrix.h
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2008-2013 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
35
public
:
36
37
PermMatrix
(
void
) :
Array
<
octave_idx_type
> (), _colp (false) { }
38
39
PermMatrix
(
octave_idx_type
n);
40
41
PermMatrix
(
const
Array<octave_idx_type>
& p,
bool
colp =
false
,
42
bool
check =
true
);
43
44
PermMatrix
(
const
PermMatrix
& m)
45
:
Array
<
octave_idx_type
> (m), _colp(m._colp) { }
46
47
PermMatrix
(
const
idx_vector
& idx,
bool
colp =
false
,
octave_idx_type
n = 0);
48
49
octave_idx_type
dim1
(
void
)
const
50
{
return
Array<octave_idx_type>::length
(); }
51
octave_idx_type
dim2
(
void
)
const
52
{
return
Array<octave_idx_type>::length
(); }
53
54
octave_idx_type
rows
(
void
)
const
{
return
dim1
(); }
55
octave_idx_type
cols
(
void
)
const
{
return
dim2
(); }
56
octave_idx_type
columns
(
void
)
const
{
return
dim2
(); }
57
58
octave_idx_type
perm_length (
void
)
const
59
{
return
Array<octave_idx_type>::length
(); }
60
// FIXME: a dangerous ambiguity?
61
octave_idx_type
length
(
void
)
const
62
{
return
perm_length (); }
63
octave_idx_type
nelem
(
void
)
const
{
return
dim1
() *
dim2
(); }
64
octave_idx_type
numel
(
void
)
const
{
return
nelem
(); }
65
66
size_t
byte_size
(
void
)
const
67
{
return
Array<octave_idx_type>::byte_size
(); }
68
69
dim_vector
dims
(
void
)
const
{
return
dim_vector
(dim1 (), dim2 ()); }
70
71
Array<octave_idx_type>
pvec (
void
)
const
72
{
return
*
this
; }
73
74
octave_idx_type
75
elem
(
octave_idx_type
i,
octave_idx_type
j)
const
76
{
77
return
(_colp
78
? ((
Array<octave_idx_type>::elem
(j) == i) ? 1 : 0)
79
: ((
Array<octave_idx_type>::elem
(i) == j) ? 1 : 0));
80
}
81
82
octave_idx_type
83
checkelem
(
octave_idx_type
i,
octave_idx_type
j)
const
;
84
85
octave_idx_type
86
operator ()
(
octave_idx_type
i,
octave_idx_type
j)
const
87
{
88
#if defined (BOUNDS_CHECKING)
89
return
checkelem
(i, j);
90
#else
91
return
elem
(i, j);
92
#endif
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
_colp; }
106
bool
is_row_perm
(
void
)
const
{
return
!_colp; }
107
108
friend
OCTAVE_API
PermMatrix
operator *
(
const
PermMatrix
& a,
109
const
PermMatrix
& b);
110
111
const
octave_idx_type
*
data
(
void
)
const
112
{
return
Array<octave_idx_type>::data
(); }
113
114
const
octave_idx_type
*
fortran_vec
(
void
)
const
115
{
return
Array<octave_idx_type>::fortran_vec
(); }
116
117
octave_idx_type
*
fortran_vec
(
void
)
118
{
return
Array<octave_idx_type>::fortran_vec
(); }
119
120
void
print_info
(std::ostream& os,
const
std::string& prefix)
const
121
{
Array<octave_idx_type>::print_info
(os, prefix); }
122
123
static
PermMatrix
eye (
octave_idx_type
n);
124
125
private
:
126
bool
_colp
;
127
};
128
129
// Multiplying permutations together.
130
PermMatrix
131
OCTAVE_API
132
operator *
(
const
PermMatrix
& a,
const
PermMatrix
& b);
133
134
#endif
Generated on Mon Dec 30 2013 03:04:44 for GNU Octave by
1.8.1.2