GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-pm-sm.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "errwarn.h"
28 #include "ovl.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 
36 // permutation matrix by sparse matrix ops
37 
38 DEFBINOP (mul_pm_sm, perm_matrix, sparse_matrix)
39 {
40  const octave_perm_matrix& v1 = dynamic_cast<const octave_perm_matrix&> (a1);
41  const octave_sparse_matrix& v2 = dynamic_cast<const octave_sparse_matrix&> (a2);
42 
43  if (v2.rows () == 1 && v2.columns () == 1)
44  {
45  double d = v2.scalar_value ();
46 
47  return octave_value (v1.sparse_matrix_value () * d);
48  }
49  else if (v1.rows () == 1 && v1.columns () == 1)
51  else
52  return v1.perm_matrix_value () * v2.sparse_matrix_value ();
53 }
54 
55 DEFBINOP (ldiv_pm_sm, perm_matrix, sparse_matrix)
56 {
57  const octave_perm_matrix& v1 = dynamic_cast<const octave_perm_matrix&> (a1);
58  const octave_sparse_matrix& v2 = dynamic_cast<const octave_sparse_matrix&> (a2);
59 
60  return v1.perm_matrix_value ().inverse () * v2.sparse_matrix_value ();
61 }
62 
63 // sparse matrix by diagonal matrix ops
64 
65 DEFBINOP (mul_sm_pm, sparse_matrix, perm_matrix)
66 {
67  const octave_sparse_matrix& v1 = dynamic_cast<const octave_sparse_matrix&> (a1);
68  const octave_perm_matrix& v2 = dynamic_cast<const octave_perm_matrix&> (a2);
69 
70  if (v1.rows () == 1 && v1.columns () == 1)
71  {
72  double d = v1.scalar_value ();
73 
74  return octave_value (d * v2.sparse_matrix_value ());
75  }
76  else if (v2.rows () == 1 && v2.columns () == 1)
77  return octave_value (v1.sparse_matrix_value ());
78  else
79  return v1.sparse_matrix_value () * v2.perm_matrix_value ();
80 }
81 
82 DEFBINOP (div_sm_pm, sparse_matrix, perm_matrix)
83 {
84  const octave_sparse_matrix& v1 = dynamic_cast<const octave_sparse_matrix&> (a1);
85  const octave_perm_matrix& v2 = dynamic_cast<const octave_perm_matrix&> (a2);
86 
87  return v1.sparse_matrix_value () * v2.perm_matrix_value ().inverse ();
88 }
89 
90 void
92 {
94  mul_pm_sm);
96  ldiv_pm_sm);
98  mul_sm_pm);
100  div_sm_pm);
101 }
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-perm.cc:210
PermMatrix perm_matrix_value(void) const
Definition: ov-perm.h:138
double scalar_value(bool frc_str_conv=false) const
Definition: ov-ch-mat.h:103
#define DEFBINOP(name, t1, t2)
Definition: ops.h:264
virtual SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-base.cc:634
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:53
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
const octave_base_value & a2
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1606
double scalar_value(bool frc_str_conv=false) const
Definition: ov-re-sparse.h:108
octave_idx_type rows(void) const
Definition: ov-base.h:316
PermMatrix inverse(void) const
Definition: PermMatrix.cc:111
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
const octave_char_matrix & v2
void install_pm_sm_ops(octave::type_info &ti)
Definition: op-pm-sm.cc:91
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1609
octave_idx_type columns(void) const
Definition: ov-base.h:323
virtual PermMatrix perm_matrix_value(void) const
Definition: ov-base.cc:681
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-re-sparse.h:125
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1605