GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-range.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 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 "errwarn.h"
31 #include "ovl.h"
32 #include "ov.h"
33 #include "ov-range.h"
34 #include "ov-ch-mat.h"
35 #include "ov-scalar.h"
36 #include "ov-re-mat.h"
37 #include "ov-flt-re-mat.h"
38 #include "ov-complex.h"
39 #include "ov-cx-mat.h"
40 #include "ov-bool.h"
41 #include "ov-bool-mat.h"
42 #include "ov-typeinfo.h"
43 #include "ov-null-mat.h"
44 #include "ops.h"
45 #include "xpow.h"
46 
47 // range unary ops.
48 
49 DEFUNOP (not, range)
50 {
51  const octave_range& v = dynamic_cast<const octave_range&> (a);
52 
53  return octave_value (! v.matrix_value ());
54 }
55 
56 DEFUNOP_OP (uplus, range, /* no-op */)
57 DEFUNOP_OP (uminus, range, -)
58 
60 {
61  const octave_range& v = dynamic_cast<const octave_range&> (a);
62 
63  return octave_value (v.matrix_value ().transpose ());
64 }
65 
66 DEFBINOP_OP (addrs, range, scalar, +)
67 DEFBINOP_OP (addsr, scalar, range, +)
68 DEFBINOP_OP (subrs, range, scalar, -)
69 DEFBINOP_OP (subsr, scalar, range, -)
70 DEFBINOP_OP (mulrs, range, scalar, *)
71 DEFBINOP_OP (mulsr, scalar, range, *)
72 
73 DEFBINOP_FN (el_powsr, scalar, range, elem_xpow)
74 DEFBINOP_FN (el_powcsr, complex, range, elem_xpow)
75 
76 DEFNDCATOP_FN (r_r, range, range, array, array, concat)
77 DEFNDCATOP_FN (r_s, range, scalar, array, array, concat)
78 DEFNDCATOP_FN (r_m, range, matrix, array, array, concat)
79 DEFNDCATOP_FN (r_cs, range, complex, array, complex_array, concat)
80 DEFNDCATOP_FN (r_cm, range, complex_matrix, array, complex_array, concat)
81 DEFNDCATOP_FN (r_b, range, bool, array, array, concat)
82 DEFNDCATOP_FN (r_bm, range, bool_matrix, array, array, concat)
83 DEFNDCATOP_FN (r_chm, range, char_matrix, array, char_array, concat)
84 DEFNDCATOP_FN (s_r, scalar, range, array, array, concat)
85 DEFNDCATOP_FN (m_r, matrix, range, array, array, concat)
86 DEFNDCATOP_FN (cs_r, complex, range, complex_array, array, concat)
87 DEFNDCATOP_FN (cm_r, complex_matrix, range, complex_array, array, concat)
88 DEFNDCATOP_FN (b_r, bool, range, array, array, concat)
89 DEFNDCATOP_FN (bm_r, bool_matrix, range, array, array, concat)
90 DEFNDCATOP_FN (chm_r, char_matrix, range, char_array, array, concat)
91 
92 CONVDECL (range_to_matrix)
93 {
94  const octave_range& v = dynamic_cast<const octave_range&> (a);
95 
96  return new octave_matrix (v.array_value ());
97 }
98 
99 void
101 {
102  INSTALL_UNOP_TI (ti, op_not, octave_range, not);
103  INSTALL_UNOP_TI (ti, op_uplus, octave_range, uplus);
104  INSTALL_UNOP_TI (ti, op_uminus, octave_range, uminus);
107 
114 
119 
135 
136  // FIXME: this would be unnecessary if
137  // octave_base_value::numeric_assign always tried converting lhs
138  // before rhs.
139 
143 
144  // However, this should probably be here just in case we need it.
145 
146  INSTALL_WIDENOP_TI (ti, octave_range, octave_matrix, range_to_matrix);
147 }
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
Matrix transpose(void) const
Definition: dMatrix.h:135
NDArray array_value(bool=false) const
Definition: ov-range.h:196
Matrix matrix_value(bool=false) const
Definition: ov-range.h:190
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
void install_range_ops(octave::type_info &ti)
Definition: op-range.cc:100
#define DEFUNOP_OP(name, t, op)
Definition: ops.h:183
#define DEFBINOP_FN(name, t1, t2, f)
Definition: ops.h:290
#define DEFBINOP_OP(name, t1, t2, op)
Definition: ops.h:235
#define INSTALL_ASSIGNCONV_TI(ti, t1, t2, tr)
Definition: ops.h:73
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:55
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f)
Definition: ops.h:348
#define INSTALL_WIDENOP_TI(ti, t1, t2, f)
Definition: ops.h:77
#define CONVDECL(name)
Definition: ops.h:168
#define DEFUNOP(name, t)
Definition: ops.h:179
#define INSTALL_CATOP_TI(ti, t1, t2, f)
Definition: ops.h:60
#define INSTALL_UNOP_TI(ti, op, t, f)
Definition: ops.h:47
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:669
octave_value op_uplus(const octave_value &a)
Definition: ov.h:1537
octave_value op_add(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1566
octave_value op_uminus(const octave_value &a)
Definition: ov.h:1538
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1540
octave_value op_sub(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1567
octave_value op_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1568
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1541
octave_value op_el_pow(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1583
octave_value op_not(const octave_value &a)
Definition: ov.h:1536
octave_value op_el_mul(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1581
octave_value elem_xpow(double a, const SparseMatrix &b)
Definition: sparse-xpow.cc:249
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:389