liveBook · Manning

C int

As explained in Fast Python: High performance techniques for large datasets

C int is a signed integer type whose range and representation are determined by the C implementation.

In Cython, declaring a variable as int gives it a native C type in the generated implementation; without that declaration, the implementation handles it as a Python object. The Python-facing wrapper remains object-based and converts values when calling the typed implementation. section 5.2.3

#cython: language_level=3
 
def add4(my_number):
    i = my_number + 4
    return i
 
def add4_annotated(int my_number):
    cdef int i
    i = my_number + 4
    return i

Compare add4 with add4_annotated to see how declaring int changes the implementation’s parameter and local variable types. section 5.2.3

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Traces int declarations into generated C implementation signatures and contrasts object handling, without detailing C representation or range.
Examples
Compares typed and untyped add4 functions and applies int declarations in an annotated image-processing loop.
What you can do after
Apply it via Cython C-level declarations to reduce Python-object work in numeric code.
How it connects
Connects C int declarations with Cython, Python objects, and generated C code.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.