GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
op-str-str.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 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-str-mat.h"
34 #include "ov-typeinfo.h"
35 #include "ov-null-mat.h"
36 #include "ops.h"
37 
39 
40 // string unary ops.
41 
42 DEFUNOP (transpose, char_matrix_str)
43 {
44  const octave_char_matrix_str& v
45  = dynamic_cast<const octave_char_matrix_str&> (a);
46 
47  if (v.ndims () > 2)
48  error ("transpose not defined for N-D objects");
49 
51  a.is_sq_string () ? '\'' : '"');
52 }
53 
54 // string by string ops.
55 
56 #define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f) \
57  static octave_value \
58  CONCAT2(oct_binop_, name) (const octave_base_value& a1, \
59  const octave_base_value& a2) \
60  { \
61  dim_vector a1_dims = a1.dims (); \
62  dim_vector a2_dims = a2.dims (); \
63  \
64  bool a1_is_scalar = a1_dims.all_ones (); \
65  bool a2_is_scalar = a2_dims.all_ones (); \
66  \
67  const octave_ ## t1& v1 = dynamic_cast<const octave_ ## t1&> (a1); \
68  const octave_ ## t2& v2 = dynamic_cast<const octave_ ## t2&> (a2); \
69  \
70  if (a1_is_scalar) \
71  { \
72  if (a2_is_scalar) \
73  return octave_value ((v1.e1 ## _value ())(0) \
74  op (v2.e2 ## _value ())(0)); \
75  else \
76  return octave_value (f ((v1.e1 ## _value ())(0), \
77  v2.e2 ## _value ())); \
78  } \
79  else \
80  { \
81  if (a2_is_scalar) \
82  return octave_value (f (v1.e1 ## _value (), \
83  (v2.e2 ## _value ())(0))); \
84  else \
85  return octave_value (f (v1.e1 ## _value (), \
86  v2.e2 ## _value ())); \
87  } \
88  }
89 
90 DEFCHARNDBINOP_FN (lt, <, char_matrix_str, char_matrix_str, char_array,
91  char_array, mx_el_lt)
92 DEFCHARNDBINOP_FN (le, <=, char_matrix_str, char_matrix_str, char_array,
93  char_array, mx_el_le)
94 DEFCHARNDBINOP_FN (eq, ==, char_matrix_str, char_matrix_str, char_array,
95  char_array, mx_el_eq)
96 DEFCHARNDBINOP_FN (ge, >=, char_matrix_str, char_matrix_str, char_array,
97  char_array, mx_el_ge)
98 DEFCHARNDBINOP_FN (gt, >, char_matrix_str, char_matrix_str, char_array,
99  char_array, mx_el_gt)
100 DEFCHARNDBINOP_FN (ne, !=, char_matrix_str, char_matrix_str, char_array,
101  char_array, mx_el_ne)
102 
103 DEFASSIGNOP (assign, char_matrix_str, char_matrix_str)
104 {
105  octave_char_matrix_str& v1 = dynamic_cast<octave_char_matrix_str&> (a1);
107  = dynamic_cast<const octave_char_matrix_str&> (a2);
108 
109  v1.assign (idx, v2.char_array_value ());
110  return octave_value ();
111 }
112 
113 DEFNULLASSIGNOP_FN (null_assign, char_matrix_str, delete_elements)
114 
115 DEFNDCHARCATOP_FN (str_str, char_matrix_str, char_matrix_str, concat)
116 
117 void
119 {
122 
125 
127  lt);
129  lt);
131  lt);
134  lt);
135 
137  le);
139  le);
141  le);
144  le);
145 
147  eq);
149  eq);
151  eq);
154  eq);
155 
157  ge);
159  ge);
161  ge);
164  ge);
165 
167  gt);
169  gt);
171  gt);
174  gt);
175 
177  ne);
179  ne);
181  ne);
184  ne);
185 
188  str_str);
190  str_str);
192  str_str);
193 
196  assign);
199  assign);
202  assign);
204  octave_char_matrix_sq_str, assign);
205 
207  null_assign);
209  null_assign);
211  null_assign);
214  null_assign);
216  null_assign);
219  null_assign);
220 
221 }
222 
OCTAVE_END_NAMESPACE(octave)
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:418
boolMatrix mx_el_le(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_ne(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_gt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_eq(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_lt(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
boolMatrix mx_el_ge(const boolMatrix &m1, const boolMatrix &m2)
Definition: boolMatrix.cc:91
charMatrix transpose(void) const
Definition: chMatrix.h:80
int ndims(void) const
Definition: ov-base-mat.h:121
OCTINTERP_API void assign(const octave_value_list &idx, const MT &rhs)
Definition: ov-base-mat.cc:225
charMatrix char_matrix_value(bool=false) const
Definition: ov-ch-mat.h:142
charNDArray char_array_value(bool=false) const
Definition: ov-ch-mat.h:145
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
const octave_base_value & a2
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
#define DEFCHARNDBINOP_FN(name, op, t1, t2, e1, e2, f)
Definition: op-str-str.cc:56
void install_str_str_ops(octave::type_info &ti)
Definition: op-str-str.cc:118
#define DEFNULLASSIGNOP_FN(name, t, f)
Definition: ops.h:100
#define DEFASSIGNOP(name, t1, t2)
Definition: ops.h:81
#define INSTALL_BINOP_TI(ti, op, t1, t2, f)
Definition: ops.h:55
#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
#define INSTALL_ASSIGNOP_TI(ti, op, t1, t2, f)
Definition: ops.h:64
#define DEFNDCHARCATOP_FN(name, t1, t2, f)
Definition: ops.h:361
octave_value op_ne(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1881
octave_value op_gt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1880
octave_value op_transpose(const octave_value &a)
Definition: ov.h:1842
octave_value op_hermitian(const octave_value &a)
Definition: ov.h:1843
octave_value op_le(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1877
octave_value op_eq(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1878
octave_value op_ge(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1879
octave_value op_lt(const octave_value &a1, const octave_value &a2)
Definition: ov.h:1876
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:391