comparison package/pytave.py @ 0:4da14cce0890 pytave-branch

First launchpad.net check in.
author David Grundberg <c04dgg@cs.umu.se>
date Fri, 17 Oct 2008 12:05:46 +0200
parents
children d95e9d46f538
comparison
equal deleted inserted replaced
-1:000000000000 0:4da14cce0890
1 # -*- coding:utf-8 -*-
2 #
3 # Copyright 2008 David Grundberg, HÃ¥kan Fors Nilsson
4 #
5 # This file is part of Pytave.
6 #
7 # Pytave is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # Pytave is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Pytave. If not, see <http://www.gnu.org/licenses/>.
19
20 """Python to Octave bridge"""
21
22 import _pytave
23
24 _pytave.init()
25 (OctaveError, ValueConvertError, ObjectConvertError) \
26 = _pytave.get_exceptions();
27
28 def feval(nargout, funcname, *arguments):
29
30 """Executes an Octave function called funcname.
31
32 The function is set to return nargout values. Returned values are
33 stored in a tuple. If the nargout argument is less than or equal
34 to 0, an empty tuple is returned.
35
36 M-files are searched for in the Octave path.
37
38 See also the Octave documentation for the builtin Octave function
39 feval.
40
41 Type conversions
42 ****************
43
44 The following type conversions are supported:
45
46 Python to Octave
47 ================
48
49 Objects:
50 int (32-bit) int32
51 float (64-bit) double
52 str string
53
54 Numeric Array:
55 UBYTE, SBYTE, matrix of correct type
56 USHORT, SHORT, -''-
57 UINT, SINT, -''-
58 LONG, -''-
59 DOUBLE -''-
60
61 All other objects causes a pytave.ObjectConvertError to be
62 raised. This exception inherits TypeError.
63
64 Octave to Python
65 ================
66
67 Scalar values to objects:
68 bool bool
69 real scalar float (64-bit)
70 string, sq_string str
71 str string
72
73 Matrix values to Numeric arrays:
74 int64 LONG
75 int32, uint32 INT, UINT
76 int16, uint16 SHORT, USHORT
77 int8, unint8 SBYTE, UBYTE
78
79 All other values causes a pytave.ValueConvertError to be
80 raised. This exception inherits TypeError.
81
82 Errors
83 ******
84
85 Octave runtime errors are encapsulated into
86 pytave.OctaveError exceptions, base class RuntimeError.
87
88 """
89
90 return _pytave.feval(nargout, funcname, arguments)
91
92 def addpath(*arguments):
93 """See Octave documentation"""
94 return _pytave.feval(1, "addpath", arguments)[0]
95
96 def rmpath(*paths):
97 """See Octave documentation"""
98 return _pytave.feval(1, "rmpath", paths)[0]
99
100 def path(*paths):
101 """See Octave documentation"""
102 return _pytave.feval(1, "path", paths)[0]
103
104 # Emacs
105 # Local Variables:
106 # fill-column:70
107 # coding:utf-8
108 # indent-tabs-mode:t
109 # tab-width:3
110 # End:
111 # vim: set textwidth=70 noexpandtab tabstop=3 :