GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base-scalar.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 // This file should not include config.h. It is only included in other
24 // C++ source files that should have included config.h before including
25 // this file.
26 
27 #include <iostream>
28 
29 #include "oct-inttypes.h"
30 
31 #include "ovl.h"
32 #include "ov-base.h"
33 #include "ov-cx-mat.h"
34 #include "ov-re-mat.h"
35 #include "ov-base-scalar.h"
36 #include "pr-output.h"
37 
38 template <typename ST>
41  const std::list<octave_value_list>& idx)
42 {
44 
45  switch (type[0])
46  {
47  case '(':
48  retval = do_index_op (idx.front ());
49  break;
50 
51  case '{':
52  case '.':
53  {
54  std::string nm = type_name ();
55  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
56  }
57  break;
58 
59  default:
61  }
62 
63  return retval.next_subsref (type, idx);
64 }
65 
66 template <typename ST>
69  const std::list<octave_value_list>& idx,
70  const octave_value& rhs)
71 {
73 
74  switch (type[0])
75  {
76  case '(':
77  {
78  if (type.length () != 1)
79  {
80  std::string nm = type_name ();
81  error ("in indexed assignment of %s, last rhs index must be ()",
82  nm.c_str ());
83  }
84 
85  retval = numeric_assign (type, idx, rhs);
86  }
87  break;
88 
89  case '{':
90  case '.':
91  {
92  std::string nm = type_name ();
93  error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
94  }
95  break;
96 
97  default:
99  }
100 
101  return retval;
102 }
103 
104 template <typename ST>
107 {
108  static dim_vector dv (1, 1);
109  return dv;
110 }
111 
112 template <typename ST>
114 octave_base_scalar<ST>::permute (const Array<int>& vec, bool inv) const
115 {
116  return Array<ST> (dim_vector (1, 1), scalar).permute (vec, inv);
117 }
118 
119 template <typename ST>
122 {
123  return Array<ST> (dim_vector (1, 1), scalar).reshape (new_dims);
124 }
125 
126 template <typename ST>
129 {
130  return Array<ST> (dim_vector (1, 1), scalar).diag (k);
131 }
132 
133 template <typename ST>
136 {
137  return Array<ST> (dim_vector (1, 1), scalar).diag (m, n);
138 }
139 
140 template <typename ST>
141 bool
143 {
146 
147  return (scalar != ST ());
148 }
149 
150 template <typename ST>
151 void
152 octave_base_scalar<ST>::print (std::ostream& os, bool pr_as_read_syntax)
153 {
154  print_raw (os, pr_as_read_syntax);
155  newline (os);
156 }
157 
158 template <typename ST>
159 void
161  bool pr_as_read_syntax) const
162 {
163  indent (os);
164  octave_print_internal (os, scalar, pr_as_read_syntax);
165 }
166 
167 template <typename ST>
168 bool
170  const std::string& name) const
171 {
172  indent (os);
173  os << name << " = ";
174  return false;
175 }
176 
177 template <typename ST>
178 void
180 {
181  std::ostringstream buf;
183  std::string tmp = buf.str ();
184  size_t pos = tmp.find_first_not_of (' ');
185  if (pos != std::string::npos)
186  os << tmp.substr (pos);
187  else if (! tmp.empty ())
188  os << tmp[0];
189 }
190 
191 template <typename ST>
194 {
195  return make_format (scalar);
196 }
197 
198 template <typename ST>
202 {
203  std::ostringstream buf;
204  octave_print_internal (buf, fmt, scalar);
205  return buf.str ();
206 }
207 
208 template <typename ST>
211 {
212  return (n == 0) ? octave_value (scalar) : octave_value ();
213 }
214 
215 template <typename ST>
216 bool
218  builtin_type_t btyp) const
219 {
220 
221  // Don't use builtin_type () here to avoid an extra VM call.
222  if (btyp == class_to_btyp<ST>::btyp)
223  {
224  *(reinterpret_cast<ST *>(where)) = scalar;
225  return true;
226  }
227  else
228  return false;
229 }
float_display_format get_edit_display_format(void) const
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5264
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
for large enough k
Definition: lu.cc:617
bool isnan(bool)
Definition: lo-mappers.h:187
void error(const char *fmt,...)
Definition: error.cc:578
builtin_type_t
Definition: ov-base.h:71
void err_nan_to_logical_conversion(void)
octave_value reshape(const dim_vector &new_dims) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
Definition: pr-output.cc:1780
nd deftypefn *std::string name
Definition: sysdep.cc:647
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
bool is_true(void) const
double tmp
Definition: data.cc:6252
bool print_name_tag(std::ostream &os, const std::string &name) const
octave_value retval
Definition: data.cc:6246
#define panic_impossible()
Definition: error.h:40
idx type
Definition: ov.cc:3114
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
float_display_format make_format(const double &d)
Definition: pr-output.cc:591
bool fast_elem_insert_self(void *where, builtin_type_t btyp) const
dim_vector dims(void) const
void short_disp(std::ostream &os) const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_value fast_elem_extract(octave_idx_type n) const
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
dim_vector dv
Definition: sub2ind.cc:263
octave_value diag(octave_idx_type k=0) const
octave_value permute(const Array< int > &, bool=false) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
octave::stream os
Definition: file-io.cc:627