comparison libinterp/operators/op-range.cc @ 28524:455fe4a6f22c

deprecate arithmetic operators for ranges; eliminate use in Octave * Range.h, Range.cc: Deprecate unary -, binary +, -, *, and / operators for Range objects. (Range::m_cache): Delete mutable data member. Remove all uses. (Range::clear_cache): Delete function and all uses. * op-range.cc: Eliminate special arithmetic operators for ranges. All computations will now be performed as arrays. Eliminate special concatenation functions.
author John W. Eaton <jwe@octave.org>
date Wed, 01 Jul 2020 15:33:53 -0400
parents c20b7290c778
children 7854d5752dd2
comparison
equal deleted inserted replaced
28523:68000a4df5a8 28524:455fe4a6f22c
29 29
30 #include "errwarn.h" 30 #include "errwarn.h"
31 #include "ovl.h" 31 #include "ovl.h"
32 #include "ov.h" 32 #include "ov.h"
33 #include "ov-range.h" 33 #include "ov-range.h"
34 #include "ov-ch-mat.h"
35 #include "ov-scalar.h"
36 #include "ov-re-mat.h" 34 #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" 35 #include "ov-typeinfo.h"
43 #include "ov-null-mat.h" 36 #include "ov-null-mat.h"
44 #include "ops.h" 37 #include "ops.h"
45 #include "xpow.h"
46 38
47 // range unary ops. 39 // Allow +RNG_VAL to avoid conversion to array.
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 */) 40 DEFUNOP_OP (uplus, range, /* no-op */)
57 DEFUNOP_OP (uminus, range, -)
58
59 DEFUNOP (transpose, range)
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 41
92 CONVDECL (range_to_matrix) 42 CONVDECL (range_to_matrix)
93 { 43 {
94 const octave_range& v = dynamic_cast<const octave_range&> (a); 44 const octave_range& v = dynamic_cast<const octave_range&> (a);
95 45
97 } 47 }
98 48
99 void 49 void
100 install_range_ops (octave::type_info& ti) 50 install_range_ops (octave::type_info& ti)
101 { 51 {
102 INSTALL_UNOP_TI (ti, op_not, octave_range, not);
103 INSTALL_UNOP_TI (ti, op_uplus, octave_range, uplus); 52 INSTALL_UNOP_TI (ti, op_uplus, octave_range, uplus);
104 INSTALL_UNOP_TI (ti, op_uminus, octave_range, uminus);
105 INSTALL_UNOP_TI (ti, op_transpose, octave_range, transpose);
106 INSTALL_UNOP_TI (ti, op_hermitian, octave_range, transpose);
107
108 INSTALL_BINOP_TI (ti, op_add, octave_range, octave_scalar, addrs);
109 INSTALL_BINOP_TI (ti, op_add, octave_scalar, octave_range, addsr);
110 INSTALL_BINOP_TI (ti, op_sub, octave_range, octave_scalar, subrs);
111 INSTALL_BINOP_TI (ti, op_sub, octave_scalar, octave_range, subsr);
112 INSTALL_BINOP_TI (ti, op_mul, octave_range, octave_scalar, mulrs);
113 INSTALL_BINOP_TI (ti, op_mul, octave_scalar, octave_range, mulsr);
114
115 INSTALL_BINOP_TI (ti, op_el_mul, octave_range, octave_scalar, mulrs);
116 INSTALL_BINOP_TI (ti, op_el_mul, octave_scalar, octave_range, mulsr);
117 INSTALL_BINOP_TI (ti, op_el_pow, octave_scalar, octave_range, el_powsr);
118 INSTALL_BINOP_TI (ti, op_el_pow, octave_complex, octave_range, el_powcsr);
119
120 INSTALL_CATOP_TI (ti, octave_range, octave_range, r_r);
121 INSTALL_CATOP_TI (ti, octave_range, octave_scalar, r_s);
122 INSTALL_CATOP_TI (ti, octave_range, octave_matrix, r_m);
123 INSTALL_CATOP_TI (ti, octave_range, octave_complex, r_cs);
124 INSTALL_CATOP_TI (ti, octave_range, octave_complex_matrix, r_cm);
125 INSTALL_CATOP_TI (ti, octave_range, octave_bool, r_b);
126 INSTALL_CATOP_TI (ti, octave_range, octave_bool_matrix, r_bm);
127 INSTALL_CATOP_TI (ti, octave_range, octave_char_matrix, r_chm);
128 INSTALL_CATOP_TI (ti, octave_scalar, octave_range, s_r);
129 INSTALL_CATOP_TI (ti, octave_matrix, octave_range, m_r);
130 INSTALL_CATOP_TI (ti, octave_complex, octave_range, cs_r);
131 INSTALL_CATOP_TI (ti, octave_complex_matrix, octave_range, cm_r);
132 INSTALL_CATOP_TI (ti, octave_bool, octave_range, b_r);
133 INSTALL_CATOP_TI (ti, octave_bool_matrix, octave_range, bm_r);
134 INSTALL_CATOP_TI (ti, octave_char_matrix, octave_range, chm_r);
135 53
136 // FIXME: this would be unnecessary if 54 // FIXME: this would be unnecessary if
137 // octave_base_value::numeric_assign always tried converting lhs 55 // octave_base_value::numeric_assign always tried converting lhs
138 // before rhs. 56 // before rhs.
139 57
140 INSTALL_ASSIGNCONV_TI (ti, octave_range, octave_null_matrix, octave_matrix); 58 INSTALL_ASSIGNCONV_TI (ti, octave_range, octave_null_matrix, octave_matrix);
141 INSTALL_ASSIGNCONV_TI (ti, octave_range, octave_null_str, octave_matrix); 59 INSTALL_ASSIGNCONV_TI (ti, octave_range, octave_null_str, octave_matrix);
142 INSTALL_ASSIGNCONV_TI (ti, octave_range, octave_null_sq_str, octave_matrix); 60 INSTALL_ASSIGNCONV_TI (ti, octave_range, octave_null_sq_str, octave_matrix);
143 61
144 // However, this should probably be here just in case we need it. 62 // Hmm, this one also seems to be needed.
145 63
146 INSTALL_WIDENOP_TI (ti, octave_range, octave_matrix, range_to_matrix); 64 INSTALL_WIDENOP_TI (ti, octave_range, octave_matrix, range_to_matrix);
147 } 65 }