Mercurial > pytave
annotate @py/py.m @ 417:4e427ec1650a
build: add Python library directory to oct file runtime path
* configure.ac: Add a -R option to add the Python library directory to the
runtime path of oct files if it is in a non-standard location.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 04 May 2017 08:11:33 -0700 |
parents | 087e7bc3697f |
children |
rev | line source |
---|---|
252
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
1 ## Copyright (C) 2016 Mike Miller |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
2 ## |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
3 ## This file is part of Pytave. |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
4 ## |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
5 ## Pytave is free software; you can redistribute it and/or modify it |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
8 ## your option) any later version. |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
9 ## |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
10 ## Pytave is distributed in the hope that it will be useful, but |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
13 ## General Public License for more details. |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
14 ## |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
16 ## along with Pytave; see the file COPYING. If not, see |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
18 |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
20 ## @deftypefn {} {} py |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
21 ## @deftypefnx {} {} py.@var{pyname} |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
22 ## Get the value of a Python object or call a Python function. |
259
16bf288f25ad
doc: fix py doc string typo (fixes issue #46)
Mike Miller <mtmiller@octave.org>
parents:
252
diff
changeset
|
23 ## @end deftypefn |
252
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
24 |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
25 function p = py () |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
26 p = class (struct (), "py"); |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
27 endfunction |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
28 |
8ebebd557e15
py: initial support for calling Python functions with "py.foo" syntax
Mike Miller <mtmiller@octave.org>
parents:
diff
changeset
|
29 %!assert (py.math.sqrt (2), sqrt (2)) |
365
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
343
diff
changeset
|
30 %!assert (ischar (char (py.sys.version))) |
328
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
31 |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
32 %!test |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
33 %! if (double (py.sys.hexversion) >= 0x03000000) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
34 %! assert (isobject (py.int (0))) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
35 %! else |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
36 %! assert (py.int (0), int64 (0)) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
37 %! endif |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
38 |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
39 %!test |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
40 %! if (double (py.sys.hexversion) < 0x03000000) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
41 %! assert (py.int (2147483647), int64 (2147483647)) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
42 %! endif |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
43 |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
44 %!test |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
45 %! if (double (py.sys.hexversion) < 0x03000000) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
46 %! assert (isobject (py.long (0))) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
47 %! endif |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
48 |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
49 %!test |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
50 %! if (double (py.sys.hexversion) >= 0x03000000) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
51 %! assert (isobject (py.int (2^100))) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
52 %! else |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
53 %! assert (isobject (py.long (2^100))) |
5782d7932529
Automatically convert Python 2 'int' type to Octave int64 (fixes issue #56)
Mike Miller <mtmiller@octave.org>
parents:
259
diff
changeset
|
54 %! endif |
343
fe6b9e618c98
Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
55 |
fe6b9e618c98
Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
56 ## Cannot use '@' to make a handle to a Python function |
fe6b9e618c98
Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
57 %!xtest |
fe6b9e618c98
Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
58 %! fn = @py.math.abs; |
fe6b9e618c98
Add %!xtests for known failures due to bugs in Octave
Mike Miller <mtmiller@octave.org>
parents:
328
diff
changeset
|
59 %! assert (fn (-3), 3) |