GNU Octave  4.4.1
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-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 #if ! defined (octave_ov_base_scalar_h)
24 #define octave_ov_base_scalar_h 1
25 
26 #include "octave-config.h"
27 
28 #include <cstdlib>
29 
30 #include <iosfwd>
31 #include <string>
32 
33 #include "lo-mappers.h"
34 #include "lo-utils.h"
35 #include "str-vec.h"
36 #include "MatrixType.h"
37 
38 #include "ov-base.h"
39 #include "ov-typeinfo.h"
40 
41 // Real scalar values.
42 
43 template <typename ST>
44 class
46 {
47 public:
48 
50  : octave_base_value (), scalar () { }
51 
52  octave_base_scalar (const ST& s)
53  : octave_base_value (), scalar (s) { }
54 
56  : octave_base_value (), scalar (s.scalar) { }
57 
58  ~octave_base_scalar (void) = default;
59 
60  octave_value squeeze (void) const { return scalar; }
61 
62  octave_value full_value (void) const { return scalar; }
63 
65  const std::list<octave_value_list>& idx);
66 
68  const std::list<octave_value_list>& idx, int)
69  { return subsref (type, idx); }
70 
72  const std::list<octave_value_list>& idx,
73  const octave_value& rhs);
74 
75  bool is_constant (void) const { return true; }
76 
77  bool is_defined (void) const { return true; }
78 
79  dim_vector dims (void) const;
80 
81  octave_idx_type numel (void) const { return 1; }
82 
83  int ndims (void) const { return 2; }
84 
85  octave_idx_type nnz (void) const { return (scalar != ST () ? 1 : 0); }
86 
87  octave_value permute (const Array<int>&, bool = false) const;
88 
89  octave_value reshape (const dim_vector& new_dims) const;
90 
91  size_t byte_size (void) const { return sizeof (ST); }
92 
93  octave_value all (int = 0) const { return (scalar != ST ()); }
94 
95  octave_value any (int = 0) const { return (scalar != ST ()); }
96 
97  octave_value diag (octave_idx_type k = 0) const;
98 
100 
102  { return octave_value (scalar); }
104  sortmode) const
105  {
106  sidx.resize (dim_vector (1, 1));
107  sidx(0) = 0;
108  return octave_value (scalar);
109  }
110 
112  { return mode ? mode : ASCENDING; }
113 
115  {
116  return Array<octave_idx_type> (dim_vector (1, 1),
117  static_cast<octave_idx_type> (0));
118  }
119 
121  { return mode ? mode : ASCENDING; }
122 
123  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
125  { return matrix_type (); }
126 
127  bool is_scalar_type (void) const { return true; }
128 
129  bool isnumeric (void) const { return true; }
130 
131  bool is_true (void) const;
132 
133  void print (std::ostream& os, bool pr_as_read_syntax = false);
134 
135  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
136 
137  bool print_name_tag (std::ostream& os, const std::string& name) const;
138 
139  void short_disp (std::ostream& os) const;
140 
142 
143  std::string edit_display (const float_display_format& fmt,
145 
146  // Unsafe. This function exists to support the MEX interface.
147  // You should not use it anywhere else.
148  void * mex_get_data (void) const { return const_cast<ST *> (&scalar); }
149 
150  const ST& scalar_ref (void) const { return scalar; }
151 
152  ST& scalar_ref (void) { return scalar; }
153 
154  octave_value fast_elem_extract (octave_idx_type n) const;
155 
156  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
157 
158 protected:
159 
160  // The value of this scalar.
161  ST scalar;
162 };
163 
164 #endif
octave_value squeeze(void) const
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5264
bool is_scalar_type(void) const
sortmode
Definition: oct-sort.h:105
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6348
idx subsref(val, idx) esult
Definition: ov.cc:3065
for large enough k
Definition: lu.cc:617
octave_idx_type numel(void) const
sortmode issorted(sortmode mode=UNSORTED) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
s
Definition: file-io.cc:2729
builtin_type_t
Definition: ov-base.h:71
bool isnumeric(void) const
int ndims(void) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
void * mex_get_data(void) const
octave_idx_type nnz(void) const
size_t byte_size(void) const
octave_value full_value(void) const
nd deftypefn *std::string name
Definition: sysdep.cc:647
octave_base_scalar(const octave_base_scalar &s)
const ST & scalar_ref(void) const
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
Definition: Array.cc:1010
bool is_true(const std::string &s)
idx type
Definition: ov.cc:3114
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
bool is_constant(void) const
octave_value all(int=0) const
octave_base_scalar(const ST &s)
Array< octave_idx_type > sort_rows_idx(sortmode) const
bool is_defined(void) const
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3114
MatrixType matrix_type(void) const
MatrixType matrix_type(const MatrixType &) const
for i
Definition: data.cc:5264
octave_value any(int=0) const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type, sortmode) const
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_value sort(octave_idx_type, sortmode) const
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
octave::stream os
Definition: file-io.cc:627
static float_display_format get_edit_display_format(const octave_value &val)