annotate python_to_octave.cc @ 325:fd5881d48238

Overhaul Python string creation and extraction * oct-py-types.cc, oct-py-types.h (pytave::extract_py_str, pytave::make_py_str): New functions to create a Python string and extract string value from Python. (pytave::make_py_dict): Use make_py_str. * octave_to_python.cc (pytave::octvalue_to_pyobj): Use make_py_str. (pytave::octstring_to_pyobject): Delete. * python_to_octave.cc (pytave::pyobj_to_octvalue): Use extract_py_str. (pytave::pyunicode_to_utf8): Delete.
author Mike Miller <mtmiller@octave.org>
date Sat, 13 Aug 2016 19:29:47 -0700
parents 2ecae5c6eeb6
children 37df9bd607ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
1 /*
139
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
2
150
a3dc9d24ae38 maint: Add myself to copyright notices
Mike Miller <mtmiller@octave.org>
parents: 146
diff changeset
3 Copyright (C) 2015-2016 Mike Miller
139
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
4 Copyright (C) 2008 David Grundberg, HÃ¥kan Fors Nilsson
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
5 Copyright (C) 2009 VZLU Prague
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
6
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
7 This file is part of Pytave.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
8
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
9 Pytave is free software: you can redistribute it and/or modify it
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
10 under the terms of the GNU General Public License as published by the
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
11 Free Software Foundation, either version 3 of the License, or (at your
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
12 option) any later version.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
13
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
14 Pytave is distributed in the hope that it will be useful, but WITHOUT
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
17 for more details.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
18
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
19 You should have received a copy of the GNU General Public License
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
20 along with Pytave; see the file COPYING. If not, see
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
21 <http://www.gnu.org/licenses/>.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
22
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
23 */
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
24
132
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 108
diff changeset
25 #if defined (HAVE_CONFIG_H)
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 108
diff changeset
26 # include <config.h>
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 108
diff changeset
27 #endif
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 108
diff changeset
28
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
29 #include <iostream>
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
30 #include <boost/python.hpp>
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
31 #include <boost/python/numeric.hpp>
46
095e26d93935 support complex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 43
diff changeset
32 #include <boost/type_traits/integral_constant.hpp>
100
ff70627aa203 Undef HAVE_STAT and HAVE_FSTAT consistently through-out all files
David Grundberg <individ@acc.umu.se>
parents: 81
diff changeset
33
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
34 #include <octave/oct.h>
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
35 #include <octave/oct-map.h>
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
36 #include <octave/Cell.h>
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
37 #include <octave/ov.h>
106
896fdc369789 Use latest Octave library API
Mike Miller <mtmiller@octave.org>
parents: 102
diff changeset
38 #include <octave/Array.h>
278
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
39 #include <octave/parse.h>
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
40
75
b0991511a16d a few fixes to numpy support
Jaroslav Hajek <highegg@gmail.com>
parents: 70
diff changeset
41 #include "arrayobjectdefs.h"
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
42 #include "exceptions.h"
325
fd5881d48238 Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents: 306
diff changeset
43 #include "oct-py-types.h"
142
dc2876fdbfaf * python_to_octave.cc: Include missing header file python_to_octave.h.
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
44 #include "python_to_octave.h"
306
2ecae5c6eeb6 Refactor code, have common functions in pytave_utils
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 282
diff changeset
45 #include "pytave_utils.h"
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
46
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
47 using namespace boost::python;
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
48
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
49 namespace pytave
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
50 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
51 template <class PythonPrimitive, class OctaveBase>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
52 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
53 copy_pyarrobj_to_octarray (OctaveBase& matrix, PyArrayObject *pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
54 const int unsigned matindex,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
55 const unsigned int matstride,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
56 const int dimension, const unsigned int offset)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
57 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
58 unsigned char *ptr = (unsigned char*) PyArray_DATA (pyarr);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
59 if (dimension == PyArray_NDIM (pyarr) - 1)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
60 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
61 // Last dimension, base case
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
62 for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
63 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
64 matrix.elem (matindex + i*matstride)
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
65 = *(PythonPrimitive*)
108
74f17b2a5d45 Use the latest NumPy API
Mike Miller <mtmiller@octave.org>
parents: 107
diff changeset
66 &ptr[offset + i*PyArray_STRIDE (pyarr, dimension)];
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
67 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
68 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
69 else if (PyArray_NDIM (pyarr) == 0)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
70 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
71 matrix.elem (0) = *(PythonPrimitive*) ptr;
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
72 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
73 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
74 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
75 for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
76 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
77 copy_pyarrobj_to_octarray<PythonPrimitive, OctaveBase> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
78 matrix,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
79 pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
80 matindex + i*matstride,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
81 matstride * PyArray_DIM (pyarr, dimension),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
82 dimension + 1,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
83 offset + i*PyArray_STRIDE (pyarr, dimension));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
84 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
85 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
86 }
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
87
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
88 template <>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
89 void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
90 copy_pyarrobj_to_octarray<PyObject *, Cell> (Cell& matrix,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
91 PyArrayObject *pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
92 const int unsigned matindex,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
93 const unsigned int matstride,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
94 const int dimension,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
95 const unsigned int offset)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
96 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
97 unsigned char *ptr = (unsigned char*) PyArray_DATA (pyarr);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
98 if (dimension == PyArray_NDIM (pyarr) - 1)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
99 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
100 // Last dimension, base case
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
101 for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
102 {
51
b001edc0f81a implement Python->Octave conversions of Character and PyObject arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 50
diff changeset
103 PyObject *pobj = *(PyObject **)
108
74f17b2a5d45 Use the latest NumPy API
Mike Miller <mtmiller@octave.org>
parents: 107
diff changeset
104 &ptr[offset + i*PyArray_STRIDE (pyarr, dimension)];
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
105 pyobj_to_octvalue (matrix.elem (matindex + i*matstride),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
106 object (handle<PyObject> (borrowed (pobj))));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
107 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
108 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
109 else if (PyArray_NDIM (pyarr) == 0)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
110 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
111 PyObject *pobj = *(PyObject **) ptr;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
112 pyobj_to_octvalue (matrix.elem (0),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
113 object (handle<PyObject> (borrowed (pobj))));
51
b001edc0f81a implement Python->Octave conversions of Character and PyObject arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 50
diff changeset
114 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
115 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
116 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
117 for (int i = 0; i < PyArray_DIM (pyarr, dimension); i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
118 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
119 copy_pyarrobj_to_octarray<PyObject *, Cell> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
120 matrix,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
121 pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
122 matindex + i*matstride,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
123 matstride * PyArray_DIM (pyarr, dimension),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
124 dimension + 1,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
125 offset + i*PyArray_STRIDE (pyarr, dimension));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
126 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
127 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
128 }
51
b001edc0f81a implement Python->Octave conversions of Character and PyObject arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 50
diff changeset
129
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
130 template <class PythonPrimitive, class OctaveBase>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
131 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
132 copy_pyarrobj_to_octarray_dispatch (OctaveBase& matrix,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
133 PyArrayObject *pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
134 const boost::true_type&)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
135 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
136 copy_pyarrobj_to_octarray<PythonPrimitive, OctaveBase> (matrix, pyarr, 0, 1, 0, 0);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
137 }
46
095e26d93935 support complex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 43
diff changeset
138
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
139 template <class PythonPrimitive, class OctaveBase>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
140 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
141 copy_pyarrobj_to_octarray_dispatch (OctaveBase& matrix,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
142 PyArrayObject *pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
143 const boost::false_type&)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
144 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
145 assert (0);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
146 }
46
095e26d93935 support complex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 43
diff changeset
147
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
148 template <class X, class Y> class matching_type : public boost::false_type { };
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
149 template <class X> class matching_type<X, X> : public boost::true_type { };
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
150 template <class X> class matching_type<X, octave_int<X> > : public boost::true_type { };
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
151 template <> class matching_type<float, double> : public boost::true_type { };
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
152 template <> class matching_type<FloatComplex, Complex> : public boost::true_type { };
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
153 template <> class matching_type<PyObject *, octave_value> : public boost::true_type { };
46
095e26d93935 support complex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 43
diff changeset
154
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
155 template <class PythonPrimitive, class OctaveBase>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
156 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
157 copy_pyarrobj_to_octarray_dispatch (OctaveBase& matrix,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
158 PyArrayObject *pyarr)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
159 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
160 matching_type<PythonPrimitive, typename OctaveBase::element_type> inst;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
161 copy_pyarrobj_to_octarray_dispatch<PythonPrimitive, OctaveBase> (matrix, pyarr, inst);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
162 }
46
095e26d93935 support complex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 43
diff changeset
163
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
164 template <class OctaveBase>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
165 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
166 copy_pyarrobj_to_octarray_boot (OctaveBase& matrix, PyArrayObject *pyarr)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
167 {
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
168
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
169 #define ARRAYCASE(AC_pyarrtype, AC_primitive) case AC_pyarrtype: \
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
170 copy_pyarrobj_to_octarray_dispatch<AC_primitive, OctaveBase> \
46
095e26d93935 support complex numbers
Jaroslav Hajek <highegg@gmail.com>
parents: 43
diff changeset
171 (matrix, pyarr); \
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
172 break; \
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
173
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
174 // Coerce NumPy's long type into one of two possible sized integer types
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
175 int type_num = PyArray_TYPE (pyarr);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
176 switch (type_num)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
177 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
178 case NPY_LONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
179 if (sizeof (npy_long) == sizeof (int64_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
180 type_num = NPY_INT64;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
181 else if (sizeof (npy_long) == sizeof (int32_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
182 type_num = NPY_INT32;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
183 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
184 case NPY_LONGLONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
185 if (sizeof (npy_longlong) == sizeof (int64_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
186 type_num = NPY_INT64;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
187 else if (sizeof (npy_longlong) == sizeof (int32_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
188 type_num = NPY_INT32;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
189 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
190 case NPY_ULONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
191 if (sizeof (npy_ulong) == sizeof (uint64_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
192 type_num = NPY_UINT64;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
193 else if (sizeof (npy_ulong) == sizeof (uint32_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
194 type_num = NPY_UINT32;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
195 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
196 case NPY_ULONGLONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
197 if (sizeof (npy_ulonglong) == sizeof (uint64_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
198 type_num = NPY_UINT64;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
199 else if (sizeof (npy_ulonglong) == sizeof (uint32_t))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
200 type_num = NPY_UINT32;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
201 break;
47
c83754e57d26 Fix compilation on 32-bit x86.
David Grundberg <individ@acc.umu.se>
parents: 46
diff changeset
202 }
c83754e57d26 Fix compilation on 32-bit x86.
David Grundberg <individ@acc.umu.se>
parents: 46
diff changeset
203
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
204 switch (type_num)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
205 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
206 ARRAYCASE (NPY_INT8, int8_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
207 ARRAYCASE (NPY_INT16, int16_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
208 ARRAYCASE (NPY_INT32, int32_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
209 ARRAYCASE (NPY_INT64, int64_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
210 ARRAYCASE (NPY_UINT8, uint8_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
211 ARRAYCASE (NPY_UINT16, uint16_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
212 ARRAYCASE (NPY_UINT32, uint32_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
213 ARRAYCASE (NPY_UINT64, uint64_t)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
214 ARRAYCASE (NPY_FLOAT, float)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
215 ARRAYCASE (NPY_DOUBLE, double)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
216 ARRAYCASE (NPY_CFLOAT, FloatComplex)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
217 ARRAYCASE (NPY_CDOUBLE, Complex)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
218 ARRAYCASE (NPY_BOOL, bool)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
219 ARRAYCASE (NPY_CHAR, char)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
220 ARRAYCASE (NPY_STRING, char)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
221 ARRAYCASE (NPY_OBJECT, PyObject *)
51
b001edc0f81a implement Python->Octave conversions of Character and PyObject arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 50
diff changeset
222
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
223 default:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
224 throw object_convert_exception (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
225 PyEval_GetFuncName ((PyObject*)pyarr)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
226 + (PyEval_GetFuncDesc ((PyObject*)pyarr)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
227 + std::string (": Unsupported Python array type")));
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
228 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
229 }
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
230
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
231 template <class OctaveBase>
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
232 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
233 pyarrobj_to_octvalueNd (octave_value& octvalue, PyArrayObject *pyarr,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
234 const dim_vector& dims)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
235 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
236 OctaveBase array (dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
237 copy_pyarrobj_to_octarray_boot<OctaveBase> (array, pyarr);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
238 octvalue = array;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
239 }
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
240
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
241 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
242 pyarr_to_octvalue (octave_value& octvalue, PyArrayObject *pyarr)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
243 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
244 dim_vector dims;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
245 switch (PyArray_NDIM (pyarr))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
246 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
247 case 0:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
248 dims = dim_vector (1, 1);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
249 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
250 case 1:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
251 // Always make PyArray vectors row vectors.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
252 dims = dim_vector (1, PyArray_DIM (pyarr, 0));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
253 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
254 default:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
255 dims.resize (PyArray_NDIM (pyarr));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
256 for (int d = 0; d < PyArray_NDIM (pyarr); d++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
257 dims(d) = PyArray_DIM (pyarr, d);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
258 break;
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
259 }
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
260
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
261 switch (PyArray_TYPE (pyarr))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
262 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
263 case NPY_BYTE:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
264 case NPY_SHORT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
265 case NPY_INT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
266 case NPY_LONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
267 case NPY_LONGLONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
268 switch (PyArray_ITEMSIZE (pyarr))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
269 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
270 case 1:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
271 pyarrobj_to_octvalueNd<int8NDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
272 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
273 case 2:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
274 pyarrobj_to_octvalueNd<int16NDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
275 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
276 case 4:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
277 pyarrobj_to_octvalueNd<int32NDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
278 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
279 case 8:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
280 pyarrobj_to_octvalueNd<int64NDArray> (octvalue, pyarr, dims);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
281 break;
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
282 default:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
283 throw object_convert_exception ("Unknown integer.");
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
284 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
285 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
286 case NPY_UBYTE:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
287 case NPY_USHORT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
288 case NPY_UINT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
289 case NPY_ULONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
290 case NPY_ULONGLONG:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
291 switch (PyArray_ITEMSIZE (pyarr))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
292 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
293 case 1:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
294 pyarrobj_to_octvalueNd<uint8NDArray> (octvalue, pyarr, dims);
143
fe783134c61c Fix conversion of integer types by using strictly sized integers
Mike Miller <mtmiller@octave.org>
parents: 142
diff changeset
295 break;
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
296 case 2:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
297 pyarrobj_to_octvalueNd<uint16NDArray> (octvalue, pyarr, dims);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
298 break;
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
299 case 4:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
300 pyarrobj_to_octvalueNd<uint32NDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
301 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
302 case 8:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
303 pyarrobj_to_octvalueNd<uint64NDArray> (octvalue, pyarr, dims);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
304 break;
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
305 default:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
306 throw object_convert_exception ("Unknown unsigned integer.");
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
307 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
308 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
309 case NPY_FLOAT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
310 pyarrobj_to_octvalueNd<FloatNDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
311 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
312 case NPY_DOUBLE:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
313 pyarrobj_to_octvalueNd<NDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
314 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
315 case NPY_CFLOAT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
316 pyarrobj_to_octvalueNd<FloatComplexNDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
317 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
318 case NPY_CDOUBLE:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
319 pyarrobj_to_octvalueNd<ComplexNDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
320 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
321 case NPY_BOOL:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
322 pyarrobj_to_octvalueNd<boolNDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
323 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
324 case NPY_CHAR:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
325 case_NPY_CHAR:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
326 pyarrobj_to_octvalueNd<charNDArray> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
327 // FIXME: is the following needed?
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
328 octvalue = octvalue.convert_to_str (true, true, '"');
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
329 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
330 case NPY_STRING:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
331 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
332 if (PyArray_ITEMSIZE (pyarr) == 1)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
333 goto case_NPY_CHAR;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
334 else
81
2e8b52a5e1b1 support NumPy string arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 79
diff changeset
335 {
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
336 // Create a new descriptor of the data.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
337 PyArray_Descr *view_descr = PyArray_DescrFromType (NPY_CHAR);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
338 // Create a new view of the NumPy array.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
339 PyArrayObject *view = (PyArrayObject *)PyArray_View (pyarr, view_descr, 0);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
340 // Store in a handle to ensure proper destruction.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
341 handle<PyObject> view_handle (allow_null ((PyObject *)view));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
342 // Call recursively.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
343 pyarr_to_octvalue (octvalue, view);
81
2e8b52a5e1b1 support NumPy string arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 79
diff changeset
344 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
345 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
346 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
347 case NPY_OBJECT:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
348 pyarrobj_to_octvalueNd<Cell> (octvalue, pyarr, dims);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
349 break;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
350 default:
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
351 throw object_convert_exception (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
352 PyEval_GetFuncDesc ((PyObject*)(pyarr)) + std::string (" ")
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
353 + PyEval_GetFuncName ((PyObject*)(pyarr))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
354 + ": Encountered unsupported Python array");
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
355 break;
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
356 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
357 }
25
113428ba033c Whitespace fixes
David Grundberg <individ@acc.umu.se>
parents: 9
diff changeset
358
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
359 static void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
360 pylist_to_cellarray (octave_value& oct_value, const boost::python::list& list)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
361 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
362 octave_idx_type length = boost::python::extract<octave_idx_type> (list.attr ("__len__") ());
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
363 octave_value_list values;
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
364
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
365 for (octave_idx_type i = 0; i < length; i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
366 {
25
113428ba033c Whitespace fixes
David Grundberg <individ@acc.umu.se>
parents: 9
diff changeset
367 octave_value val;
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
368
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
369 pyobj_to_octvalue (val, list[i]);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
370 values.append (val);
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
371
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
372 }
25
113428ba033c Whitespace fixes
David Grundberg <individ@acc.umu.se>
parents: 9
diff changeset
373
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
374 oct_value = Cell (values);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
375 }
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
376
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
377 static void
179
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
378 pytuple_to_cellarray (octave_value& oct_value, const boost::python::tuple& tuple)
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
379 {
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
380 octave_idx_type length = boost::python::extract<octave_idx_type> (tuple.attr ("__len__") ());
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
381 octave_value_list values;
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
382
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
383 for (octave_idx_type i = 0; i < length; i++)
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
384 {
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
385 octave_value val;
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
386
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
387 pyobj_to_octvalue (val, tuple[i]);
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
388 values.append (val);
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
389
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
390 }
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
391
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
392 oct_value = Cell (values);
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
393 }
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
394
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
395 static void
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
396 pydict_to_octmap (octave_value& oct_value, const boost::python::dict& dict)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
397 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
398 boost::python::list list = dict.items ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
399 octave_idx_type length = boost::python::extract<octave_idx_type> (list.attr ("__len__") ());
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
400
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
401 dim_vector dims = dim_vector (1, 1);
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
402
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
403 octave_value_list vals (length);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
404 string_vector keys (length);
43
31df83060183 avoid duplicate conversions in python dict->octave map
Jaroslav Hajek <highegg@gmail.com>
parents: 31
diff changeset
405
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
406 // Extract all keys and convert values. Remember whether dimensions
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
407 // match.
107
691ef5c6b9e2 maint: Clean up std namespace pollution
Mike Miller <mtmiller@octave.org>
parents: 106
diff changeset
408
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
409 for (octave_idx_type i = 0; i < length; i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
410 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
411 std::string& key = keys[i];
43
31df83060183 avoid duplicate conversions in python dict->octave map
Jaroslav Hajek <highegg@gmail.com>
parents: 31
diff changeset
412
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
413 boost::python::tuple tuple =
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
414 boost::python::extract<boost::python::tuple> (list[i]) ();
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
415
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
416 boost::python::extract<std::string> str (tuple[0]);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
417 if (! str.check ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
418 throw object_convert_exception (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
419 std::string ("Can not convert key of type ")
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
420 + PyEval_GetFuncName (boost::python::object (tuple[0]).ptr ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
421 + PyEval_GetFuncDesc (boost::python::object (tuple[0]).ptr ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
422 + " to a structure field name. Field names must be strings.");
43
31df83060183 avoid duplicate conversions in python dict->octave map
Jaroslav Hajek <highegg@gmail.com>
parents: 31
diff changeset
423
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
424 key = str ();
43
31df83060183 avoid duplicate conversions in python dict->octave map
Jaroslav Hajek <highegg@gmail.com>
parents: 31
diff changeset
425
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
426 if (! valid_identifier (key))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
427 throw object_convert_exception (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
428 std::string ("Can not convert key `") + key + "' to a structure "
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
429 "field name. Field names must be valid Octave identifiers.");
43
31df83060183 avoid duplicate conversions in python dict->octave map
Jaroslav Hajek <highegg@gmail.com>
parents: 31
diff changeset
430
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
431 octave_value& val = vals(i);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
432
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
433 pyobj_to_octvalue (val, tuple[1]);
43
31df83060183 avoid duplicate conversions in python dict->octave map
Jaroslav Hajek <highegg@gmail.com>
parents: 31
diff changeset
434
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
435 if (val.is_cell ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
436 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
437 if (i == 0)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
438 dims = val.dims ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
439 else if (val.numel () != 1 && val.dims () != dims)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
440 throw object_convert_exception (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
441 "Dimensions of the struct fields do not match");
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
442 }
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
443 }
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
444
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
445 octave_map map = octave_map (dims);
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
446
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
447 for (octave_idx_type i = 0; i < length; i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
448 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
449 std::string& key = keys[i];
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
450 octave_value val = vals(i);
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
451
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
452 if (val.is_cell ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
453 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
454 const Cell c = val.cell_value ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
455 if (c.numel () == 1)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
456 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
457 map.assign (key, Cell (dims, c(0)));
68
2f4d6286fb36 make Octave->Python conversions uniformly arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 56
diff changeset
458 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
459 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
460 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
461 map.assign (key, c);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
462 }
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
463 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
464 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
465 map.assign (key, Cell (dims, val));
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
466 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
467 oct_value = map;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
468 }
9
9a773d71a973 celler & structar ^_^
Håkan Fors nilsson <c04hfn@cs.umu.se>
parents: 6
diff changeset
469
278
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
470 static void
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
471 pyobj_to_oct_pyobject (octave_value& oct_value,
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
472 const boost::python::object& py_object)
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
473 {
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
474 object main_module = import ("__main__");
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
475 object main_namespace = main_module.attr ("__dict__");
306
2ecae5c6eeb6 Refactor code, have common functions in pytave_utils
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 282
diff changeset
476 object builtins_module;
2ecae5c6eeb6 Refactor code, have common functions in pytave_utils
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 282
diff changeset
477 pytave::get_builtins_module (builtins_module);
278
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
478 object hex_function = builtins_module.attr ("hex");
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
479 object id_function = builtins_module.attr ("id");
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
480 object idtmp = hex_function (id_function (py_object));
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
481 std::string id = extract<std::string> (idtmp);
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
482
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
483 // Ensure we have a __InOct__ dict, and then put `res` into it
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
484 exec ("if not (\"__InOct__\" in vars() or \"__InOct__\" in globals()):\n"
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
485 " __InOct__ = dict()\n"
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
486 " # FIXME: make it accessible elsewhere?\n"
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
487 " import __main__\n"
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
488 " __main__.__InOct__ = __InOct__\n",
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
489 main_namespace, main_namespace);
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
490 main_namespace["__InOct__"][id] = py_object;
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
491 // Create @pyobject
282
4c4747646e12 Make pyobject callable by users (to convert input)
Colin Macdonald <cbm@m.fsf.org>
parents: 279
diff changeset
492 oct_value = feval ("pyobject", ovl (0, id), 2);
278
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
493 }
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
494
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
495 void pyobj_to_octvalue (octave_value& oct_value,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
496 const boost::python::object& py_object)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
497 {
271
0a4f620da178 Convert numeric value to long instead of int to avoid overflow (fixes issue #40)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
498 extract<long> longx (py_object);
183
2b03585d4ddd Add proper conversion of booleans between octave and python. (fixes issue #6)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 179
diff changeset
499 extract<bool> boolx (py_object);
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
500 extract<double> doublex (py_object);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
501 extract<Complex> complexx (py_object);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
502 extract<numeric::array> arrayx (py_object);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
503 extract<boost::python::list> listx (py_object);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
504 extract<boost::python::dict> dictx (py_object);
179
c05ff3e85fec Add conversion of python tuples to octave cell arrays.
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 177
diff changeset
505 extract<boost::python::tuple> tuplex (py_object);
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
506
184
8b97647e48f1 maint: whitespace fixes for cset 2b03585d4ddd
Mike Miller <mtmiller@octave.org>
parents: 183
diff changeset
507 if (boolx.check () && PyBool_Check ((PyArrayObject*)py_object.ptr ()))
183
2b03585d4ddd Add proper conversion of booleans between octave and python. (fixes issue #6)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 179
diff changeset
508 oct_value = boolx ();
271
0a4f620da178 Convert numeric value to long instead of int to avoid overflow (fixes issue #40)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
509 else if (longx.check ())
0a4f620da178 Convert numeric value to long instead of int to avoid overflow (fixes issue #40)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
510 oct_value = longx ();
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
511 else if (doublex.check ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
512 oct_value = doublex ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
513 else if (complexx.check ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
514 oct_value = complexx ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
515 else if (arrayx.check ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
516 pyarr_to_octvalue (oct_value, (PyArrayObject*)py_object.ptr ());
325
fd5881d48238 Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents: 306
diff changeset
517 else if (PyBytes_Check (py_object.ptr ()) || PyUnicode_Check (py_object.ptr ()))
fd5881d48238 Overhaul Python string creation and extraction
Mike Miller <mtmiller@octave.org>
parents: 306
diff changeset
518 oct_value = extract_py_str (py_object.ptr ());
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
519 else
278
9278a272b1c8 Drop conversion of lists, dicts and tuples (fixes issues #27, #26)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 225
diff changeset
520 pyobj_to_oct_pyobject (oct_value, py_object);
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
521 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
522
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
523 void pytuple_to_octlist (octave_value_list& octave_list,
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
524 const boost::python::tuple& python_tuple)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
525 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
526 int length = extract<int> (python_tuple.attr ("__len__") ());
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
527
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
528 for (int i = 0; i < length; i++)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
529 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
530 pyobj_to_octvalue (octave_list(i), python_tuple[i]);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
531 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 143
diff changeset
532 }
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
533 }