I'm looking at python code working with numba, and have some questions. There is less tutorial on numba, so that I come here to ask.
In numba, data type is pre-declared to help processing. I'm not clear on the rule to declare data type. One example is numba.float64[:,::1]
. I feel it's declaring a 2D array in float type. However, I'm not sure what ::1
means here. Another example is nb.types.NPDatetime('M')[::1]
. Is it slicing the 1D array?
I still have questions on ListType()
, which is imported from numba.types
. Only one element is allowed here? In my code, one class type is saved and passed to ListType()
as single argument. What if I need to explicitly define this class type, and pass it here? Thanks.
I feel there is few tutorial or documents on numba module. If ok, please share some resources on numba. That's very appreciated.
One example is
numba.float64[:,::1]
. I feel it's declaring a 2D array in float type. However, I'm not sure what::1
means here
Exactly. ::1
means that the array axis is contiguous. This enable further optimizations like the use of SIMD instructions.
Another example is
nb.types.NPDatetime('M')[::1]
. Is it slicing the 1D array?
nb.types.NPDatetime('M')
is a Numpy datetime type (where 'M'
is meant to specify the granularity of the datetime. eg. months) here and [::1]
means that this is a 1D contiguous array (containing datetime objects).
One should not be confused between object instances and object types. In Python, this is quite frequent to mix both but this is due to the dynamic nature of the language. Statically-typed compiled languages like C or C++ clearly separate the two concepts and types cannot be manipulated at runtime.
Only one element is allowed here?
ListType
is a class representing the type of a typed list. Its unique parameter defines the type of the item in the resulting type of list. For example nb.types.ListType(nb.types.int32)
returns an object representing the type of a typed list containing 32-bit integers. Note that it is not a list instance. It is meant to be provided to Numba signature or other types.