Commit 64ad2013 authored by Robert Bradshaw's avatar Robert Bradshaw

Parsing fix, vector test.

parent 2031ca09
...@@ -1853,13 +1853,13 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None): ...@@ -1853,13 +1853,13 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None):
# Make sure this is not a declaration of a variable or function. # Make sure this is not a declaration of a variable or function.
if s.sy == '(': if s.sy == '(':
s.next() s.next()
if s.sy == '*' or s.sy == '**': if s.sy == '*' or s.sy == '**' or s.sy == '&':
s.put_back('(', '(') s.put_back('(', '(')
else: else:
s.put_back('(', '(') s.put_back('(', '(')
s.put_back('IDENT', name) s.put_back('IDENT', name)
name = None name = None
elif s.sy not in ('*', '**', '['): elif s.sy not in ('*', '**', '[', '&'):
s.put_back('IDENT', name) s.put_back('IDENT', name)
name = None name = None
......
from cython.operator cimport dereference as d
cdef extern from "<vector>" namespace "std": cdef extern from "<vector>" namespace "std":
cdef cppclass vector[T]: cdef cppclass vector[T]:
void push_back(T) void push_back(T)
size_t size() size_t size()
T operator[](size_t) T& operator[](size_t)
def simple_test(double x): def simple_test(double x):
""" """
>>> simple_test(55) >>> simple_test(55)
3 3
""" """
cdef vector[double] *v
try: try:
v = new vector[double]() v = new vector[double]()
v.push_back(1.0) v.push_back(1.0)
...@@ -30,7 +31,6 @@ def list_test(L): ...@@ -30,7 +31,6 @@ def list_test(L):
>>> list_test([-1] * 1000) >>> list_test([-1] * 1000)
(1000, 1000) (1000, 1000)
""" """
cdef vector[int] *v
try: try:
v = new vector[int]() v = new vector[int]()
for a in L: for a in L:
...@@ -46,7 +46,6 @@ def index_test(L): ...@@ -46,7 +46,6 @@ def index_test(L):
>>> index_test([1.25]) >>> index_test([1.25])
(1.25, 1.25) (1.25, 1.25)
""" """
cdef vector[double] *v
try: try:
v = new vector[double]() v = new vector[double]()
for a in L: for a in L:
...@@ -54,3 +53,21 @@ def index_test(L): ...@@ -54,3 +53,21 @@ def index_test(L):
return v[0][0], v[0][len(L)-1] return v[0][0], v[0][len(L)-1]
finally: finally:
del v del v
def index_set_test(L):
"""
>>> index_set_test([1,2,4,8])
(-1.0, -8.0)
>>> index_set_test([1.25])
(-1.25, -1.25)
"""
try:
v = new vector[double]()
for a in L:
v.push_back(a)
for i in range(v.size()):
d(v)[i] = -d(v)[i]
return d(v)[0], d(v)[v.size()-1]
finally:
del v
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment