Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
faec30c4
Commit
faec30c4
authored
Aug 22, 2016
by
Wenzel Jakob
Committed by
GitHub
Aug 22, 2016
Browse files
Merge pull request #321 from dean0x7d/pytest
Port test suite to pytest
parents
bf099587
99dbdc16
Changes
108
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
0 additions
and
736 deletions
+0
-736
example/example-eval.py
example/example-eval.py
+0
-5
example/example-eval.ref
example/example-eval.ref
+0
-13
example/example-eval_call.py
example/example-eval_call.py
+0
-1
example/example-inheritance.py
example/example-inheritance.py
+0
-12
example/example-inheritance.ref
example/example-inheritance.ref
+0
-3
example/example-keep-alive.py
example/example-keep-alive.py
+0
-67
example/example-keep-alive.ref
example/example-keep-alive.ref
+0
-33
example/example-methods-and-attributes.py
example/example-methods-and-attributes.py
+0
-50
example/example-methods-and-attributes.ref
example/example-methods-and-attributes.ref
+0
-34
example/example-modules.py
example/example-modules.py
+0
-43
example/example-modules.ref
example/example-modules.ref
+0
-31
example/example-numpy-dtypes.py
example/example-numpy-dtypes.py
+0
-102
example/example-numpy-dtypes.ref
example/example-numpy-dtypes.ref
+0
-28
example/example-numpy-vectorize.py
example/example-numpy-vectorize.py
+0
-36
example/example-numpy-vectorize.ref
example/example-numpy-vectorize.ref
+0
-79
example/example-opaque-types.py
example/example-opaque-types.py
+0
-52
example/example-opaque-types.ref
example/example-opaque-types.ref
+0
-19
example/example-operator-overloading.py
example/example-operator-overloading.py
+0
-41
example/example-operator-overloading.ref
example/example-operator-overloading.ref
+0
-66
example/example-pickling.py
example/example-pickling.py
+0
-21
No files found.
example/example-eval.py
deleted
100644 → 0
View file @
bf099587
from
example
import
example_eval
example_eval
()
example/example-eval.ref
deleted
100644 → 0
View file @
bf099587
eval_statements test
eval_statements passed
eval test
eval passed
eval_single_statement test
eval_single_statement passed
eval_file test
eval_file passed
eval failure test
eval failure test passed
eval_file failure test
eval_file failure test passed
Hello World!
example/example-eval_call.py
deleted
100644 → 0
View file @
bf099587
call_test2
(
y
)
\ No newline at end of file
example/example-inheritance.py
deleted
100644 → 0
View file @
bf099587
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
from
example
import
return_class_1
from
example
import
return_class_2
from
example
import
return_none
print
(
type
(
return_class_1
()).
__name__
)
print
(
type
(
return_class_2
()).
__name__
)
print
(
type
(
return_none
()).
__name__
)
example/example-inheritance.ref
deleted
100644 → 0
View file @
bf099587
DerivedClass1
DerivedClass2
NoneType
example/example-keep-alive.py
deleted
100644 → 0
View file @
bf099587
from
__future__
import
print_function
import
sys
import
gc
sys
.
path
.
append
(
'.'
)
from
example
import
Parent
,
Child
if
True
:
p
=
Parent
()
p
.
addChild
(
Child
())
gc
.
collect
()
print
(
p
)
p
=
None
gc
.
collect
()
print
(
""
)
if
True
:
p
=
Parent
()
p
.
returnChild
()
gc
.
collect
()
print
(
p
)
p
=
None
gc
.
collect
()
print
(
""
)
if
True
:
p
=
Parent
()
p
.
addChildKeepAlive
(
Child
())
gc
.
collect
()
print
(
p
)
p
=
None
gc
.
collect
()
print
(
""
)
if
True
:
p
=
Parent
()
p
.
returnChildKeepAlive
()
gc
.
collect
()
print
(
p
)
p
=
None
gc
.
collect
()
print
(
""
)
if
True
:
p
=
Parent
()
p
.
returnNullChildKeepAliveChild
()
gc
.
collect
()
print
(
p
)
p
=
None
gc
.
collect
()
print
(
""
)
if
True
:
p
=
Parent
()
p
.
returnNullChildKeepAliveParent
()
gc
.
collect
()
print
(
p
)
p
=
None
gc
.
collect
()
print
(
""
)
print
(
"Terminating.."
)
example/example-keep-alive.ref
deleted
100644 → 0
View file @
bf099587
Allocating parent.
Allocating child.
Releasing child.
<example.Parent object at 0x10eb726c0>
Releasing parent.
Allocating parent.
Allocating child.
Releasing child.
<example.Parent object at 0x10eb726c0>
Releasing parent.
Allocating parent.
Allocating child.
<example.Parent object at 0x10eb726c0>
Releasing parent.
Releasing child.
Allocating parent.
Allocating child.
<example.Parent object at 0x10eb726c0>
Releasing parent.
Releasing child.
Allocating parent.
<example.Parent object at 0x10eb726c0>
Releasing parent.
Allocating parent.
<example.Parent object at 0x10eb726c0>
Releasing parent.
Terminating..
example/example-methods-and-attributes.py
deleted
100755 → 0
View file @
bf099587
#!/usr/bin/env python
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
from
example
import
ExampleMandA
instance1
=
ExampleMandA
()
instance2
=
ExampleMandA
(
32
)
instance1
.
add1
(
instance2
)
instance1
.
add2
(
instance2
)
instance1
.
add3
(
instance2
)
instance1
.
add4
(
instance2
)
instance1
.
add5
(
instance2
)
instance1
.
add6
(
32
)
instance1
.
add7
(
32
)
instance1
.
add8
(
32
)
instance1
.
add9
(
32
)
instance1
.
add10
(
32
)
print
(
"Instance 1: "
+
str
(
instance1
))
print
(
"Instance 2: "
+
str
(
instance2
))
print
(
instance1
.
self1
())
print
(
instance1
.
self2
())
print
(
instance1
.
self3
())
print
(
instance1
.
self4
())
print
(
instance1
.
self5
())
print
(
instance1
.
internal1
())
print
(
instance1
.
internal2
())
print
(
instance1
.
internal3
())
print
(
instance1
.
internal4
())
print
(
instance1
.
internal5
())
print
(
"Instance 1, direct access = %i"
%
instance1
.
value
)
instance1
.
value
=
100
print
(
"Instance 1: "
+
str
(
instance1
))
from
example
import
ConstructorStats
cstats
=
ConstructorStats
.
get
(
ExampleMandA
)
print
(
"Instances not destroyed:"
,
cstats
.
alive
())
instance1
=
instance2
=
None
print
(
"Instances not destroyed:"
,
cstats
.
alive
())
print
(
"Constructor values:"
,
cstats
.
values
())
print
(
"Default constructions:"
,
cstats
.
default_constructions
)
print
(
"Copy constructions:"
,
cstats
.
copy_constructions
)
print
(
"Move constructions:"
,
cstats
.
move_constructions
>=
1
)
print
(
"Copy assignments:"
,
cstats
.
copy_assignments
)
print
(
"Move assignments:"
,
cstats
.
move_assignments
)
example/example-methods-and-attributes.ref
deleted
100644 → 0
View file @
bf099587
### ExampleMandA @ 0x2801910 created via default constructor
### ExampleMandA @ 0x27fa780 created 32
### ExampleMandA @ 0x7fff80a98a74 created via copy constructor
### ExampleMandA @ 0x7fff80a98a78 created via copy constructor
### ExampleMandA @ 0x7fff80a98a78 destroyed
### ExampleMandA @ 0x7fff80a98a74 destroyed
Instance 1: ExampleMandA[value=320]
Instance 2: ExampleMandA[value=32]
### ExampleMandA @ 0x7fff80a98a84 created via copy constructor
### ExampleMandA @ 0x2801fd0 created via move constructor
### ExampleMandA @ 0x7fff80a98a84 destroyed
ExampleMandA[value=320]
### ExampleMandA @ 0x2801fd0 destroyed
ExampleMandA[value=320]
ExampleMandA[value=320]
ExampleMandA[value=320]
ExampleMandA[value=320]
320
320
320
320
320
Instance 1, direct access = 320
Instance 1: ExampleMandA[value=100]
Instances not destroyed: 2
### ExampleMandA @ 0x2801910 destroyed
### ExampleMandA @ 0x27fa780 destroyed
Instances not destroyed: 0
Constructor values: ['32']
Default constructions: 1
Copy constructions: 3
Move constructions: True
Copy assignments: 0
Move assignments: 0
example/example-modules.py
deleted
100755 → 0
View file @
bf099587
#!/usr/bin/env python
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
import
example
print
(
example
.
__name__
)
print
(
example
.
submodule
.
__name__
)
from
example.submodule
import
*
from
example
import
OD
submodule_func
()
b
=
B
()
print
(
b
.
get_a1
())
print
(
b
.
a1
)
print
(
b
.
get_a2
())
print
(
b
.
a2
)
b
.
a1
=
A
(
42
)
b
.
a2
=
A
(
43
)
print
(
b
.
get_a1
())
print
(
b
.
a1
)
print
(
b
.
get_a2
())
print
(
b
.
a2
)
print
(
OD
([(
1
,
'a'
),
(
2
,
'b'
)]))
from
example
import
ConstructorStats
cstats
=
[
ConstructorStats
.
get
(
A
),
ConstructorStats
.
get
(
B
)]
print
(
"Instances not destroyed:"
,
[
x
.
alive
()
for
x
in
cstats
])
b
=
None
print
(
"Instances not destroyed:"
,
[
x
.
alive
()
for
x
in
cstats
])
print
(
"Constructor values:"
,
[
x
.
values
()
for
x
in
cstats
])
print
(
"Default constructions:"
,
[
x
.
default_constructions
for
x
in
cstats
])
print
(
"Copy constructions:"
,
[
x
.
copy_constructions
for
x
in
cstats
])
#print("Move constructions:", [x.move_constructions >= 0 for x in cstats]) # Don't invoke any
print
(
"Copy assignments:"
,
[
x
.
copy_assignments
for
x
in
cstats
])
print
(
"Move assignments:"
,
[
x
.
move_assignments
for
x
in
cstats
])
example/example-modules.ref
deleted
100644 → 0
View file @
bf099587
example
example.submodule
submodule_func()
### A @ 0x21a5bc0 created 1
### A @ 0x21a5bc4 created 2
### B @ 0x21a5bc0 created via default constructor
A[1]
A[1]
A[2]
A[2]
### A @ 0x20f93b0 created 42
### A @ 0x21a5bc0 assigned via copy assignment
### A @ 0x20f93b0 destroyed
### A @ 0x20f93d0 created 43
### A @ 0x21a5bc4 assigned via copy assignment
### A @ 0x20f93d0 destroyed
A[42]
A[42]
A[43]
A[43]
OrderedDict([(1, 'a'), (2, 'b')])
Instances not destroyed: [2, 1]
### B @ 0x21a5bc0 destroyed
### A @ 0x21a5bc4 destroyed
### A @ 0x21a5bc0 destroyed
Instances not destroyed: [0, 0]
Constructor values: [['1', '2', '42', '43'], []]
Default constructions: [0, 1]
Copy constructions: [0, 0]
Copy assignments: [2, 0]
Move assignments: [0, 0]
example/example-numpy-dtypes.py
deleted
100644 → 0
View file @
bf099587
#!/usr/bin/env python
from
__future__
import
print_function
import
numpy
as
np
from
example
import
(
create_rec_simple
,
create_rec_packed
,
create_rec_nested
,
print_format_descriptors
,
print_rec_simple
,
print_rec_packed
,
print_rec_nested
,
print_dtypes
,
get_format_unbound
,
create_rec_partial
,
create_rec_partial_nested
,
create_string_array
,
print_string_array
,
test_array_ctors
,
test_dtype_ctors
,
test_dtype_methods
)
def
check_eq
(
arr
,
data
,
dtype
):
np
.
testing
.
assert_equal
(
arr
,
np
.
array
(
data
,
dtype
=
dtype
))
try
:
get_format_unbound
()
raise
Exception
except
RuntimeError
as
e
:
assert
'unsupported buffer format'
in
str
(
e
)
print_format_descriptors
()
print_dtypes
()
simple_dtype
=
np
.
dtype
({
'names'
:
[
'x'
,
'y'
,
'z'
],
'formats'
:
[
'?'
,
'u4'
,
'f4'
],
'offsets'
:
[
0
,
4
,
8
]})
packed_dtype
=
np
.
dtype
([(
'x'
,
'?'
),
(
'y'
,
'u4'
),
(
'z'
,
'f4'
)])
elements
=
[(
False
,
0
,
0.0
),
(
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)]
for
func
,
dtype
in
[(
create_rec_simple
,
simple_dtype
),
(
create_rec_packed
,
packed_dtype
)]:
arr
=
func
(
0
)
assert
arr
.
dtype
==
dtype
check_eq
(
arr
,
[],
simple_dtype
)
check_eq
(
arr
,
[],
packed_dtype
)
arr
=
func
(
3
)
assert
arr
.
dtype
==
dtype
check_eq
(
arr
,
elements
,
simple_dtype
)
check_eq
(
arr
,
elements
,
packed_dtype
)
if
dtype
==
simple_dtype
:
print_rec_simple
(
arr
)
else
:
print_rec_packed
(
arr
)
arr
=
create_rec_partial
(
3
)
print
(
arr
.
dtype
)
partial_dtype
=
arr
.
dtype
assert
''
not
in
arr
.
dtype
.
fields
assert
partial_dtype
.
itemsize
>
simple_dtype
.
itemsize
check_eq
(
arr
,
elements
,
simple_dtype
)
check_eq
(
arr
,
elements
,
packed_dtype
)
arr
=
create_rec_partial_nested
(
3
)
print
(
arr
.
dtype
)
assert
''
not
in
arr
.
dtype
.
fields
assert
''
not
in
arr
.
dtype
.
fields
[
'a'
][
0
].
fields
assert
arr
.
dtype
.
itemsize
>
partial_dtype
.
itemsize
np
.
testing
.
assert_equal
(
arr
[
'a'
],
create_rec_partial
(
3
))
nested_dtype
=
np
.
dtype
([(
'a'
,
simple_dtype
),
(
'b'
,
packed_dtype
)])
arr
=
create_rec_nested
(
0
)
assert
arr
.
dtype
==
nested_dtype
check_eq
(
arr
,
[],
nested_dtype
)
arr
=
create_rec_nested
(
3
)
assert
arr
.
dtype
==
nested_dtype
check_eq
(
arr
,
[((
False
,
0
,
0.0
),
(
True
,
1
,
1.5
)),
((
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)),
((
False
,
2
,
3.0
),
(
True
,
3
,
4.5
))],
nested_dtype
)
print_rec_nested
(
arr
)
assert
create_rec_nested
.
__doc__
.
strip
().
endswith
(
'numpy.ndarray[NestedStruct]'
)
arr
=
create_string_array
(
True
)
print
(
arr
.
dtype
)
print_string_array
(
arr
)
dtype
=
arr
.
dtype
assert
arr
[
'a'
].
tolist
()
==
[
b
''
,
b
'a'
,
b
'ab'
,
b
'abc'
]
assert
arr
[
'b'
].
tolist
()
==
[
b
''
,
b
'a'
,
b
'ab'
,
b
'abc'
]
arr
=
create_string_array
(
False
)
assert
dtype
==
arr
.
dtype
data
=
np
.
arange
(
1
,
7
,
dtype
=
'int32'
)
for
i
in
range
(
8
):
np
.
testing
.
assert_array_equal
(
test_array_ctors
(
10
+
i
),
data
.
reshape
((
3
,
2
)))
np
.
testing
.
assert_array_equal
(
test_array_ctors
(
20
+
i
),
data
.
reshape
((
3
,
2
)))
for
i
in
range
(
5
):
np
.
testing
.
assert_array_equal
(
test_array_ctors
(
30
+
i
),
data
)
np
.
testing
.
assert_array_equal
(
test_array_ctors
(
40
+
i
),
data
)
d1
=
np
.
dtype
({
'names'
:
[
'a'
,
'b'
],
'formats'
:
[
'int32'
,
'float64'
],
'offsets'
:
[
1
,
10
],
'itemsize'
:
20
})
d2
=
np
.
dtype
([(
'a'
,
'i4'
),
(
'b'
,
'f4'
)])
assert
test_dtype_ctors
()
==
[
np
.
dtype
(
'int32'
),
np
.
dtype
(
'float64'
),
np
.
dtype
(
'bool'
),
d1
,
d1
,
np
.
dtype
(
'uint32'
),
d2
]
assert
test_dtype_methods
()
==
[
np
.
dtype
(
'int32'
),
simple_dtype
,
False
,
True
,
np
.
dtype
(
'int32'
).
itemsize
,
simple_dtype
.
itemsize
]
example/example-numpy-dtypes.ref
deleted
100644 → 0
View file @
bf099587
T{=?:x:3x=I:y:=f:z:}
T{=?:x:=I:y:=f:z:}
T{=T{=?:x:3x=I:y:=f:z:}:a:=T{=?:x:=I:y:=f:z:}:b:}
T{=?:x:3x=I:y:=f:z:12x}
T{8x=T{=?:x:3x=I:y:=f:z:12x}:a:8x}
T{=3s:a:=3s:b:}
{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':12}
[('x', '?'), ('y', '<u4'), ('z', '<f4')]
[('a', {'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':12}), ('b', [('x', '?'), ('y', '<u4'), ('z', '<f4')])]
{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}
{'names':['a'], 'formats':[{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}], 'offsets':[8], 'itemsize':40}
[('a', 'S3'), ('b', 'S3')]
s:0,0,0
s:1,1,1.5
s:0,2,3
p:0,0,0
p:1,1,1.5
p:0,2,3
{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}
{'names':['a'], 'formats':[{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}], 'offsets':[8], 'itemsize':40}
n:a=s:0,0,0;b=p:1,1,1.5
n:a=s:1,1,1.5;b=p:0,2,3
n:a=s:0,2,3;b=p:1,3,4.5
[('a', 'S3'), ('b', 'S3')]
a='',b=''
a='a',b='a'
a='ab',b='ab'
a='abc',b='abc'
example/example-numpy-vectorize.py
deleted
100755 → 0
View file @
bf099587
#!/usr/bin/env python
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
import
example
try
:
import
numpy
as
np
except
ImportError
:
# NumPy missing: skip test
exit
(
99
)
from
example
import
vectorized_func
from
example
import
vectorized_func2
from
example
import
vectorized_func3
print
(
vectorized_func3
(
np
.
array
(
3
+
7j
)))
for
f
in
[
vectorized_func
,
vectorized_func2
]:
print
(
f
(
1
,
2
,
3
))
print
(
f
(
np
.
array
(
1
),
np
.
array
(
2
),
3
))
print
(
f
(
np
.
array
([
1
,
3
]),
np
.
array
([
2
,
4
]),
3
))
print
(
f
(
np
.
array
([[
1
,
3
,
5
],
[
7
,
9
,
11
]]),
np
.
array
([[
2
,
4
,
6
],
[
8
,
10
,
12
]]),
3
))
print
(
np
.
array
([[
1
,
3
,
5
],
[
7
,
9
,
11
]])
*
np
.
array
([[
2
,
4
,
6
],
[
8
,
10
,
12
]])
*
3
)
print
(
f
(
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]]),
np
.
array
([
2
,
3
,
4
]),
2
))
print
(
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]])
*
np
.
array
([
2
,
3
,
4
])
*
2
)
print
(
f
(
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]]),
np
.
array
([[
2
],
[
3
]]),
2
))
print
(
np
.
array
([[
1
,
2
,
3
],
[
4
,
5
,
6
]])
*
np
.
array
([[
2
],
[
3
]])
*
2
)
from
example
import
selective_func
selective_func
(
np
.
array
([
1
],
dtype
=
np
.
int32
))
selective_func
(
np
.
array
([
1.0
],
dtype
=
np
.
float32
))
selective_func
(
np
.
array
([
1.0j
],
dtype
=
np
.
complex64
))
print
(
vectorized_func
.
__doc__
)
example/example-numpy-vectorize.ref
deleted
100644 → 0
View file @
bf099587
(6+14j)
my_func(x:int=1, y:float=2, z:float=3)
6.0
my_func(x:int=1, y:float=2, z:float=3)
6.0
my_func(x:int=1, y:float=2, z:float=3)
my_func(x:int=3, y:float=4, z:float=3)
[ 6. 36.]
my_func(x:int=1, y:float=2, z:float=3)
my_func(x:int=3, y:float=4, z:float=3)
my_func(x:int=5, y:float=6, z:float=3)
my_func(x:int=7, y:float=8, z:float=3)
my_func(x:int=9, y:float=10, z:float=3)
my_func(x:int=11, y:float=12, z:float=3)
[[ 6. 36. 90.]
[ 168. 270. 396.]]
[[ 6 36 90]
[168 270 396]]
my_func(x:int=1, y:float=2, z:float=2)
my_func(x:int=2, y:float=3, z:float=2)
my_func(x:int=3, y:float=4, z:float=2)
my_func(x:int=4, y:float=2, z:float=2)
my_func(x:int=5, y:float=3, z:float=2)
my_func(x:int=6, y:float=4, z:float=2)
[[ 4. 12. 24.]
[ 16. 30. 48.]]
[[ 4 12 24]
[16 30 48]]
my_func(x:int=1, y:float=2, z:float=2)
my_func(x:int=2, y:float=2, z:float=2)
my_func(x:int=3, y:float=2, z:float=2)
my_func(x:int=4, y:float=3, z:float=2)
my_func(x:int=5, y:float=3, z:float=2)
my_func(x:int=6, y:float=3, z:float=2)
[[ 4. 8. 12.]
[ 24. 30. 36.]]
[[ 4 8 12]
[24 30 36]]
my_func(x:int=1, y:float=2, z:float=3)
6.0
my_func(x:int=1, y:float=2, z:float=3)
6.0
my_func(x:int=1, y:float=2, z:float=3)
my_func(x:int=3, y:float=4, z:float=3)
[ 6. 36.]
my_func(x:int=1, y:float=2, z:float=3)
my_func(x:int=3, y:float=4, z:float=3)
my_func(x:int=5, y:float=6, z:float=3)
my_func(x:int=7, y:float=8, z:float=3)
my_func(x:int=9, y:float=10, z:float=3)
my_func(x:int=11, y:float=12, z:float=3)
[[ 6. 36. 90.]
[ 168. 270. 396.]]
[[ 6 36 90]
[168 270 396]]
my_func(x:int=1, y:float=2, z:float=2)
my_func(x:int=2, y:float=3, z:float=2)
my_func(x:int=3, y:float=4, z:float=2)
my_func(x:int=4, y:float=2, z:float=2)
my_func(x:int=5, y:float=3, z:float=2)
my_func(x:int=6, y:float=4, z:float=2)
[[ 4. 12. 24.]
[ 16. 30. 48.]]
[[ 4 12 24]
[16 30 48]]
my_func(x:int=1, y:float=2, z:float=2)
my_func(x:int=2, y:float=2, z:float=2)
my_func(x:int=3, y:float=2, z:float=2)
my_func(x:int=4, y:float=3, z:float=2)
my_func(x:int=5, y:float=3, z:float=2)
my_func(x:int=6, y:float=3, z:float=2)
[[ 4. 8. 12.]
[ 24. 30. 36.]]
[[ 4 8 12]
[24 30 36]]
Int branch taken.
Float branch taken.
Complex float branch taken.
vectorized_func(arg0: numpy.ndarray[int], arg1: numpy.ndarray[float], arg2: numpy.ndarray[float]) -> object
example/example-opaque-types.py
deleted
100644 → 0
View file @
bf099587
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
from
example
import
StringList
,
print_opaque_list
from
example
import
ClassWithSTLVecProperty
from
example
import
return_void_ptr
,
print_void_ptr
from
example
import
return_null_str
,
print_null_str
from
example
import
return_unique_ptr
from
example
import
ExampleMandA
#####
l
=
StringList
()
l
.
push_back
(
"Element 1"
)
l
.
push_back
(
"Element 2"
)
print_opaque_list
(
l
)
print
(
"Back element is %s"
%
l
.
back
())
for
i
,
k
in
enumerate
(
l
):
print
(
"%i/%i : %s"
%
(
i
+
1
,
len
(
l
),
k
))
l
.
pop_back
()
print_opaque_list
(
l
)
#####
cvp
=
ClassWithSTLVecProperty
()
print_opaque_list
(
cvp
.
stringList
)
cvp
.
stringList
=
l
cvp
.
stringList
.
push_back
(
"Element 3"
)
print_opaque_list
(
cvp
.
stringList
)
#####
print_void_ptr
(
return_void_ptr
())
print_void_ptr
(
ExampleMandA
())
# Should also work for other C++ types
from
example
import
ConstructorStats
print
(
"ExampleMandA still alive:"
,
ConstructorStats
.
get
(
ExampleMandA
).
alive
())
try
:
print_void_ptr
([
1
,
2
,
3
])
# This should not work
except
Exception
as
e
:
print
(
"Caught expected exception: "
+
str
(
e
))
print
(
return_null_str
())
print_null_str
(
return_null_str
())
#####
ptr
=
return_unique_ptr
()
print
(
ptr
)
print_opaque_list
(
ptr
)
example/example-opaque-types.ref
deleted
100644 → 0
View file @
bf099587
Opaque list: [Element 1, Element 2]
Back element is Element 2
1/2 : Element 1
2/2 : Element 2
Opaque list: [Element 1]
Opaque list: []
Opaque list: [Element 1, Element 3]
Got void ptr : 0x1234
### ExampleMandA @ 0x2ac5370 created via default constructor
Got void ptr : 0x2ac5370
### ExampleMandA @ 0x2ac5370 destroyed
ExampleMandA still alive: 0
Caught expected exception: Incompatible function arguments. The following argument types are supported:
1. (arg0: capsule) -> None
Invoked with: [1, 2, 3]
None
Got null str : 0x0
<example.StringList object at 0x7f7ecde6fc00>
Opaque list: [some value]
example/example-operator-overloading.py
deleted
100755 → 0
View file @
bf099587
#!/usr/bin/env python
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
from
example
import
Vector2
,
Vector
v1
=
Vector2
(
1
,
2
)
v2
=
Vector
(
3
,
-
1
)
print
(
"v1 = "
+
str
(
v1
))
print
(
"v2 = "
+
str
(
v2
))
print
(
"v1+v2 = "
+
str
(
v1
+
v2
))
print
(
"v1-v2 = "
+
str
(
v1
-
v2
))
print
(
"v1-8 = "
+
str
(
v1
-
8
))
print
(
"v1+8 = "
+
str
(
v1
+
8
))
print
(
"v1*8 = "
+
str
(
v1
*
8
))
print
(
"v1/8 = "
+
str
(
v1
/
8
))
print
(
"8-v1 = "
+
str
(
8
-
v1
))
print
(
"8+v1 = "
+
str
(
8
+
v1
))
print
(
"8*v1 = "
+
str
(
8
*
v1
))
print
(
"8/v1 = "
+
str
(
8
/
v1
))
v1
+=
v2
v1
*=
2
print
(
"(v1+v2)*2 = "
+
str
(
v1
))
from
example
import
ConstructorStats
cstats
=
ConstructorStats
.
get
(
Vector2
)
print
(
"Instances not destroyed:"
,
cstats
.
alive
())
v1
=
None
print
(
"Instances not destroyed:"
,
cstats
.
alive
())
v2
=
None
print
(
"Instances not destroyed:"
,
cstats
.
alive
())
print
(
"Constructor values:"
,
cstats
.
values
())
print
(
"Default constructions:"
,
cstats
.
default_constructions
)
print
(
"Copy constructions:"
,
cstats
.
copy_constructions
)
print
(
"Move constructions:"
,
cstats
.
move_constructions
>=
10
)
print
(
"Copy assignments:"
,
cstats
.
copy_assignments
)
print
(
"Move assignments:"
,
cstats
.
move_assignments
)
example/example-operator-overloading.ref
deleted
100644 → 0
View file @
bf099587
### Vector2 @ 0x11f7830 created [1.000000, 2.000000]
### Vector2 @ 0x11427c0 created [3.000000, -1.000000]
v1 = [1.000000, 2.000000]
v2 = [3.000000, -1.000000]
### Vector2 @ 0x7ffef6b144b8 created [4.000000, 1.000000]
### Vector2 @ 0x11f7e90 created via move constructor
### Vector2 @ 0x7ffef6b144b8 destroyed
### Vector2 @ 0x11f7e90 destroyed
v1+v2 = [4.000000, 1.000000]
### Vector2 @ 0x7ffef6b144b8 created [-2.000000, 3.000000]
### Vector2 @ 0x11f7e90 created via move constructor
### Vector2 @ 0x7ffef6b144b8 destroyed
### Vector2 @ 0x11f7e90 destroyed
v1-v2 = [-2.000000, 3.000000]
### Vector2 @ 0x7ffef6b144c8 created [-7.000000, -6.000000]
### Vector2 @ 0x1115760 created via move constructor
### Vector2 @ 0x7ffef6b144c8 destroyed
### Vector2 @ 0x1115760 destroyed
v1-8 = [-7.000000, -6.000000]
### Vector2 @ 0x7ffef6b144c8 created [9.000000, 10.000000]
### Vector2 @ 0x1115760 created via move constructor
### Vector2 @ 0x7ffef6b144c8 destroyed
### Vector2 @ 0x1115760 destroyed
v1+8 = [9.000000, 10.000000]
### Vector2 @ 0x7ffef6b144b8 created [8.000000, 16.000000]
### Vector2 @ 0x1115760 created via move constructor
### Vector2 @ 0x7ffef6b144b8 destroyed
### Vector2 @ 0x1115760 destroyed
v1*8 = [8.000000, 16.000000]
### Vector2 @ 0x7ffef6b144a8 created [0.125000, 0.250000]
### Vector2 @ 0x112f150 created via move constructor
### Vector2 @ 0x7ffef6b144a8 destroyed
### Vector2 @ 0x112f150 destroyed
v1/8 = [0.125000, 0.250000]
### Vector2 @ 0x7ffef6b144f8 created [7.000000, 6.000000]
### Vector2 @ 0x112f1b0 created via move constructor
### Vector2 @ 0x7ffef6b144f8 destroyed
### Vector2 @ 0x112f1b0 destroyed
8-v1 = [7.000000, 6.000000]
### Vector2 @ 0x7ffef6b144f8 created [9.000000, 10.000000]
### Vector2 @ 0x112f1b0 created via move constructor
### Vector2 @ 0x7ffef6b144f8 destroyed
### Vector2 @ 0x112f1b0 destroyed
8+v1 = [9.000000, 10.000000]
### Vector2 @ 0x7ffef6b144e8 created [8.000000, 16.000000]
### Vector2 @ 0x112f230 created via move constructor
### Vector2 @ 0x7ffef6b144e8 destroyed
### Vector2 @ 0x112f230 destroyed
8*v1 = [8.000000, 16.000000]
### Vector2 @ 0x7ffef6b144d8 created [8.000000, 4.000000]
### Vector2 @ 0x11fb360 created via move constructor
### Vector2 @ 0x7ffef6b144d8 destroyed
### Vector2 @ 0x11fb360 destroyed
8/v1 = [8.000000, 4.000000]
(v1+v2)*2 = [8.000000, 2.000000]
Instances not destroyed: 2
### Vector2 @ 0x11f7830 destroyed
Instances not destroyed: 1
### Vector2 @ 0x11427c0 destroyed
Instances not destroyed: 0
Constructor values: ['[1.000000, 2.000000]', '[3.000000, -1.000000]', '[4.000000, 1.000000]', '[-2.000000, 3.000000]', '[-7.000000, -6.000000]', '[9.000000, 10.000000]', '[8.000000, 16.000000]', '[0.125000, 0.250000]', '[7.000000, 6.000000]', '[9.000000, 10.000000]', '[8.000000, 16.000000]', '[8.000000, 4.000000]']
Default constructions: 0
Copy constructions: 0
Move constructions: True
Copy assignments: 0
Move assignments: 0
example/example-pickling.py
deleted
100644 → 0
View file @
bf099587
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
'.'
)
from
example
import
Pickleable
try
:
import
cPickle
as
pickle
# Use cPickle on Python 2.7
except
ImportError
:
import
pickle
p
=
Pickleable
(
"test_value"
)
p
.
setExtra1
(
15
)
p
.
setExtra2
(
48
)
data
=
pickle
.
dumps
(
p
,
2
)
# Must use pickle protocol >= 2
print
(
"%s %i %i"
%
(
p
.
value
(),
p
.
extra1
(),
p
.
extra2
()))
p2
=
pickle
.
loads
(
data
)
print
(
"%s %i %i"
%
(
p2
.
value
(),
p2
.
extra1
(),
p2
.
extra2
()))
Prev
1
2
3
4
5
6
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment