GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-cs-cs.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
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 "Array-util.h"
28 
29 #include "errwarn.h"
30 #include "ovl.h"
31 #include "ov.h"
32 #include "ov-complex.h"
33 #include "ov-cx-mat.h"
34 #include "ov-flt-cx-mat.h"
35 #include "ov-typeinfo.h"
36 #include "ov-null-mat.h"
37 #include "ops.h"
38 #include "xdiv.h"
39 #include "xpow.h"
40 
41 // unary complex scalar ops.
42 
43 DEFUNOP (not, complex)
44 {
45  const octave_complex& v = dynamic_cast<const octave_complex&> (a);
46  Complex x = v.complex_value ();
47  if (octave::math::isnan (x))
49 
50  return octave_value (x == 0.0);
51 }
52 
53 DEFUNOP_OP (uplus, complex, /* no-op */)
54 DEFUNOP_OP (uminus, complex, -)
55 DEFUNOP_OP (transpose, complex, /* no-op */)
56 
57 DEFUNOP (hermitian, complex)
58 {
59  const octave_complex& v = dynamic_cast<const octave_complex&> (a);
60 
61  return octave_value (conj (v.complex_value ()));
62 }
63 
64 DEFNCUNOP_METHOD (incr, complex, increment)
65 DEFNCUNOP_METHOD (decr, complex, decrement)
66 
67 // complex scalar by complex scalar ops.
68 
69 DEFBINOP_OP (add, complex, complex, +)
70 DEFBINOP_OP (sub, complex, complex, -)
71 DEFBINOP_OP (mul, complex, complex, *)
72 
73 DEFBINOP (div, complex, complex)
74 {
75  const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1);
76  const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
77 
79 
80  if (d == 0.0)
82 
83  return octave_value (v1.complex_value () / d);
84 }
85 
86 DEFBINOP_FN (pow, complex, complex, xpow)
87 
88 DEFBINOP (ldiv, complex, complex)
89 {
90  const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1);
91  const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
92 
93  Complex d = v1.complex_value ();
94 
95  if (d == 0.0)
97 
98  return octave_value (v2.complex_value () / d);
99 }
100 
101 DEFCMPLXCMPOP_OP (lt, complex, complex, <)
102 DEFCMPLXCMPOP_OP (le, complex, complex, <=)
103 DEFCMPLXCMPOP_OP (eq, complex, complex, ==)
104 DEFCMPLXCMPOP_OP (ge, complex, complex, >=)
105 DEFCMPLXCMPOP_OP (gt, complex, complex, >)
106 DEFCMPLXCMPOP_OP (ne, complex, complex, !=)
107 
108 DEFBINOP_OP (el_mul, complex, complex, *)
109 
110 DEFBINOP (el_div, complex, complex)
111 {
112  const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1);
113  const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
114 
115  Complex d = v2.complex_value ();
116 
117  if (d == 0.0)
119 
120  return octave_value (v1.complex_value () / d);
121 }
122 
123 DEFBINOP_FN (el_pow, complex, complex, xpow)
124 
125 DEFBINOP (el_ldiv, complex, complex)
126 {
127  const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1);
128  const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
129 
130  Complex d = v1.complex_value ();
131 
132  if (d == 0.0)
134 
135  return octave_value (v2.complex_value () / d);
136 }
137 
138 DEFBINOP (el_and, complex, complex)
139 {
140  const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1);
141  const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
142 
143  return v1.complex_value () != 0.0 && v2.complex_value () != 0.0;
144 }
145 
146 DEFBINOP (el_or, complex, complex)
147 {
148  const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1);
149  const octave_complex& v2 = dynamic_cast<const octave_complex&> (a2);
150 
151  return v1.complex_value () != 0.0 || v2.complex_value () != 0.0;
152 }
153 
154 DEFNDCATOP_FN (cs_cs, complex, complex, complex_array, complex_array, concat)
155 
156 void
158 {
163  INSTALL_UNOP_TI (ti, op_hermitian, octave_complex, hermitian);
164 
165  INSTALL_NCUNOP_TI (ti, op_incr, octave_complex, incr);
166  INSTALL_NCUNOP_TI (ti, op_decr, octave_complex, decr);
167 
186 
188 
191 
198 }
octave_value xpow(const SparseMatrix &a, double b)
Definition: sparse-xpow.cc:58
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1574
#define DEFBINOP(name, t1, t2)
Definition: ops.h:264
#define DEFUNOP(name, t)
Definition: ops.h:213
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1620
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:53
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1613
octave_value op_el_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1621
static void transpose(octave_idx_type N, const octave_idx_type *ridx, const octave_idx_type *cidx, octave_idx_type *ridx2, octave_idx_type *cidx2)
Definition: symrcm.cc:386
bool isnan(bool)
Definition: lo-mappers.h:187
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
octave_value op_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1608
#define INSTALL_NCUNOP_TI(ti, op, t, f)
Definition: ops.h:49
#define DEFUNOP_OP(name, t, op)
Definition: ops.h:217
void err_nan_to_logical_conversion(void)
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
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:269
const octave_base_value & a2
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:45
octave_value op_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1606
octave_value op_el_or(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1623
ComplexColumnVector conj(const ComplexColumnVector &a)
Definition: CColVector.cc:215
octave_value op_not(const octave_value &a)
Definition: ov.h:1573
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:58
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1577
octave_value op_el_and(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1622
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
Complex complex_value(bool=false) const
Definition: ov-ch-mat.cc:122
void warn_divide_by_zero(void)
Definition: errwarn.cc:326
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1612
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1611
octave_value op_el_div(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1619
#define INSTALL_ASSIGNCONV_TI(ti, t1, t2, tr)
Definition: ops.h:71
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
Complex complex_value(bool=false) const
Definition: ov-complex.cc:225
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1616
#define DEFCMPLXCMPOP_OP(name, t1, t2, op)
Definition: ops.h:281
void install_cs_cs_ops(octave::type_info &ti)
Definition: op-cs-cs.cc:157
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1603
octave_value op_ldiv(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1609
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1604
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1618
#define DEFBINOP_FN(name, t1, t2, f)
Definition: ops.h:324
std::complex< double > Complex
Definition: oct-cmplx.h:31
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1578
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1614
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:382
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1575
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1605
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1615
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 * x
#define DEFNCUNOP_METHOD(name, t, method)
Definition: ops.h:251