GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
op-dms-template.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2008-2026 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 (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "ops.h"
31#include "xpow.h"
32#include SINCLUDE
33#include MINCLUDE
34
35// matrix by diag matrix ops.
36
37#if ! defined (SCALARV)
38# define SCALARV SCALAR
39#endif
40
41#if ! defined (DIAG_MATRIXV)
42# define DIAG_MATRIXV DIAG_MATRIX
43#endif
44
45#if ! defined (MATRIXV)
46# define MATRIXV MATRIX
47#endif
48
50
51#define OCTAVE_DIAG_MATRIX CONCAT2(octave_, DIAG_MATRIX)
52#define OCTAVE_MATRIX CONCAT2(octave_, MATRIX)
53#define OCTAVE_SCALAR CONCAT2(octave_, SCALAR)
54#define DIAG_MATRIX_VALUE CONCAT2(DIAG_MATRIXV, _value)
55#define MATRIX_VALUE CONCAT2(MATRIXV, _value)
56#define SCALAR_VALUE CONCAT2(SCALARV, _value)
57
58template <typename DM, typename S>
60dm_s_mul (const DM& dm, const S& d)
61{
63 {
64 if (math::isfinite (std::norm (d)))
65 return octave_value (dm.DIAG_MATRIX_VALUE () * d);
66 else
67 return octave_value (dm.MATRIX_VALUE () * d);
68 }
69 else
70 {
71 if (math::isfinite (d))
72 return octave_value (dm.DIAG_MATRIX_VALUE () * d);
73 else
74 return octave_value (dm.MATRIX_VALUE () * d);
75 }
76}
77
79{
82
83 return dm_s_mul<> (v1, v2.SCALAR_VALUE ());
84}
85
86template <typename DM, typename S>
88dm_s_div (const DM& dm, const S& d)
89{
91 {
92 auto nd = std::norm (d);
93 if (nd == 0.0 || math::isnan (nd))
94 return octave_value (dm.MATRIX_VALUE () / d);
95 else
96 return octave_value (dm.DIAG_MATRIX_VALUE () / d);
97 }
98 else
99 {
100 if (d == 0.0 || math::isnan (d))
101 return octave_value (dm.MATRIX_VALUE () / d);
102 else
103 return octave_value (dm.DIAG_MATRIX_VALUE () / d);
104 }
105}
106
107DEFBINOP (dmsdiv, MATRIX, SCALAR)
108{
111
112 return dm_s_div<> (v1, v2.SCALAR_VALUE ());
113}
114
115template <typename S, typename DM>
117s_dm_mul (const S& d, const DM& dm)
118{
120 {
121 if (math::isfinite (std::norm (d)))
122 return octave_value (d * dm.DIAG_MATRIX_VALUE ());
123 else
124 return octave_value (d * dm.MATRIX_VALUE ());
125 }
126 else
127 {
128 if (math::isfinite (d))
129 return octave_value (d * dm.DIAG_MATRIX_VALUE ());
130 else
131 return octave_value (d * dm.MATRIX_VALUE ());
132 }
133}
134
135DEFBINOP (sdmmul, SCALAR, DIAG_MATRIX)
136{
137 OCTAVE_CAST_BASE_VALUE (const OCTAVE_SCALAR&, v1, a1);
139
140 return s_dm_mul<> (v1.SCALAR_VALUE (), v2);
141}
142
143template <typename S, typename DM>
145s_dm_ldiv (const S& d, const DM& dm)
146{
148 {
149 auto nd = std::norm (d);
150 if (nd == 0.0 || math::isnan (nd))
151 return octave_value (dm.MATRIX_VALUE () / d);
152 else
153 return octave_value (dm.DIAG_MATRIX_VALUE () / d);
154 }
155 else
156 {
157 if (d == 0.0 || math::isnan (d))
158 return octave_value (dm.MATRIX_VALUE () / d);
159 else
160 return octave_value (dm.DIAG_MATRIX_VALUE () / d);
161 }
162}
163
164DEFBINOP (sdmldiv, SCALAR, MATRIX)
165{
166 OCTAVE_CAST_BASE_VALUE (const OCTAVE_SCALAR&, v1, a1);
168
169 return s_dm_ldiv<> (v1.SCALAR_VALUE (), v2);
170}
171
172DEFBINOP (dmspow, MATRIX, SCALAR)
173{
176
177 return xpow (v1.DIAG_MATRIX_VALUE (), v2.SCALAR_VALUE ());
178}
179
180#define SHORT_NAME CONCAT3(MSHORT, _, SSHORT)
181#define INST_NAME CONCAT3(install_, SHORT_NAME, _ops)
182
183void
192
193OCTAVE_END_NAMESPACE(octave)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DIAG_MATRIX
Definition op-cdm-cs.cc:30
#define SCALAR
Definition op-cdm-cs.cc:29
#define MATRIX
Definition op-cdm-cs.cc:31
#define INST_NAME
octave_value s_dm_ldiv(const S &d, const DM &dm)
octave_value dm_s_div(const DM &dm, const S &d)
#define OCTAVE_SCALAR
octave_value dm_s_mul(const DM &dm, const S &d)
#define OCTAVE_DIAG_MATRIX
octave_value s_dm_mul(const S &d, const DM &dm)
const octave_base_value & a2
const octave_char_matrix & v2
#define DEFBINOP(name, t1, t2)
Definition ops.h:248
#define OCTAVE_CAST_BASE_VALUE(T, T_VAL, BASE_VAL)
Definition ops.h:52
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition ops.h:70
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition ov.h:1678
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition ov.h:1682
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition ov.h:1681
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition ov.h:1679
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
octave_value xpow(const SparseMatrix &a, double b)