annotate @pyobject/subsref.m @ 411:3613ffbd52b2

Overhaul implicit conversion of arguments and return values * oct-py-types.cc, oct-py-types.h (pytave::py_implicitly_convert_argument, pytave::py_implicitly_convert_return_value): New functions. * __py_struct_from_dict__.cc, oct-py-eval.cc, pycall.cc, pyeval.cc, pyexec.cc: Use them instead of legacy conversion functions. Add necessary #includes, remove #includes of legacy header files. * @pyobject/subsasgn.m, @pyobject/subsref.m: Change %!tests that depend on NumPy implicit conversion into %!xtests. * octave_to_python.cc, octave_to_python.h, python_to_octave.cc, python_to_octave.h: Delete, no longer used. * Makefile.am (COMMON_SOURCE_FILES, PYTAVE_HEADER_FILES): Remove the files.
author Mike Miller <mtmiller@octave.org>
date Wed, 03 May 2017 16:30:45 -0700
parents a8102b1a57a1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
1 ## Copyright (C) 2016 Colin B. Macdonald
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
2 ##
246
4acc64f89d67 maint: fix copyright header comment blocks
Mike Miller <mtmiller@octave.org>
parents: 245
diff changeset
3 ## This file is part of Pytave
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
4 ##
246
4acc64f89d67 maint: fix copyright header comment blocks
Mike Miller <mtmiller@octave.org>
parents: 245
diff changeset
5 ## Pytave is free software; you can redistribute it and/or modify
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
7 ## by the Free Software Foundation; either version 3 of the License,
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
8 ## or (at your option) any later version.
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
9 ##
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
10 ## This software is distributed in the hope that it will be useful,
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
12 ## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
13 ## the GNU General Public License for more details.
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
14 ##
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
16 ## License along with this software; see the file COPYING.
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
17 ## If not, see <http://www.gnu.org/licenses/>.
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
18
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
19 ## -*- texinfo -*-
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
20 ## @documentencoding UTF-8
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
21 ## @defop Method @@pyobject subsref (@var{x}, @var{idx})
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
22 ## @defopx Operator @@pyobject {@var{x}.@var{property}} {}
238
c64435b14a6e Minor doc fix
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
23 ## @defopx Operator @@pyobject {@var{x}.@var{method}(@var{a}, @dots{})} {}
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
24 ## @defopx Operator @@pyobject {@var{x}@{@var{i}@}} {}
238
c64435b14a6e Minor doc fix
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
25 ## @defopx Operator @@pyobject {@var{x}@{@var{i}, @var{j}, @dots{}@}} {}
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
26 ## @defopx Operator @@pyobject {@var{x}(@var{a})} {}
238
c64435b14a6e Minor doc fix
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
27 ## @defopx Operator @@pyobject {@var{x}(@var{a}, @var{b}, @dots{})} {}
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
28 ## Call methods and access properties of a Python object.
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
29 ##
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
30 ##
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
31 ## @seealso{@@pyobject/subsasgn}
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
32 ## @end defop
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
33
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
34
244
46382ade33e4 maint: minor cosmetic fixes to cset 708715efa18e
Mike Miller <mtmiller@octave.org>
parents: 243
diff changeset
35 function varargout = subsref (x, idx)
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
36
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
37 t = idx(1);
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
38 switch (t.type)
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
39 case "."
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
40 assert (ischar (t.subs))
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
41 r = pycall ("getattr", x, t.subs);
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
42
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
43 case "()"
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
44 ## Determine the types and protocols that we are able to index into
370
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
45 x_is_callable = __py_isinstance__ (x, "py.collections.Callable");
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
46 x_is_sequence = __py_isinstance__ (x, "py.collections.Sequence") ...
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
47 | __py_isinstance__ (x, "py.array.array") ...
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
48 | __py_isinstance__ (x, "py.numpy.ndarray");
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
49
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
50 if (! (x_is_callable || x_is_sequence))
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
51 error ("subsref: cannot index Python object, not sequence or callable");
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
52 endif
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
53
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
54 if (x_is_sequence)
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
55 error ("subsref: slice indexing of Python objects not yet implemented");
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
56 endif
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
57
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
58 r = pycall (x, t.subs{:});
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
59
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
60 case "{}"
322
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
61 ## Determine the types and protocols that we are able to index into
370
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
62 x_is_mapping = __py_isinstance__ (x, "py.collections.Mapping");
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
63 x_is_sequence = __py_isinstance__ (x, "py.collections.Sequence") ...
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
64 | __py_isinstance__ (x, "py.array.array") ...
a8102b1a57a1 pyobject.subsref: restore performance by calling __py_isinstance__ directly
Mike Miller <mtmiller@octave.org>
parents: 369
diff changeset
65 | __py_isinstance__ (x, "py.numpy.ndarray");
322
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
66
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
67 if (! (x_is_mapping || x_is_sequence))
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
68 error ("subsref: cannot index Python object, not sequence or mapping");
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
69 endif
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
70
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
71 ## Subtract one from index: do this for lists, arrays, numpy arrays, etc
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
72 for i = 1:length (t.subs)
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
73 j = t.subs{i};
322
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
74 if (isindex (j) && isnumeric (j) && x_is_sequence)
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
75 t.subs{i} = cast (j, class (sizemax ())) - 1;
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
76 endif
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
77 endfor
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
78
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
79 if (ischar (t.subs{1}) && strcmp (t.subs{1}, ":"))
322
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
80 if (x_is_mapping)
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
81 ind = ":";
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
82 else
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
83 ind = int32 ([1:length(x)] - 1);
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
84 endif
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
85 elseif (isscalar (t.subs))
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
86 ind = t.subs{1};
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
87 else
317
461f333daf67 Fix multi-indexing conversion to tuple
Colin Macdonald <cbm@m.fsf.org>
parents: 314
diff changeset
88 ind = pycall ("tuple", t.subs);
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
89 endif
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
90
323
a511d43e1fc0 pyobject.subsref: avoid attempting to index on empty index range
Mike Miller <mtmiller@octave.org>
parents: 322
diff changeset
91 if (isempty (ind) && x_is_sequence)
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
92 r = pyobject ();
323
a511d43e1fc0 pyobject.subsref: avoid attempting to index on empty index range
Mike Miller <mtmiller@octave.org>
parents: 322
diff changeset
93 elseif (isnumeric (ind) && length (ind) > 1)
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
94 r = {};
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
95 for k = 1:length (ind)
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
96 r(end+1) = pycall ("operator.getitem", x, ind(k));
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
97 endfor
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
98 else
369
540b36e797c8 Reduce number of function calls, clean up formatting in subasgn and subsref
Mike Miller <mtmiller@octave.org>
parents: 368
diff changeset
99 r = pycall ("operator.getitem", x, ind);
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
100 endif
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
101
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
102 otherwise
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
103 t
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
104 error ("@pyobject/subsref: not implemented")
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
105 endswitch
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
106
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
107 ## deal with additional indexing (might be recursive)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
108 if (length (idx) > 1)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
109 r = subsref (r, idx(2:end));
245
72a2f508f2d8 maint: Use Octave keywords for ending code blocks
Mike Miller <mtmiller@octave.org>
parents: 244
diff changeset
110 endif
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
111
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
112 ## unpack results, ensure "ans" works (see also pycall)
368
4d54fb68de71 __py_is_none__: new compiled function to test whether an object is None
Mike Miller <mtmiller@octave.org>
parents: 367
diff changeset
113 if (nargout == 0 && ! __py_is_none__ (r))
274
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
114 varargout{1} = r;
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
115 elseif (nargout == 1)
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
116 varargout{1} = r;
274
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
117 elseif (nargout >= 2)
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
118 assert (length (r) == nargout, ...
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
119 "pyobject/subsref: number of outputs must match")
288
f5282c87e5d5 Fix cell indexing for pyobject in subsref
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 275
diff changeset
120 [varargout{1:nargout}] = subsref (r, struct ("type", "{}", "subs", {{1:nargout}}));
245
72a2f508f2d8 maint: Use Octave keywords for ending code blocks
Mike Miller <mtmiller@octave.org>
parents: 244
diff changeset
121 endif
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
122 endfunction
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
123
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
124
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
125 %!test
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
126 %! % list indexing
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
127 %! L = pyeval ("[10., 20.]");
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
128 %! assert (L{1}, 10)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
129 %! assert (L{2}, 20)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
130
290
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
131 %!test
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
132 %! % list indexing, slice
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
133 %! L = pyeval ("[10., 20., [30., 40.]]");
297
e7ee2c2e64e8 undo recent unnecessary change to slice test
Colin Macdonald <cbm@m.fsf.org>
parents: 290
diff changeset
134 %! L2 = L{:};
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
135 %! assert (L2{1}, 10)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
136 %! assert (L2{2}, 20)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
137 %! assert (L2{3}{1}, 30)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
138 %! assert (L2{3}{2}, 40)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
139
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
140 %!test
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
141 %! % list indexing, nested list
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
142 %! L = pyeval ("[1., 2., [10., 11., 12.]]");
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
143 %! assert (L{2}, 2)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
144 %! assert (L{3}{1}, 10)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
145 %! assert (L{3}{3}, 12)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
146
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
147 %!test
299
714d1bf1ef78 Add test of multivariable output from subsref
Colin Macdonald <cbm@m.fsf.org>
parents: 297
diff changeset
148 %! % list indexing, assign to vars
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
149 %! L = pyeval ("[1., 2., 'Octave']");
299
714d1bf1ef78 Add test of multivariable output from subsref
Colin Macdonald <cbm@m.fsf.org>
parents: 297
diff changeset
150 %! [a, b, c] = L{:};
714d1bf1ef78 Add test of multivariable output from subsref
Colin Macdonald <cbm@m.fsf.org>
parents: 297
diff changeset
151 %! assert (a, 1)
714d1bf1ef78 Add test of multivariable output from subsref
Colin Macdonald <cbm@m.fsf.org>
parents: 297
diff changeset
152 %! assert (b, 2)
365
087e7bc3697f Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents: 343
diff changeset
153 %! assert (char (c), "Octave")
299
714d1bf1ef78 Add test of multivariable output from subsref
Colin Macdonald <cbm@m.fsf.org>
parents: 297
diff changeset
154
411
3613ffbd52b2 Overhaul implicit conversion of arguments and return values
Mike Miller <mtmiller@octave.org>
parents: 370
diff changeset
155 ## Test that depends on implicit creation of NumPy arrays, do we want this?
3613ffbd52b2 Overhaul implicit conversion of arguments and return values
Mike Miller <mtmiller@octave.org>
parents: 370
diff changeset
156 %!xtest
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
157 %! % 2D array indexing
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
158 %! A = pyobject ([1. 2.; 3. 4.]);
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
159 %! assert (A{1, 1}, 1)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
160 %! assert (A{2, 1}, 3)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
161 %! assert (A{1, 2}, 2)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
162
322
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
163 ## Test element indexing on array.array types
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
164 %!test
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
165 %! a = pycall ("array.array", "d", {11, 12, 13, 14});
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
166 %! assert (a{1}, 11)
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
167 %! assert (a{2}, 12)
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
168 %! assert (a{end}, 14)
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
169
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
170 %!test
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
171 %! % dict: str key access
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
172 %! d = pyeval ("{'one':1., 5:5, 6:6}");
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
173 %! assert (d{"one"}, 1)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
174
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
175 %!test
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
176 %! % dict: integer key access
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
177 %! d = pyeval ("{5:42., 6:42.}");
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
178 %! assert (d{6}, 42)
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
179
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
180 %!test
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
181 %! % dict: integer key should not subtract one
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
182 %! d = pyeval ("{5:40., 6:42.}");
221
a76d75683455 pyobject: split subsref to its own file, reformat
Colin Macdonald <cbm@m.fsf.org>
parents:
diff changeset
183 %! assert (d{6}, 42)
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
184
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
185 %!test
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
186 %! % dict: floating point keys should work
312
d9f9156a13c9 Remove unncessary calls to fromPythonVarName
Colin Macdonald <cbm@m.fsf.org>
parents: 299
diff changeset
187 %! d = pyeval ("{5.5:'ok'}");
365
087e7bc3697f Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents: 343
diff changeset
188 %! assert (char (d{5.5}), "ok")
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
189
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
190 %!test
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
191 %! % dict: make sure key ":" doesn't break anything
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
192 %! d = pyeval ("{'a':1., ':':2.}");
260
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
193 %! assert (d{'a'}, 1)
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
194 %! assert (d{':'}, 2)
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
195
daf1aff501f1 indexing: fix off-by-one with dicts (fixes issue #10)
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
196 %!test
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
197 %! % method call with args
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
198 %! s = pyeval ("set({1, 2})");
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
199 %! s.add (42)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
200 %! assert (length (s) == 3)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
201
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
202 %!test
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
203 %! % get a callable
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
204 %! s = pyeval ("set({1, 2})");
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
205 %! sa = s.add;
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
206 %! assert (isa (sa, "pyobject"))
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
207 %! % and then call it
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
208 %! sa (42)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
209 %! assert (length (s) == 3)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
210
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
211 %!test
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
212 %! % callable can return something
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
213 %! s = pyeval ("set({1., 2.})");
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
214 %! v = s.pop ();
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
215 %! assert (length (s) == 1)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
216 %! assert (v == 1 || v == 2)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
217
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
218 %!test
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
219 %! % chain
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
220 %! pyexec ("import sys")
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
221 %! s = pyeval ("set({sys})");
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
222 %! ver = s.pop ().version;
365
087e7bc3697f Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents: 343
diff changeset
223 %! assert (isa (ver, "pyobject"))
087e7bc3697f Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents: 343
diff changeset
224 %! assert (ischar (char (ver)))
240
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
225
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
226 %!test
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
227 %! % don't set "ans" if no return value
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
228 %! s = pyeval ("set({1, 2})");
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
229 %! sa = s.add;
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
230 %! clear ans
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
231 %! sa (42)
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
232 %! assert (! exist ("ans", "var"))
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
233
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
234 %!test
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
235 %! % *do* set "ans" if return value
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
236 %! s = pyeval ("set({1, 2})");
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
237 %! clear ans
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
238 %! s.pop ();
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
239 %! assert (exist ("ans", "var"))
708715efa18e pyobject: support callables with arguments (fixes issue #18)
Colin Macdonald <cbm@m.fsf.org>
parents: 227
diff changeset
240 %! assert (length (s) == 1)
274
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
241
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
242 %!test
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
243 %! % multiple return values: can get all of them
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
244 %! f = pyeval ("lambda: (1, 2, 3)");
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
245 %! a = f ();
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
246 %! assert (length (a) == 3)
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
247
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
248 %!test
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
249 %! % multiple return values: separate them
327
15c20ab4b80a Do not automatically convert Python integer types to Octave (see issue #56)
Mike Miller <mtmiller@octave.org>
parents: 323
diff changeset
250 %! f = pyeval ("lambda: (1., 2., 3.)");
274
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
251 %! [a, b, c] = f ();
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
252 %! assert (a, 1)
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
253 %! assert (b, 2)
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
254 %! assert (c, 3)
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
255
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
256 %!test
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
257 %! % multiple return values: set ans
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
258 %! f = pyeval ("lambda: (1, 2, 3)");
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
259 %! f ();
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
260 %! assert (length (ans) == 3)
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
261
290
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
262 %!test
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
263 %! % ensure None is returned if nargout > 0
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
264 %! L = pyeval ("[1, None, 3]");
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
265 %! a = L{2};
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
266 %! assert (char (a), "None")
f2b4576879a6 Edit tests in subsref to use and verify cell indexing
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 288
diff changeset
267
343
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
268 ## Test of multi-element indexing, fails to return correct number of output args
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
269 %!xtest
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
270 %! a = {1, 2, 3, 4, 5, 6};
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
271 %! b = pyobject (a);
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
272 %! b{:};
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
273 %! assert (ans, a{end})
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
274
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
275 %!xtest
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
276 %! a = {1, 2, 3, 4, 5, 6};
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
277 %! b = pyobject (a);
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
278 %! c = {b{:}};
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
279 %! assert (c, a)
fe6b9e618c98 Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents: 327
diff changeset
280
322
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
281 %!error <cannot index Python object>
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
282 %! f = pyeval ("abs");
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
283 %! f{1}
2461b86cb8fb pyobject.subsref: support indexing into Python array objects
Mike Miller <mtmiller@octave.org>
parents: 319
diff changeset
284
274
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
285 %!error <outputs must match>
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
286 %! % multiple return values: too many outputs
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
287 %! f = pyeval ("lambda: (1, 2)");
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
288 %! [a, b, c] = f ();
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
289
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
290 %!error <outputs must match>
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
291 %! % multiple return values: not enough outputs
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
292 %! f = pyeval ("lambda: (1, 2, 3)");
decd3bd7da7e Partial support for multiple outputs from callables
Colin Macdonald <cbm@m.fsf.org>
parents: 248
diff changeset
293 %! [a, b] = f ();