Manual
Ops & Types
The op decorator is available through from pypie import op. op marks a Python function, so PyPie may validate its type and parallelize its execution.
Static typing
The definition must annotate the type of each argument and the result. PyPie validates the function definition using these annotations, and gives errors if validation fails.
Supported types
PyPie provides Tensor and common scalar types, such as float32 and bf32.
PyPie supports Python Lists, Tuples, and Classes, if their elements are recursively supported.
Implicit variables
PyPie infers the type of implicit variables, e.g. [T, n]. Here, T is a type and n is an int64. Optionally, you may annotate the variables that are int64s, e.g. [T, n: int64].
PyPie rejects other annotations for implicits given by users.
from pypie import Tensor, op @op def plus[T, n](x: Tensor[T][[n]], y: Tensor[T][[n]]) -> Tensor[T][[n]]: return x + y
Strict conversions
PyPie does not implicitly convert datatypes. E.g. the followings trigger type errors.
from pypie import op @op def x_is_not_y[X, Y](x: X, y: Y) -> X: # `X` != `Y` return x + y @op def x_is_not_float[X](x: X, y: float32) -> float32: # `X` != `float32` return x + y @op def f32_is_not_f16[X](x: float32, y: float16) -> float32: # `float32` != `float16` return x + y
They need explicit casts.
from pypie import op @op def cast_y[X, Y](x: X, y: Y) -> X: return x + y.cast(X) @op def cast_to_float[X](x: X, y: float32) -> float32: return x.cast(float32) + y @op def cast_bits[X](x: float32, y: float16) -> float32: return x + y.cast(float32)
Flexible literals
Literals do not need casts. E.g. PyPie is happy with the following.
from pypie import op @op def literal_is_flexible[X](x: X) -> X: return x + 0.1