GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base-scalar.h
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 (octave_ov_base_scalar_h)
27 #define octave_ov_base_scalar_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "lo-mappers.h"
37 #include "lo-utils.h"
38 #include "str-vec.h"
39 #include "MatrixType.h"
40 
41 #include "ov-base.h"
42 #include "ov-typeinfo.h"
43 
44 // Real scalar values.
45 
46 template <typename ST>
47 class
49 {
50 public:
51 
53  : octave_base_value (), scalar () { }
54 
55  octave_base_scalar (const ST& s)
56  : octave_base_value (), scalar (s) { }
57 
59  : octave_base_value (), scalar (s.scalar) { }
60 
61  ~octave_base_scalar (void) = default;
62 
63  octave_value squeeze (void) const { return scalar; }
64 
65  octave_value full_value (void) const { return scalar; }
66 
67  // We don't need to override all three forms of subsref. The using
68  // declaration will avoid warnings about partially-overloaded virtual
69  // functions.
71 
72  octave_value subsref (const std::string& type,
73  const std::list<octave_value_list>& idx);
74 
75  octave_value_list subsref (const std::string& type,
76  const std::list<octave_value_list>& idx, int)
77  { return subsref (type, idx); }
78 
79  octave_value subsasgn (const std::string& type,
80  const std::list<octave_value_list>& idx,
81  const octave_value& rhs);
82 
83  bool is_constant (void) const { return true; }
84 
85  bool is_defined (void) const { return true; }
86 
87  dim_vector dims (void) const;
88 
89  octave_idx_type numel (void) const { return 1; }
90 
91  int ndims (void) const { return 2; }
92 
93  octave_idx_type nnz (void) const { return (scalar != ST () ? 1 : 0); }
94 
95  octave_value permute (const Array<int>&, bool = false) const;
96 
97  octave_value reshape (const dim_vector& new_dims) const;
98 
99  size_t byte_size (void) const { return sizeof (ST); }
100 
101  octave_value all (int = 0) const { return (scalar != ST ()); }
102 
103  octave_value any (int = 0) const { return (scalar != ST ()); }
104 
105  octave_value diag (octave_idx_type k = 0) const;
106 
108 
110  { return octave_value (scalar); }
112  sortmode) const
113  {
114  sidx.resize (dim_vector (1, 1));
115  sidx(0) = 0;
116  return octave_value (scalar);
117  }
118 
120  { return mode == UNSORTED ? ASCENDING : mode; }
121 
123  {
124  return Array<octave_idx_type> (dim_vector (1, 1),
125  static_cast<octave_idx_type> (0));
126  }
127 
129  { return mode == UNSORTED ? ASCENDING : mode; }
130 
131  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
133  { return matrix_type (); }
134 
135  bool is_scalar_type (void) const { return true; }
136 
137  bool isnumeric (void) const { return true; }
138 
139  bool is_true (void) const;
140 
141  void print (std::ostream& os, bool pr_as_read_syntax = false);
142 
143  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
144 
145  bool print_name_tag (std::ostream& os, const std::string& name) const;
146 
147  void short_disp (std::ostream& os) const;
148 
150 
151  std::string edit_display (const float_display_format& fmt,
152  octave_idx_type i, octave_idx_type j) const;
153 
154  // Unsafe. This function exists to support the MEX interface.
155  // You should not use it anywhere else.
156  void * mex_get_data (void) const { return const_cast<ST *> (&scalar); }
157 
158  const ST& scalar_ref (void) const { return scalar; }
159 
160  ST& scalar_ref (void) { return scalar; }
161 
162  octave_value fast_elem_extract (octave_idx_type n) const;
163 
164  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
165 
166 protected:
167 
168  // The value of this scalar.
169  ST scalar;
170 };
171 
172 #endif
template class OCTAVE_API Array< octave_idx_type >
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1011
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
bool is_scalar_type(void) const
octave_base_scalar(const ST &s)
octave_idx_type nnz(void) const
bool isnumeric(void) const
Array< octave_idx_type > sort_rows_idx(sortmode) const
size_t byte_size(void) const
const ST & scalar_ref(void) const
octave_base_scalar(const octave_base_scalar &s)
bool is_constant(void) const
octave_value squeeze(void) const
int ndims(void) const
MatrixType matrix_type(const MatrixType &) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
void * mex_get_data(void) const
~octave_base_scalar(void)=default
octave_value any(int=0) const
octave_value sort(octave_idx_type, sortmode) const
octave_idx_type numel(void) const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type, sortmode) const
sortmode issorted(sortmode mode=UNSORTED) const
MatrixType matrix_type(void) const
octave_value full_value(void) const
bool is_defined(void) const
octave_value all(int=0) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:201
QString name
bool is_true(const std::string &s)
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
static float_display_format get_edit_display_format(const octave_value &val)
sortmode
Definition: oct-sort.h:95
@ UNSORTED
Definition: oct-sort.h:95
@ ASCENDING
Definition: oct-sort.h:95
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
builtin_type_t
Definition: ov-base.h:72
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:669