GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-base-scalar.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 
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 
76  { return do_index_op (idx); }
77 
78  bool is_constant (void) const { return true; }
79 
80  bool is_defined (void) const { return true; }
81 
82  dim_vector dims (void) const;
83 
84  octave_idx_type numel (void) const { return 1; }
85 
86  int ndims (void) const { return 2; }
87 
88  octave_idx_type nnz (void) const { return (scalar != ST ()) ? 1 : 0; }
89 
90  octave_value permute (const Array<int>&, bool = false) const;
91 
92  octave_value reshape (const dim_vector& new_dims) const;
93 
94  size_t byte_size (void) const { return sizeof (ST); }
95 
96  octave_value all (int = 0) const { return (scalar != ST ()); }
97 
98  octave_value any (int = 0) const { return (scalar != ST ()); }
99 
100  octave_value diag (octave_idx_type k = 0) const;
101 
103 
105  { return octave_value (scalar); }
107  sortmode) const
108  {
109  sidx.resize (dim_vector (1, 1));
110  sidx(0) = 0;
111  return octave_value (scalar);
112  }
113 
115  { return mode ? mode : ASCENDING; }
116 
118  {
119  return Array<octave_idx_type> (dim_vector (1, 1),
120  static_cast<octave_idx_type> (0));
121  }
122 
124  { return mode ? mode : ASCENDING; }
125 
126  MatrixType matrix_type (void) const { return MatrixType::Diagonal; }
128  { return matrix_type (); }
129 
130  bool is_scalar_type (void) const { return true; }
131 
132  bool is_numeric_type (void) const { return true; }
133 
134  bool is_true (void) const;
135 
136  void print (std::ostream& os, bool pr_as_read_syntax = false);
137 
138  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
139 
140  bool print_name_tag (std::ostream& os, const std::string& name) const;
141 
142  void short_disp (std::ostream& os) const;
143 
144  // Unsafe. This function exists to support the MEX interface.
145  // You should not use it anywhere else.
146  void *mex_get_data (void) const { return const_cast<ST *> (&scalar); }
147 
148  const ST& scalar_ref (void) const { return scalar; }
149 
150  ST& scalar_ref (void) { return scalar; }
151 
152  octave_value fast_elem_extract (octave_idx_type n) const;
153 
154  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
155 
156 protected:
157 
158  // The value of this scalar.
159  ST scalar;
160 };
161 
162 #endif
sortmode is_sorted(sortmode mode=UNSORTED) const
bool is_true(const std::string &s)
Definition: mkoctfile.cc:398
size_t byte_size(void) const
const ST & scalar_ref(void) const
MatrixType matrix_type(void) const
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5342
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
sortmode
Definition: oct-sort.h:105
octave_value_list do_multi_index_op(int, const octave_value_list &idx)
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:6386
idx subsref(val, idx) esult
Definition: ov.cc:3080
octave_value any(int=0) const
bool is_scalar_type(void) const
for large enough k
Definition: lu.cc:606
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
octave_idx_type nnz(void) const
s
Definition: file-io.cc:2682
builtin_type_t
Definition: ov-base.h:61
bool is_defined(void) const
octave_value sort(octave_idx_type, sortmode) const
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
octave_base_scalar(const octave_base_scalar &s)
bool is_numeric_type(void) const
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
bool is_constant(void) const
octave_value squeeze(void) const
idx type
Definition: ov.cc:3129
MatrixType matrix_type(const MatrixType &) const
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
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type, sortmode) const
octave_base_scalar(const ST &s)
octave_value full_value(void) const
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
octave_idx_type numel(void) const
void * mex_get_data(void) const
Array< octave_idx_type > sort_rows_idx(sortmode) const
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
int ndims(void) 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:854
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
octave_value all(int=0) const