Commit 06e44270 authored by Stefan Behnel's avatar Stefan Behnel

allow fixed size C array declarations in pure mode

--HG--
extra : amend_source : 49ba7a5625c69a46f550f471dfbd462a5082b27c
parent b702b864
......@@ -34,8 +34,6 @@ def index_type(base_type, item):
a 2D strided array of doubles. The syntax is the same as for
Cython memoryviews.
"""
assert isinstance(item, (tuple, slice))
class InvalidTypeSpecification(Exception):
pass
......@@ -60,9 +58,13 @@ def index_type(base_type, item):
return _ArrayType(base_type, len(item),
is_c_contig=step_idx == len(item) - 1,
is_f_contig=step_idx == 0)
else:
elif isinstance(item, slice):
verify_slice(item)
return _ArrayType(base_type, 1, is_c_contig=bool(item.step))
else:
# int[8] etc.
assert int(item) == item and not isinstance(item, float) # array size must be a plain integer
array(base_type, item)
# END shameless copy
......
......@@ -221,3 +221,19 @@ def cdef_inline(x):
def call_cdef_inline(x):
ret = cdef_inline(x)
return ret, cython.typeof(ret)
@cython.locals(counts=cython.int[10], digit=cython.int)
def count_digits_in_carray(digits):
"""
>>> digits = '37692837651902834128342341'
>>> ''.join(sorted(digits))
'01112222333334445667788899'
>>> count_digits_in_carray(map(int, digits))
[1, 3, 4, 5, 3, 1, 2, 2, 3, 2]
"""
counts = [0] * 10
for digit in digits:
assert 0 <= digit <= 9
counts[digit] += 1
return counts
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