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
libinterp
operators
op-pm-sm.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2009-2013 Jason Riedy
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
#ifdef HAVE_CONFIG_H
24
#include <config.h>
25
#endif
26
27
#include "
gripes.h
"
28
#include "
oct-obj.h
"
29
#include "
ov.h
"
30
#include "
ov-typeinfo.h
"
31
#include "
ops.h
"
32
33
#include "
ov-perm.h
"
34
#include "
ov-re-sparse.h
"
35
#include "
ov-bool-sparse.h
"
36
37
// Unary permutation ops, some cast to sparse
38
39
//Avoid casting to a full matrix
40
DEFUNOP_OP
(uplus, perm_matrix,
/* no-op */
)
41
42
// Not calling standard CAST_UNOP_ARG for these next two because a
43
// dynamic_cast would fail.
44
DEFUNOP
(not, perm_matrix)
45
{
46
// Obviously negation of a permutation matrix destroys sparsity
47
return
octave_value
( ! a.bool_array_value ());
48
}
49
50
DEFUNOP
(uminus, perm_matrix)
51
{
52
return
octave_value
( - a.sparse_matrix_value ());
53
}
54
55
// Most other logical operations cast to SparseBoolMatrix
56
DEFBINOP
(eq_pm, perm_matrix, perm_matrix)
57
{
58
CAST_BINOP_ARGS
(
const
octave_perm_matrix
&,
const
octave_perm_matrix
&);
59
return
v1
.
sparse_bool_matrix_value
() ==
v2
.
sparse_bool_matrix_value
();
60
}
61
DEFBINOP
(ne_pm, perm_matrix, perm_matrix)
62
{
63
CAST_BINOP_ARGS
(
const
octave_perm_matrix
&,
const
octave_perm_matrix
&);
64
return
v1
.
sparse_bool_matrix_value
() !=
v2
.
sparse_bool_matrix_value
();
65
}
66
DEFBINOP
(el_and_pm, perm_matrix, perm_matrix)
67
{
68
CAST_BINOP_ARGS
(
const
octave_perm_matrix
&,
const
octave_perm_matrix
&);
69
return
mx_el_and
(
v1
.
sparse_bool_matrix_value
(),
70
v2
.
sparse_bool_matrix_value
());
71
}
72
DEFBINOP
(el_or_pm, perm_matrix, perm_matrix)
73
{
74
CAST_BINOP_ARGS
(
const
octave_perm_matrix
&,
const
octave_perm_matrix
&);
75
return
mx_el_or
(
v1
.
sparse_bool_matrix_value
(),
76
v2
.
sparse_bool_matrix_value
());
77
}
78
79
// permutation matrix by sparse matrix ops
80
81
DEFBINOP
(mul_pm_sm, perm_matrix, sparse_matrix)
82
{
83
CAST_BINOP_ARGS
(
const
octave_perm_matrix
&,
const
octave_sparse_matrix
&);
84
85
if
(
v2
.
rows
() == 1 &&
v2
.
columns
() == 1)
86
{
87
double
d
=
v2
.
scalar_value
();
88
89
return
octave_value
(
v1
.
sparse_matrix_value
() *
d
);
90
}
91
else
if
(
v1
.
rows
() == 1 &&
v1
.
columns
() == 1)
92
return
octave_value
(
v2
.
sparse_matrix_value
());
93
else
94
return
v1
.
perm_matrix_value
() *
v2
.
sparse_matrix_value
();
95
}
96
97
DEFBINOP
(ldiv_pm_sm, perm_matrix, sparse_matrix)
98
{
99
CAST_BINOP_ARGS
(
const
octave_perm_matrix
&,
const
octave_sparse_matrix
&);
100
101
return
v1
.
perm_matrix_value
().
inverse
() *
v2
.
sparse_matrix_value
();
102
}
103
104
// sparse matrix by diagonal matrix ops
105
106
DEFBINOP
(mul_sm_pm, sparse_matrix, perm_matrix)
107
{
108
CAST_BINOP_ARGS
(
const
octave_sparse_matrix
&,
const
octave_perm_matrix
&);
109
110
if
(
v1
.
rows
() == 1 &&
v1
.
columns
() == 1)
111
{
112
double
d
=
v1
.
scalar_value
();
113
114
return
octave_value
(d *
v2
.
sparse_matrix_value
());
115
}
116
else
if
(
v2
.
rows
() == 1 &&
v2
.
columns
() == 1)
117
return
octave_value
(
v1
.
sparse_matrix_value
());
118
else
119
return
v1
.
sparse_matrix_value
() *
v2
.
perm_matrix_value
();
120
}
121
122
DEFBINOP
(div_sm_pm, sparse_matrix, perm_matrix)
123
{
124
CAST_BINOP_ARGS
(
const
octave_sparse_matrix
&,
const
octave_perm_matrix
&);
125
126
return
v1
.
sparse_matrix_value
() *
v2
.
perm_matrix_value
().
inverse
();
127
}
128
129
void
130
install_pm_sm_ops
(
void
)
131
{
132
INSTALL_UNOP
(
op_not
,
octave_perm_matrix
, not);
133
INSTALL_UNOP
(
op_uplus
,
octave_perm_matrix
, uplus);
134
INSTALL_UNOP
(
op_uminus
,
octave_perm_matrix
, uminus);
135
136
137
INSTALL_BINOP
(
op_mul
,
octave_perm_matrix
,
octave_sparse_matrix
,
138
mul_pm_sm);
139
INSTALL_BINOP
(
op_ldiv
,
octave_perm_matrix
,
octave_sparse_matrix
,
140
ldiv_pm_sm);
141
INSTALL_BINOP
(
op_mul
,
octave_sparse_matrix
,
octave_perm_matrix
,
142
mul_sm_pm);
143
INSTALL_BINOP
(
op_div
,
octave_sparse_matrix
,
octave_perm_matrix
,
144
div_sm_pm);
145
146
INSTALL_BINOP
(
op_eq
,
octave_perm_matrix
,
octave_perm_matrix
, eq_pm);
147
INSTALL_BINOP
(
op_ne
,
octave_perm_matrix
,
octave_perm_matrix
, ne_pm);
148
INSTALL_BINOP
(
op_el_and
,
octave_perm_matrix
,
octave_perm_matrix
, el_and_pm);
149
INSTALL_BINOP
(
op_el_or
,
octave_perm_matrix
,
octave_perm_matrix
, el_or_pm);
150
}
Generated on Mon Dec 30 2013 03:04:36 for GNU Octave by
1.8.1.2