Mercurial > octave-nkf
annotate libinterp/octave-value/ov-fcn-inline.cc @ 18416:bcd71a2531d3
Support disp/display overloading in classdef
* ov-classdef.h (octave_classdef::print, octave_classdef::print_raw):
Move definition to C++ file.
(octave_classdef::print_as_scalar): Removed method.
(octave_classdef::print_name_tag, octave_classdef::print_with_name):
New methods.
* ov-classdef.cc (octave_classdef::print): Moved from header.
(octave_classdef::print_raw): Likewise. Call overloaded disp, if
defined and not called from builtin.
(octave_classdef::print_name_tag): New method.
(octave_classdef::print_with_name): New method, calls overloaded
"display" if defined.
* pr-output.cc (octave_print_internal(std::ostream, bool): Avoid
compilation warning.
(Frats, Fdisp, Ffdisp): Allow to call non-const octave_value::print.
* ov.h (octave_value::print): Make non-const.
* ov-base.h (octave_base_value::print): Likewise.
* ov-base.cc (octave_base_value::print): Likewise.
* ov-base-diag.h (octave_base_diag::print): Likewise.
* ov-base-diag.cc (octave_base_diag::print): Likewise.
* ov-base-mat.h (octave_base_matrix::print): Likewise.
* ov-base-mat.cc (octave_base_matrix::print): Likewise.
* ov-base-scalar.h (octave_base_scalar::print): Likewise.
* ov-base-scalar.cc (octave_base_scalar::print): Likewise.
* ov-base-sparse.h (octave_base_sparse::print): Likewise.
* ov-base-sparse.cc (octave_base_sparse::print): Likewise.
* ov-cell.h (octave_cell::print): Likewise.
* ov-cell.cc (octave_cell::print): Likewise.
* ov-class.h (octave_class::print): Likewise.
* ov-class.cc (octave_class::print): Likewise.
* ov-colon.h (octave_magic_colon::print): Likewise.
* ov-colon.cc (octave_magic_colon::print): Likewise.
* ov-fcn-handle.h (octave_fcn_handle::print): Likewise.
* ov-fcn-handle.cc (octave_fcn_handle::print): Likewise.
* ov-fcn-inline.h (octave_fcn_inline::print): Likewise.
* ov-fcn-inline.cc (octave_fcn_inline::print): Likewise.
* ov-java.h (octave_java::print): Likewise.
* ov-java.cc (octave_java::print): Likewise.
* ov-lazy-idx.h (octave_lazy_index::print): Likewise.
* ov-oncleanup.h (octave_oncleanup::print): Likewise.
* ov-oncleanup.cc (octave_oncleanup::print): Likewise.
* ov-perm.h (octave_perm_matrix::print): Likewise.
* ov-perm.cc (octave_perm_matrix::print): Likewise.
* ov-range.h (octave_range::print): Likewise.
* ov-range.cc (octave_range::print): Likewise.
* ov-struct.h (octave_struct::print, octave_scalar_struct): Likewise.
* ov-struct.cc (octave_struct::print, octave_scalar_struct): Likewise.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Fri, 31 Jan 2014 11:41:19 -0500 |
parents | 6a71e5030df5 |
children | f958e8cd6348 |
rev | line source |
---|---|
4933 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
3 Copyright (C) 2004-2013 David Bateman |
4933 | 4 |
7016 | 5 This file is part of Octave. |
4933 | 6 |
7016 | 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. | |
4933 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4933 | 20 |
21 In addition to the terms of the GPL, you are permitted to link | |
22 this program with any Open Source program, as defined by the | |
23 Open Source Initiative (www.opensource.org) | |
24 | |
25 */ | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
4988 | 31 #include <istream> |
4933 | 32 #include <iostream> |
5765 | 33 #include <sstream> |
5164 | 34 #include <vector> |
4933 | 35 |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
36 #include "oct-locbuf.h" |
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
37 |
4933 | 38 #include "defun.h" |
39 #include "error.h" | |
40 #include "gripes.h" | |
41 #include "oct-map.h" | |
42 #include "ov-base.h" | |
43 #include "ov-fcn-inline.h" | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
44 #include "ov-usr-fcn.h" |
4933 | 45 #include "pr-output.h" |
46 #include "variables.h" | |
47 #include "parse.h" | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
48 #include "toplev.h" |
4933 | 49 |
4972 | 50 #include "byte-swap.h" |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
51 #include "ls-ascii-helper.h" |
4972 | 52 #include "ls-oct-ascii.h" |
53 #include "ls-hdf5.h" | |
54 #include "ls-utils.h" | |
55 | |
4933 | 56 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_inline); |
57 | |
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_inline, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
59 "inline function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 "function_handle"); |
4933 | 61 |
62 octave_fcn_inline::octave_fcn_inline (const std::string& f, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
63 const string_vector& a, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 const std::string& n) |
5007 | 65 : octave_fcn_handle (n), iftext (f), ifargs (a) |
4933 | 66 { |
4973 | 67 // Form a string representing the function. |
4933 | 68 |
5765 | 69 std::ostringstream buf; |
4933 | 70 |
5007 | 71 buf << "@("; |
4933 | 72 |
73 for (int i = 0; i < ifargs.length (); i++) | |
74 { | |
75 if (i > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 buf << ", "; |
4933 | 77 |
78 buf << ifargs(i); | |
79 } | |
80 | |
5765 | 81 buf << ") " << iftext; |
4933 | 82 |
5007 | 83 int parse_status; |
5765 | 84 octave_value anon_fcn_handle = eval_string (buf.str (), true, parse_status); |
4933 | 85 |
5007 | 86 if (parse_status == 0) |
4933 | 87 { |
5007 | 88 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
4933 | 89 |
5007 | 90 if (fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 fcn = fh->fcn_val (); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
93 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
94 octave_user_function *uf = fcn.user_function_value (); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
95 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
96 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 octave_function *curr_fcn = octave_call_stack::current (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
99 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 if (curr_fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 symbol_table::scope_id parent_scope |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 = curr_fcn->parent_fcn_scope (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 if (parent_scope < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 parent_scope = curr_fcn->scope (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
107 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
108 uf->stash_parent_fcn_scope (parent_scope); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 } |
4933 | 112 } |
5007 | 113 |
114 if (fcn.is_undefined ()) | |
4933 | 115 error ("inline: unable to define function"); |
116 } | |
117 | |
6625 | 118 // This function is supplied to allow a Matlab style class structure |
119 // to be returned.. | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
120 octave_map |
6625 | 121 octave_fcn_inline::map_value (void) const |
122 { | |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
123 octave_scalar_map m; |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
124 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
125 m.assign ("version", 1.0); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
126 m.assign ("isEmpty", 0.0); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
127 m.assign ("expr", fcn_text ()); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
128 |
6625 | 129 string_vector args = fcn_arg_names (); |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
130 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
131 m.assign ("numArgs", args.length ()); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
132 m.assign ("args", args); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
133 |
6625 | 134 std::ostringstream buf; |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
135 |
6625 | 136 for (int i = 0; i < args.length (); i++) |
137 buf << args(i) << " = INLINE_INPUTS_{" << i + 1 << "}; "; | |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
138 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
139 m.assign ("inputExpr", buf.str ()); |
6625 | 140 |
141 return m; | |
142 } | |
143 | |
4972 | 144 bool |
6974 | 145 octave_fcn_inline::save_ascii (std::ostream& os) |
4972 | 146 { |
4973 | 147 os << "# nargs: " << ifargs.length () << "\n"; |
4972 | 148 for (int i = 0; i < ifargs.length (); i++) |
4973 | 149 os << ifargs(i) << "\n"; |
150 if (nm.length () < 1) | |
151 // Write an invalid value to flag empty fcn handle name. | |
4972 | 152 os << "0\n"; |
153 else | |
154 os << nm << "\n"; | |
155 os << iftext << "\n"; | |
156 return true; | |
157 } | |
158 | |
159 bool | |
160 octave_fcn_inline::load_ascii (std::istream& is) | |
161 { | |
162 int nargs; | |
163 if (extract_keyword (is, "nargs", nargs, true)) | |
164 { | |
165 ifargs.resize (nargs); | |
166 for (int i = 0; i < nargs; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 is >> ifargs(i); |
4972 | 168 is >> nm; |
169 if (nm == "0") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 nm = ""; |
4988 | 171 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
172 skip_preceeding_newline (is); |
4988 | 173 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
174 std::string buf; |
4988 | 175 |
176 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 { |
4988 | 178 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 // Get a line of text whitespace characters included, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 // leaving newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 buf = read_until_newline (is, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
182 } |
4988 | 183 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
184 iftext = buf; |
4972 | 185 |
186 octave_fcn_inline tmp (iftext, ifargs, nm); | |
187 fcn = tmp.fcn; | |
188 | |
189 return true; | |
190 } | |
191 else | |
192 return false; | |
193 } | |
194 | |
4973 | 195 bool |
4972 | 196 octave_fcn_inline::save_binary (std::ostream& os, bool&) |
197 { | |
5828 | 198 int32_t tmp = ifargs.length (); |
5760 | 199 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 200 for (int i = 0; i < ifargs.length (); i++) |
4972 | 201 { |
4973 | 202 tmp = ifargs(i).length (); |
5760 | 203 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 204 os.write (ifargs(i).c_str (), ifargs(i).length ()); |
4972 | 205 } |
4973 | 206 tmp = nm.length (); |
5760 | 207 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 208 os.write (nm.c_str (), nm.length ()); |
209 tmp = iftext.length (); | |
5760 | 210 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 211 os.write (iftext.c_str (), iftext.length ()); |
4972 | 212 return true; |
213 } | |
214 | |
4973 | 215 bool |
4972 | 216 octave_fcn_inline::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 oct_mach_info::float_format) |
4972 | 218 { |
5828 | 219 int32_t nargs; |
5760 | 220 if (! is.read (reinterpret_cast<char *> (&nargs), 4)) |
4972 | 221 return false; |
222 if (swap) | |
223 swap_bytes<4> (&nargs); | |
224 | |
225 if (nargs < 1) | |
226 return false; | |
227 else | |
228 { | |
5828 | 229 int32_t tmp; |
4973 | 230 ifargs.resize (nargs); |
4972 | 231 for (int i = 0; i < nargs; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
232 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
233 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
234 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 swap_bytes<4> (&tmp); |
4972 | 237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 is.read (ctmp, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 ifargs(i) = std::string (ctmp); |
4972 | 241 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 } |
4972 | 245 |
5760 | 246 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 return false; |
4972 | 248 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 swap_bytes<4> (&tmp); |
4972 | 250 |
251 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
252 is.read (ctmp1, tmp); | |
253 nm = std::string (ctmp1); | |
254 | |
255 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
256 return false; |
4972 | 257 |
5760 | 258 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 return false; |
4972 | 260 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 swap_bytes<4> (&tmp); |
4972 | 262 |
263 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
264 is.read (ctmp2, tmp); | |
265 iftext = std::string (ctmp2); | |
266 | |
267 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 return false; |
4972 | 269 |
270 octave_fcn_inline ftmp (iftext, ifargs, nm); | |
271 fcn = ftmp.fcn; | |
272 } | |
273 return true; | |
274 } | |
275 | |
276 #if defined (HAVE_HDF5) | |
277 bool | |
278 octave_fcn_inline::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 bool /* save_as_floats */) |
4972 | 280 { |
281 hid_t group_hid = -1; | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
282 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
283 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
284 #else |
4972 | 285 group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
286 #endif |
4972 | 287 if (group_hid < 0 ) return false; |
288 | |
289 size_t len = 0; | |
4973 | 290 for (int i = 0; i < ifargs.length (); i++) |
291 if (len < ifargs(i).length ()) | |
292 len = ifargs(i).length (); | |
4972 | 293 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
294 hid_t space_hid, data_hid, type_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
295 space_hid = data_hid = type_hid = -1; |
4972 | 296 bool retval = true; |
297 | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
298 // FIXME: Is there a better way of saving string vectors, |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
299 // than a null padded matrix? |
4972 | 300 |
301 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
302 | |
303 // Octave uses column-major, while HDF5 uses row-major ordering | |
4973 | 304 hdims[1] = ifargs.length (); |
4972 | 305 hdims[0] = len + 1; |
306 | |
307 space_hid = H5Screate_simple (2, hdims, 0); | |
308 if (space_hid < 0) | |
309 { | |
310 H5Gclose (group_hid); | |
311 return false; | |
312 } | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
313 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
314 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
316 #else |
4973 | 317 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
318 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
319 #endif |
4972 | 320 if (data_hid < 0) |
321 { | |
322 H5Sclose (space_hid); | |
323 H5Gclose (group_hid); | |
324 return false; | |
325 } | |
326 | |
4973 | 327 OCTAVE_LOCAL_BUFFER (char, s, ifargs.length () * (len + 1)); |
4972 | 328 |
329 // Save the args as a null teminated list | |
4973 | 330 for (int i = 0; i < ifargs.length (); i++) |
4972 | 331 { |
4973 | 332 const char * cptr = ifargs(i).c_str (); |
333 for (size_t j = 0; j < ifargs(i).length (); j++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
334 s[i*(len+1)+j] = *cptr++; |
4973 | 335 s[ifargs(i).length ()] = '\0'; |
4972 | 336 } |
337 | |
4973 | 338 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 H5P_DEFAULT, s) >= 0; |
4972 | 340 |
341 H5Dclose (data_hid); | |
342 H5Sclose (space_hid); | |
343 | |
344 if (!retval) | |
345 { | |
346 H5Gclose (group_hid); | |
347 return false; | |
4973 | 348 } |
4972 | 349 |
350 // attach the type of the variable | |
4973 | 351 type_hid = H5Tcopy (H5T_C_S1); |
4972 | 352 H5Tset_size (type_hid, nm.length () + 1); |
353 if (type_hid < 0) | |
354 { | |
355 H5Gclose (group_hid); | |
356 return false; | |
4973 | 357 } |
4972 | 358 |
359 hdims[0] = 0; | |
5760 | 360 space_hid = H5Screate_simple (0 , hdims, 0); |
4972 | 361 if (space_hid < 0) |
362 { | |
363 H5Tclose (type_hid); | |
364 H5Gclose (group_hid); | |
365 return false; | |
4973 | 366 } |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
367 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
368 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
370 #else |
4972 | 371 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
372 #endif |
4973 | 373 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 H5P_DEFAULT, nm.c_str ()) < 0) |
4972 | 375 { |
376 H5Sclose (space_hid); | |
377 H5Tclose (type_hid); | |
378 H5Gclose (group_hid); | |
379 return false; | |
4973 | 380 } |
4972 | 381 H5Dclose (data_hid); |
382 | |
383 // attach the type of the variable | |
384 H5Tset_size (type_hid, iftext.length () + 1); | |
385 if (type_hid < 0) | |
386 { | |
387 H5Gclose (group_hid); | |
388 return false; | |
4973 | 389 } |
4972 | 390 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
391 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
392 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
393 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
394 #else |
4973 | 395 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
397 #endif |
4973 | 398 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 H5P_DEFAULT, iftext.c_str ()) < 0) |
4972 | 400 { |
401 H5Sclose (space_hid); | |
402 H5Tclose (type_hid); | |
403 H5Gclose (group_hid); | |
404 return false; | |
4973 | 405 } |
4972 | 406 |
407 H5Dclose (data_hid); | |
4988 | 408 H5Sclose (space_hid); |
409 H5Tclose (type_hid); | |
410 H5Gclose (group_hid); | |
4972 | 411 |
412 return retval; | |
413 } | |
414 | |
415 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9038
diff
changeset
|
416 octave_fcn_inline::load_hdf5 (hid_t loc_id, const char *name) |
4972 | 417 { |
418 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; | |
419 hsize_t rank; | |
420 int slen; | |
421 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
422 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
423 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
424 #else |
4972 | 425 group_hid = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
426 #endif |
4972 | 427 if (group_hid < 0 ) return false; |
428 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
429 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
430 data_hid = H5Dopen (group_hid, "args", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
431 #else |
4972 | 432 data_hid = H5Dopen (group_hid, "args"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
433 #endif |
4972 | 434 space_hid = H5Dget_space (data_hid); |
435 rank = H5Sget_simple_extent_ndims (space_hid); | |
436 | |
437 if (rank != 2) | |
4973 | 438 { |
4972 | 439 H5Dclose (data_hid); |
440 H5Sclose (space_hid); | |
441 H5Gclose (group_hid); | |
442 return false; | |
443 } | |
444 | |
445 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
446 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
447 | |
448 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
449 | |
4973 | 450 ifargs.resize (hdims[1]); |
4972 | 451 |
452 OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]); | |
453 | |
4973 | 454 if (H5Dread (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
455 H5P_DEFAULT, s1) < 0) |
4973 | 456 { |
4972 | 457 H5Dclose (data_hid); |
458 H5Sclose (space_hid); | |
459 H5Gclose (group_hid); | |
460 return false; | |
461 } | |
462 | |
463 H5Dclose (data_hid); | |
464 H5Sclose (space_hid); | |
465 | |
466 for (size_t i = 0; i < hdims[1]; i++) | |
467 ifargs(i) = std::string (s1 + i*hdims[0]); | |
468 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
469 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
470 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
471 #else |
4972 | 472 data_hid = H5Dopen (group_hid, "nm"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
473 #endif |
4972 | 474 |
475 if (data_hid < 0) | |
476 { | |
477 H5Gclose (group_hid); | |
478 return false; | |
479 } | |
480 | |
481 type_hid = H5Dget_type (data_hid); | |
482 type_class_hid = H5Tget_class (type_hid); | |
483 | |
484 if (type_class_hid != H5T_STRING) | |
485 { | |
486 H5Tclose (type_hid); | |
487 H5Dclose (data_hid); | |
488 H5Gclose (group_hid); | |
489 return false; | |
490 } | |
4973 | 491 |
4972 | 492 space_hid = H5Dget_space (data_hid); |
493 rank = H5Sget_simple_extent_ndims (space_hid); | |
494 | |
495 if (rank != 0) | |
496 { | |
497 H5Sclose (space_hid); | |
498 H5Tclose (type_hid); | |
499 H5Dclose (data_hid); | |
500 H5Gclose (group_hid); | |
501 return false; | |
502 } | |
503 | |
504 slen = H5Tget_size (type_hid); | |
505 if (slen < 0) | |
506 { | |
507 H5Sclose (space_hid); | |
508 H5Tclose (type_hid); | |
509 H5Dclose (data_hid); | |
510 H5Gclose (group_hid); | |
511 return false; | |
512 } | |
513 | |
514 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
515 | |
516 // create datatype for (null-terminated) string to read into: | |
517 st_id = H5Tcopy (H5T_C_S1); | |
518 H5Tset_size (st_id, slen); | |
519 | |
5760 | 520 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4972 | 521 { |
522 H5Sclose (space_hid); | |
523 H5Tclose (type_hid); | |
524 H5Gclose (group_hid); | |
525 return false; | |
526 } | |
527 H5Tclose (st_id); | |
528 H5Dclose (data_hid); | |
529 nm = nm_tmp; | |
530 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
531 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
532 data_hid = H5Dopen (group_hid, "iftext", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
533 #else |
4972 | 534 data_hid = H5Dopen (group_hid, "iftext"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
535 #endif |
4972 | 536 |
537 if (data_hid < 0) | |
538 { | |
539 H5Gclose (group_hid); | |
540 return false; | |
541 } | |
542 | |
543 type_hid = H5Dget_type (data_hid); | |
544 type_class_hid = H5Tget_class (type_hid); | |
545 | |
546 if (type_class_hid != H5T_STRING) | |
547 { | |
548 H5Tclose (type_hid); | |
549 H5Dclose (data_hid); | |
550 H5Gclose (group_hid); | |
551 return false; | |
552 } | |
4973 | 553 |
4972 | 554 space_hid = H5Dget_space (data_hid); |
555 rank = H5Sget_simple_extent_ndims (space_hid); | |
556 | |
557 if (rank != 0) | |
558 { | |
559 H5Sclose (space_hid); | |
560 H5Tclose (type_hid); | |
561 H5Dclose (data_hid); | |
562 H5Gclose (group_hid); | |
563 return false; | |
564 } | |
565 | |
566 slen = H5Tget_size (type_hid); | |
567 if (slen < 0) | |
568 { | |
569 H5Sclose (space_hid); | |
570 H5Tclose (type_hid); | |
571 H5Dclose (data_hid); | |
572 H5Gclose (group_hid); | |
573 return false; | |
574 } | |
575 | |
576 OCTAVE_LOCAL_BUFFER (char, iftext_tmp, slen); | |
577 | |
578 // create datatype for (null-terminated) string to read into: | |
579 st_id = H5Tcopy (H5T_C_S1); | |
580 H5Tset_size (st_id, slen); | |
581 | |
5760 | 582 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, iftext_tmp) < 0) |
4972 | 583 { |
584 H5Sclose (space_hid); | |
585 H5Tclose (type_hid); | |
586 H5Gclose (group_hid); | |
587 return false; | |
588 } | |
589 H5Tclose (st_id); | |
590 H5Dclose (data_hid); | |
591 iftext = iftext_tmp; | |
592 | |
593 octave_fcn_inline ftmp (iftext, ifargs, nm); | |
594 fcn = ftmp.fcn; | |
595 | |
596 return true; | |
597 } | |
598 #endif | |
599 | |
4933 | 600 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18099
diff
changeset
|
601 octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) |
4933 | 602 { |
603 print_raw (os, pr_as_read_syntax); | |
604 newline (os); | |
605 } | |
606 | |
607 void | |
608 octave_fcn_inline::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
609 { | |
5765 | 610 std::ostringstream buf; |
4933 | 611 |
612 if (nm.empty ()) | |
613 buf << "f("; | |
614 else | |
615 buf << nm << "("; | |
616 | |
617 for (int i = 0; i < ifargs.length (); i++) | |
618 { | |
619 if (i) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
620 buf << ", "; |
4933 | 621 |
622 buf << ifargs(i); | |
623 } | |
624 | |
5765 | 625 buf << ") = " << iftext; |
4933 | 626 |
5765 | 627 octave_print_internal (os, buf.str (), pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
628 current_print_indent_level ()); |
4933 | 629 } |
630 | |
631 octave_value | |
5279 | 632 octave_fcn_inline::convert_to_str_internal (bool, bool, char type) const |
4933 | 633 { |
5279 | 634 return octave_value (fcn_text (), type); |
4933 | 635 } |
636 | |
6973 | 637 DEFUNX ("inline", Finline, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
638 "-*- texinfo -*-\n\ |
10840 | 639 @deftypefn {Built-in Function} {} inline (@var{str})\n\ |
6547 | 640 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{arg1}, @dots{})\n\ |
4933 | 641 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{n})\n\ |
642 Create an inline function from the character string @var{str}.\n\ | |
5034 | 643 If called with a single argument, the arguments of the generated\n\ |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
644 function are extracted from the function itself. The generated\n\ |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
645 function arguments will then be in alphabetical order. It should\n\ |
5034 | 646 be noted that i, and j are ignored as arguments due to the\n\ |
647 ambiguity between their use as a variable or their use as an inbuilt\n\ | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
648 constant. All arguments followed by a parenthesis are considered\n\ |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
15978
diff
changeset
|
649 to be functions. If no arguments are found, a function taking a single\n\ |
15977
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
650 argument named @code{x} will be created.\n\ |
4933 | 651 \n\ |
652 If the second and subsequent arguments are character strings,\n\ | |
653 they are the names of the arguments of the function.\n\ | |
654 \n\ | |
655 If the second argument is an integer @var{n}, the arguments are\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
656 @qcode{\"x\"}, @qcode{\"P1\"}, @dots{}, @qcode{\"P@var{N}\"}.\n\ |
5642 | 657 @seealso{argnames, formula, vectorize}\n\ |
658 @end deftypefn") | |
4933 | 659 { |
660 octave_value retval; | |
661 | |
662 int nargin = args.length (); | |
663 | |
664 if (nargin > 0) | |
665 { | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
666 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
667 { |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
668 std::string fun = args(0).string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
669 string_vector fargs; |
4933 | 670 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 if (nargin == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
672 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 bool is_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
674 bool in_string = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
675 std::string tmp_arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
676 size_t i = 0; |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
677 size_t fun_length = fun.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
678 |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
679 while (i < fun_length) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
681 bool terminate_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
682 char c = fun[i++]; |
4933 | 683 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
684 if (in_string) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
685 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
686 if (c == '\'' || c == '\"') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
687 in_string = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
688 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
689 else if (c == '\'' || c == '\"') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
690 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
691 in_string = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 if (is_arg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
693 terminate_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
694 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
695 else if (! isalpha (c) && c != '_') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
696 if (! is_arg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
698 else if (isdigit (c)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
699 tmp_arg.append (1, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
700 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
701 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 // Before we do anything remove trailing whitespaces. |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
703 while (i < fun_length && isspace (c)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
704 c = fun[i++]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
705 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
706 // Do we have a variable or a function? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 if (c != '(') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
708 terminate_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
710 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
711 tmp_arg = std::string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
712 is_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
713 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
714 } |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
715 else if (! is_arg) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
716 { |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
717 if (c == 'e' || c == 'E') |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
718 { |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
719 // possible number in exponent form, not arg |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
720 if (isdigit (fun[i]) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
721 || fun[i] == '-' || fun[i] == '+') |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
722 continue; |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
723 } |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
724 is_arg = true; |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
725 tmp_arg.append (1, c); |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
726 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
729 tmp_arg.append (1, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 } |
5034 | 731 |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
732 if (terminate_arg || (i == fun_length && is_arg)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
733 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
734 bool have_arg = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
735 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
736 for (int j = 0; j < fargs.length (); j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 if (tmp_arg == fargs (j)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
738 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
739 have_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
741 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
742 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
743 if (! have_arg && tmp_arg != "i" && tmp_arg != "j" && |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
744 tmp_arg != "NaN" && tmp_arg != "nan" && |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
745 tmp_arg != "Inf" && tmp_arg != "inf" && |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
746 tmp_arg != "NA" && tmp_arg != "pi" && |
14145
5a25a51146a1
ov-fcn-inline.cc (Vinline): Add "e" to the built-in variables (bug #35236)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
747 tmp_arg != "e" && tmp_arg != "eps") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
748 fargs.append (tmp_arg); |
5037 | 749 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
750 tmp_arg = std::string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
751 is_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
752 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 } |
5034 | 754 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
755 // Sort the arguments into ascii order. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
756 fargs.sort (); |
15977
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
757 |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
758 if (fargs.length () == 0) |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
759 fargs.append (std::string ("x")); |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
760 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
761 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 else if (nargin == 2 && args(1).is_numeric_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
763 { |
15978
dc5d42399e89
maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15977
diff
changeset
|
764 if (! args(1).is_scalar_type ()) |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
765 { |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
766 error ("inline: N must be an integer"); |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
767 return retval; |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
768 } |
15978
dc5d42399e89
maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15977
diff
changeset
|
769 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
770 int n = args(1).int_value (); |
4933 | 771 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
772 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
773 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
774 if (n >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
775 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
776 fargs.resize (n+1); |
4933 | 777 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 fargs(0) = "x"; |
4933 | 779 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
780 for (int i = 1; i < n+1; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
781 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
782 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
783 buf << "P" << i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
784 fargs(i) = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
785 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
786 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
787 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
788 { |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
789 error ("inline: N must be a positive integer or zero"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
792 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
793 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
794 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
795 error ("inline: N must be an integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
796 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
797 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
799 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
800 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
801 fargs.resize (nargin - 1); |
4933 | 802 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
803 for (int i = 1; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
804 { |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
805 if (args(i).is_string ()) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
806 { |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
807 std::string s = args(i).string_value (); |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
808 fargs(i-1) = s; |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
809 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
810 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
811 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
812 error ("inline: expecting string arguments"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
813 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
814 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
815 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
816 } |
4933 | 817 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
818 retval = octave_value (new octave_fcn_inline (fun, fargs)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
819 } |
4933 | 820 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
821 error ("inline: STR argument must be a string"); |
4933 | 822 } |
823 else | |
5823 | 824 print_usage (); |
4933 | 825 |
826 return retval; | |
827 } | |
828 | |
7394 | 829 /* |
830 %!shared fn | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
831 %! fn = inline ("x.^2 + 1"); |
7394 | 832 %!assert (feval (fn, 6), 37) |
833 %!assert (fn (6), 37) | |
15977
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
834 %!assert (feval (inline ("sum (x(:))"), [1 2; 3 4]), 10) |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
835 %!assert (feval (inline ("sqrt (x^2 + y^2)", "x", "y"), 3, 4), 5) |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
836 %!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp(3*4) + 5) |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
837 |
15978
dc5d42399e89
maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15977
diff
changeset
|
838 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
839 %!error inline () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
840 %!error <STR argument must be a string> inline (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
841 %!error <N must be an integer> inline ("2", ones (2,2)) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
842 %!error <N must be a positive integer> inline ("2", -1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
843 %!error <expecting string arguments> inline ("2", "x", -1, "y") |
7394 | 844 */ |
845 | |
4933 | 846 DEFUN (formula, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
847 "-*- texinfo -*-\n\ |
4933 | 848 @deftypefn {Built-in Function} {} formula (@var{fun})\n\ |
849 Return a character string representing the inline function @var{fun}.\n\ | |
850 Note that @code{char (@var{fun})} is equivalent to\n\ | |
851 @code{formula (@var{fun})}.\n\ | |
5642 | 852 @seealso{argnames, inline, vectorize}\n\ |
853 @end deftypefn") | |
4933 | 854 { |
855 octave_value retval; | |
856 | |
857 int nargin = args.length (); | |
858 | |
859 if (nargin == 1) | |
860 { | |
861 octave_fcn_inline* fn = args(0).fcn_inline_value (true); | |
862 | |
863 if (fn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
864 retval = octave_value (fn->fcn_text ()); |
4933 | 865 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
866 error ("formula: FUN must be an inline function"); |
4933 | 867 } |
868 else | |
5823 | 869 print_usage (); |
4933 | 870 |
871 return retval; | |
872 } | |
873 | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
874 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
875 %!assert (formula (fn), "x.^2 + 1") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
876 %!assert (formula (fn), char (fn)) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
877 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
878 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
879 %!error formula () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
880 %!error formula (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
881 %!error <FUN must be an inline function> formula (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
882 */ |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
883 |
4933 | 884 DEFUN (argnames, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
885 "-*- texinfo -*-\n\ |
4933 | 886 @deftypefn {Built-in Function} {} argnames (@var{fun})\n\ |
887 Return a cell array of character strings containing the names of\n\ | |
888 the arguments of the inline function @var{fun}.\n\ | |
6529 | 889 @seealso{inline, formula, vectorize}\n\ |
5642 | 890 @end deftypefn") |
4933 | 891 { |
892 octave_value retval; | |
893 | |
894 int nargin = args.length (); | |
895 | |
896 if (nargin == 1) | |
897 { | |
898 octave_fcn_inline *fn = args(0).fcn_inline_value (true); | |
899 | |
900 if (fn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
902 string_vector t1 = fn->fcn_arg_names (); |
4933 | 903 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
904 Cell t2 (dim_vector (t1.length (), 1)); |
4933 | 905 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
906 for (int i = 0; i < t1.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
907 t2(i) = t1(i); |
4933 | 908 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
909 retval = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 } |
4933 | 911 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
912 error ("argnames: FUN must be an inline function"); |
4933 | 913 } |
914 else | |
5823 | 915 print_usage (); |
4933 | 916 |
917 return retval; | |
918 } | |
919 | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
920 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
921 %!assert (argnames (fn), {"x"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
922 %!assert (argnames (inline ("1e-3*y + 2e4*z")), {"y"; "z"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
923 %!assert (argnames (inline ("2", 2)), {"x"; "P1"; "P2"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
924 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
925 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
926 %!error argnames () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
927 %!error argnames (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
928 %!error <FUN must be an inline function> argnames (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
929 */ |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
930 |
4933 | 931 DEFUN (vectorize, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
932 "-*- texinfo -*-\n\ |
6635 | 933 @deftypefn {Built-in Function} {} vectorize (@var{fun})\n\ |
4933 | 934 Create a vectorized version of the inline function @var{fun}\n\ |
935 by replacing all occurrences of @code{*}, @code{/}, etc., with\n\ | |
936 @code{.*}, @code{./}, etc.\n\ | |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
937 \n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
938 This may be useful, for example, when using inline functions with\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
939 numerical integration or optimization where a vector-valued function\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
940 is expected.\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
941 \n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
942 @example\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
943 @group\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
944 fcn = vectorize (inline (\"x^2 - 1\"))\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
945 @result{} fcn = f(x) = x.^2 - 1\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
946 quadv (fcn, 0, 3)\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
947 @result{} 6\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
948 @end group\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
949 @end example\n\ |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
950 @seealso{inline, formula, argnames}\n\ |
5642 | 951 @end deftypefn") |
4933 | 952 { |
953 octave_value retval; | |
954 | |
955 int nargin = args.length (); | |
956 | |
957 if (nargin == 1) | |
958 { | |
5409 | 959 std::string old_func; |
960 octave_fcn_inline* old = 0; | |
961 bool func_is_string = true; | |
4933 | 962 |
5409 | 963 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
964 old_func = args(0).string_value (); |
5409 | 965 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
966 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
967 old = args(0).fcn_inline_value (true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
968 func_is_string = false; |
5409 | 969 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
970 if (old) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
971 old_func = old->fcn_text (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
972 else |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
973 error ("vectorize: FUN must be a string or inline function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
974 } |
5409 | 975 |
976 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
977 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
978 std::string new_func; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
979 size_t i = 0; |
4933 | 980 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
981 while (i < old_func.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
982 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
983 std::string t1 = old_func.substr (i, 1); |
4933 | 984 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
985 if (t1 == "*" || t1 == "/" || t1 == "\\" || t1 == "^") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
986 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
987 if (i && old_func.substr (i-1, 1) != ".") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
988 new_func.append ("."); |
4933 | 989 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
990 // Special case for ** operator. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
991 if (t1 == "*" && i < (old_func.length () - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
992 && old_func.substr (i+1, 1) == "*") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
993 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
994 new_func.append ("*"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
995 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
996 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
998 new_func.append (t1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
999 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1000 } |
4933 | 1001 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1002 if (func_is_string) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1003 retval = octave_value (new_func); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1004 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1005 retval = octave_value (new octave_fcn_inline |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1006 (new_func, old->fcn_arg_names ())); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1007 } |
4933 | 1008 } |
1009 else | |
5823 | 1010 print_usage (); |
4933 | 1011 |
1012 return retval; | |
1013 } | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1014 |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1015 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1016 %!assert (char (vectorize (fn)), "x.^2 + 1") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1017 %!assert (char (vectorize (inline ("1e-3*y + 2e4*z"))), "1e-3.*y + 2e4.*z") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1018 %!assert (char (vectorize (inline ("2**x^5"))), "2.**x.^5") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1019 %!assert (vectorize ("x.^2 + 1"), "x.^2 + 1") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1020 %!assert (vectorize ("1e-3*y + 2e4*z"), "1e-3.*y + 2e4.*z") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1021 %!assert (vectorize ("2**x^5"), "2.**x.^5") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1022 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
1023 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1024 %!error vectorize () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1025 %!error vectorize (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1026 %!error <FUN must be a string or inline function> vectorize (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1027 */ |