Mercurial > hg > octave-nkf
annotate libinterp/octave-value/ov-builtin.cc @ 20811:a22d8a2eb0e5
fix adaptive strategy in ode solvers.
* script/ode/ode45.m: remove unused option OutputSave
* script/ode/private/integrate_adaptive.m: rewrite algorithm
to be more compatible.
* script/ode/private/runge_kutta_45_dorpri.m: use kahan summation
for time increment.
author | Carlo de Falco <carlo.defalco@polimi.it> |
---|---|
date | Sun, 11 Oct 2015 18:44:58 +0200 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
2974 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19795
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2974 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2974 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2974 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "error.h" | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7487
diff
changeset
|
28 #include "gripes.h" |
2974 | 29 #include "oct-obj.h" |
30 #include "ov-builtin.h" | |
31 #include "ov.h" | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11523
diff
changeset
|
32 #include "profiler.h" |
4748 | 33 #include "toplev.h" |
34 #include "unwind-prot.h" | |
2974 | 35 |
36 | |
4612 | 37 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_builtin, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
38 "built-in function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
39 "built-in function"); |
2974 | 40 |
41 octave_value_list | |
4247 | 42 octave_builtin::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
43 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
44 int nargout) |
3933 | 45 { |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
46 return octave_builtin::subsref (type, idx, nargout, 0); |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
47 } |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
48 |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
49 octave_value_list |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
50 octave_builtin::subsref (const std::string& type, |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
51 const std::list<octave_value_list>& idx, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 int nargout, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 const std::list<octave_lvalue>* lvalue_list) |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
54 { |
3933 | 55 octave_value_list retval; |
56 | |
57 switch (type[0]) | |
58 { | |
59 case '(': | |
5154 | 60 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
61 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5154 | 62 |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
63 retval = do_multi_index_op (tmp_nargout, idx.front (), |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
64 idx.size () == 1 ? lvalue_list : 0); |
5154 | 65 } |
3933 | 66 break; |
67 | |
68 case '{': | |
69 case '.': | |
70 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
71 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10184
diff
changeset
|
72 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 73 } |
74 break; | |
75 | |
76 default: | |
77 panic_impossible (); | |
78 } | |
79 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 // FIXME: perhaps there should be an |
4059 | 81 // octave_value_list::next_subsref member function? See also |
82 // octave_user_function::subsref. | |
83 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 // FIXME: Note that if a function call returns multiple |
4059 | 85 // values, and there is further indexing to perform, then we are |
86 // ignoring all but the first value. Is this really what we want to | |
87 // do? If it is not, then what should happen for stat("file").size, | |
88 // for exmaple? | |
3933 | 89 |
4219 | 90 if (idx.size () > 1) |
4994 | 91 retval = retval(0).next_subsref (nargout, type, idx); |
4059 | 92 |
93 return retval; | |
3933 | 94 } |
95 | |
96 octave_value_list | |
3544 | 97 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args) |
2974 | 98 { |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
99 return octave_builtin::do_multi_index_op (nargout, args, 0); |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
100 } |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
101 |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
102 octave_value_list |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
103 octave_builtin::do_multi_index_op (int nargout, const octave_value_list& args, |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
104 const std::list<octave_lvalue> *lvalue_list) |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
105 { |
2974 | 106 octave_value_list retval; |
107 | |
5864 | 108 if (args.has_magic_colon ()) |
20638
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
109 error ("invalid use of colon in function argument list"); |
2974 | 110 else |
4748 | 111 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
112 unwind_protect frame; |
4987 | 113 |
5743 | 114 octave_call_stack::push (this); |
4975 | 115 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
116 frame.add_fcn (octave_call_stack::pop); |
4748 | 117 |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
118 if (lvalue_list || curr_lvalue_list) |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
119 { |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
120 frame.protect_var (curr_lvalue_list); |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
121 curr_lvalue_list = lvalue_list; |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
122 } |
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
123 |
20744
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
124 BEGIN_PROFILER_BLOCK (octave_builtin) |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11523
diff
changeset
|
125 |
20744
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
126 retval = (*f) (args, nargout); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
127 // Do not allow null values to be returned from functions. |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
128 // FIXME: perhaps true builtins should be allowed? |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
129 retval.make_storable_values (); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
130 // Fix the case of a single undefined value. |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
131 // This happens when a compiled function uses |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
132 // octave_value retval; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
133 // instead of |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
134 // octave_value_list retval; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
135 // the idiom is very common, so we solve that here. |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
136 if (retval.length () == 1 && retval.xelem (0).is_undefined ()) |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
137 retval.clear (); |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
138 |
20744
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20638
diff
changeset
|
139 END_PROFILER_BLOCK |
4748 | 140 } |
2974 | 141 |
142 return retval; | |
143 } | |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
144 |
14973 | 145 jit_type * |
146 octave_builtin::to_jit (void) const | |
147 { | |
148 return jtype; | |
149 } | |
150 | |
151 void | |
152 octave_builtin::stash_jit (jit_type &type) | |
153 { | |
154 jtype = &type; | |
155 } | |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
156 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
157 octave_builtin::fcn |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
158 octave_builtin::function (void) const |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
159 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
160 return f; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
161 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
162 |
10887
f10d0bc8f9cc
make isargout available to DEFUNs
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
163 const std::list<octave_lvalue> *octave_builtin::curr_lvalue_list = 0; |