Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are all the types available in Cython?

During a Cython meetup a speaker pointed to other data types such as cython.ssize_t. The type ssize_t is briefly mentioned in this Wikipedia article however it is not well explained. Similarly Cython documentation mentions types in terms of how types are automatically converted.

What are all the data types available in Cython and what are their specifications?

like image 952
Greg Avatar asked Apr 01 '19 09:04

Greg


1 Answers

You have basically access to most of the C types:

Here are the equivalent of all the Python types (if I do not miss some), taken from Oreilly book cython book

Python bool:

  • bint (boolean coded on 4 bits, alias for short)

Python int and long

  • [unsigned] char
  • [unsigned] short
  • [unsigned] int
  • [unsigned] long
  • [unsigned] long long

Python float

  • float
  • double
  • long double

Python complex

  • float complex
  • double complex

Python bytes / str / unicode

  • char *
  • std::string

For the size_t and Py_ssite_t, keep in mind these are aliases.

Py_ssize_t is defined in python.h imported implicitly in cython. That can hold the size (in bytes) of the largest object the Python interpreter ever creates.

While size_t is a standard C89 type, defined in <stddef.h>.

like image 172
BlueSheepToken Avatar answered Sep 28 '22 09:09

BlueSheepToken