gt4py.cartesian.frontend package
Submodules
gt4py.cartesian.frontend.base module
- class gt4py.cartesian.frontend.base.Frontend[source]
Bases:
abc.ABC
- abstract classmethod generate(definition: Union[gt4py.cartesian.type_hints.StencilFunc, gt4py.cartesian.type_hints.AnnotatedStencilFunc], externals: Dict[str, Any], options: gt4py.cartesian.definitions.BuildOptions) gt4py.cartesian.gtc.gtir.Stencil [source]
Generate a StencilDefinition from a stencil Python function.
- Raises
GTScriptSyntaxError – If there is a parsing error.
GTScriptDefinitionError – If types are misused in the definition.
TypeError – If there is an error in resolving external types.
- abstract classmethod get_stencil_id(qualified_name: str, definition: Union[gt4py.cartesian.type_hints.StencilFunc, gt4py.cartesian.type_hints.AnnotatedStencilFunc], externals: Dict[str, Any], options_id: str) gt4py.cartesian.definitions.StencilID [source]
Create a StencilID object that contains a unique hash for the stencil.
Notes
This method seems to no longer be used through StencilBuilder.
- Returns
An object that contains the qualified name and unique hash.
- Return type
- Raises
GTSyntaxError – If there is a parsing error.
TypeError – If there is a error resolving external types.
- abstract classmethod prepare_stencil_definition(definition: Union[gt4py.cartesian.type_hints.StencilFunc, gt4py.cartesian.type_hints.AnnotatedStencilFunc], externals: Dict[str, Any]) gt4py.cartesian.type_hints.AnnotatedStencilFunc [source]
Annotate the stencil function if not already done so.
- Raises
GTSyntaxError – If there is a parsing error.
TypeError – If there is a error resolving external types.
- gt4py.cartesian.frontend.base.from_name(name: str) Optional[Type[gt4py.cartesian.frontend.base.Frontend]] [source]
Return frontend by name.
- gt4py.cartesian.frontend.base.register(frontend_cls: Type[gt4py.cartesian.frontend.base.Frontend]) None [source]
Register a new frontend.
gt4py.cartesian.frontend.defir_to_gtir module
- class gt4py.cartesian.frontend.defir_to_gtir.DefIRToGTIR[source]
Bases:
gt4py.cartesian.frontend.node_util.IRNodeVisitor
- GT4PY_BUILTIN_TO_GTIR = {<Builtin.TRUE: 1>: <BuiltInLiteral.TRUE: 'true'>, <Builtin.FALSE: 0>: <BuiltInLiteral.FALSE: 'false'>}
- GT4PY_ITERATIONORDER_TO_GTIR_LOOPORDER = {<IterationOrder.BACKWARD: -1>: <LoopOrder.BACKWARD: 'backward'>, <IterationOrder.PARALLEL: 0>: <LoopOrder.PARALLEL: 'parallel'>, <IterationOrder.FORWARD: 1>: <LoopOrder.FORWARD: 'forward'>}
- GT4PY_LEVELMARKER_TO_GTIR_LEVELMARKER = {<LevelMarker.START: 0>: <LevelMarker.START: 'start'>, <LevelMarker.END: -1>: <LevelMarker.END: 'end'>}
- GT4PY_NATIVE_FUNC_TO_GTIR = {<NativeFunction.ABS: 1>: <NativeFunction.ABS: 'abs'>, <NativeFunction.MIN: 2>: <NativeFunction.MIN: 'min'>, <NativeFunction.MAX: 3>: <NativeFunction.MAX: 'max'>, <NativeFunction.MOD: 4>: <NativeFunction.MOD: 'mod'>, <NativeFunction.SIN: 5>: <NativeFunction.SIN: 'sin'>, <NativeFunction.COS: 6>: <NativeFunction.COS: 'cos'>, <NativeFunction.TAN: 7>: <NativeFunction.TAN: 'tan'>, <NativeFunction.ARCSIN: 8>: <NativeFunction.ARCSIN: 'arcsin'>, <NativeFunction.ARCCOS: 9>: <NativeFunction.ARCCOS: 'arccos'>, <NativeFunction.ARCTAN: 10>: <NativeFunction.ARCTAN: 'arctan'>, <NativeFunction.SINH: 11>: <NativeFunction.SINH: 'sinh'>, <NativeFunction.COSH: 12>: <NativeFunction.COSH: 'cosh'>, <NativeFunction.TANH: 13>: <NativeFunction.TANH: 'tanh'>, <NativeFunction.ARCSINH: 14>: <NativeFunction.ARCSINH: 'arcsinh'>, <NativeFunction.ARCCOSH: 15>: <NativeFunction.ARCCOSH: 'arccosh'>, <NativeFunction.ARCTANH: 16>: <NativeFunction.ARCTANH: 'arctanh'>, <NativeFunction.SQRT: 17>: <NativeFunction.SQRT: 'sqrt'>, <NativeFunction.EXP: 18>: <NativeFunction.EXP: 'exp'>, <NativeFunction.LOG: 19>: <NativeFunction.LOG: 'log'>, <NativeFunction.GAMMA: 20>: <NativeFunction.GAMMA: 'gamma'>, <NativeFunction.CBRT: 21>: <NativeFunction.CBRT: 'cbrt'>, <NativeFunction.ISFINITE: 22>: <NativeFunction.ISFINITE: 'isfinite'>, <NativeFunction.ISINF: 23>: <NativeFunction.ISINF: 'isinf'>, <NativeFunction.ISNAN: 24>: <NativeFunction.ISNAN: 'isnan'>, <NativeFunction.FLOOR: 25>: <NativeFunction.FLOOR: 'floor'>, <NativeFunction.CEIL: 26>: <NativeFunction.CEIL: 'ceil'>, <NativeFunction.TRUNC: 27>: <NativeFunction.TRUNC: 'trunc'>}
- GT4PY_OP_TO_GTIR_OP = {<BinaryOperator.ADD: 1>: <ArithmeticOperator.ADD: '+'>, <BinaryOperator.SUB: 2>: <ArithmeticOperator.SUB: '-'>, <BinaryOperator.MUL: 3>: <ArithmeticOperator.MUL: '*'>, <BinaryOperator.DIV: 4>: <ArithmeticOperator.DIV: '/'>, <BinaryOperator.AND: 11>: <LogicalOperator.AND: 'and'>, <BinaryOperator.OR: 12>: <LogicalOperator.OR: 'or'>, <BinaryOperator.EQ: 21>: <ComparisonOperator.EQ: '=='>, <BinaryOperator.NE: 22>: <ComparisonOperator.NE: '!='>, <BinaryOperator.LT: 23>: <ComparisonOperator.LT: '<'>, <BinaryOperator.LE: 24>: <ComparisonOperator.LE: '<='>, <BinaryOperator.GT: 25>: <ComparisonOperator.GT: '>'>, <BinaryOperator.GE: 26>: <ComparisonOperator.GE: '>='>}
- GT4PY_UNARYOP_TO_GTIR = {<UnaryOperator.POS: 1>: <UnaryOperator.POS: '+'>, <UnaryOperator.NEG: 2>: <UnaryOperator.NEG: '-'>, <UnaryOperator.NOT: 11>: <UnaryOperator.NOT: 'not'>}
- transform_offset(offset: Dict[str, Union[int, gt4py.cartesian.frontend.nodes.Expr]], **kwargs: Any) Union[gt4py.cartesian.gtc.common.CartesianOffset, gt4py.cartesian.gtc.gtir.VariableKOffset] [source]
- visit_ArgumentInfo(node: gt4py.cartesian.frontend.nodes.ArgumentInfo, all_params: Dict[str, gt4py.cartesian.gtc.gtir.Decl]) gt4py.cartesian.gtc.gtir.Decl [source]
- visit_Assign(node: gt4py.cartesian.frontend.nodes.Assign) gt4py.cartesian.gtc.gtir.ParAssignStmt [source]
- visit_AxisBound(node: gt4py.cartesian.frontend.nodes.AxisBound) gt4py.cartesian.gtc.common.AxisBound [source]
- visit_AxisInterval(node: gt4py.cartesian.frontend.nodes.AxisInterval) Tuple[gt4py.cartesian.gtc.common.AxisBound, gt4py.cartesian.gtc.common.AxisBound] [source]
- visit_BinOpExpr(node: gt4py.cartesian.frontend.nodes.BinOpExpr) Union[gt4py.cartesian.gtc.gtir.BinaryOp, gt4py.cartesian.gtc.gtir.NativeFuncCall] [source]
- visit_BlockStmt(node: gt4py.cartesian.frontend.nodes.BlockStmt) List[gt4py.cartesian.gtc.gtir.Stmt] [source]
- visit_BuiltinLiteral(node: gt4py.cartesian.frontend.nodes.BuiltinLiteral) gt4py.cartesian.gtc.gtir.Literal [source]
- visit_Cast(node: gt4py.cartesian.frontend.nodes.Cast) gt4py.cartesian.gtc.gtir.Cast [source]
- visit_ComputationBlock(node: gt4py.cartesian.frontend.nodes.ComputationBlock) gt4py.cartesian.gtc.gtir.VerticalLoop [source]
- visit_FieldDecl(node: gt4py.cartesian.frontend.nodes.FieldDecl) gt4py.cartesian.gtc.gtir.FieldDecl [source]
- visit_FieldRef(node: gt4py.cartesian.frontend.nodes.FieldRef) gt4py.cartesian.gtc.gtir.FieldAccess [source]
- visit_HorizontalIf(node: gt4py.cartesian.frontend.nodes.HorizontalIf) gt4py.cartesian.gtc.gtir.FieldIfStmt [source]
- visit_If(node: gt4py.cartesian.frontend.nodes.If) Union[gt4py.cartesian.gtc.gtir.FieldIfStmt, gt4py.cartesian.gtc.gtir.ScalarIfStmt] [source]
- visit_NativeFuncCall(node: gt4py.cartesian.frontend.nodes.NativeFuncCall) gt4py.cartesian.gtc.gtir.NativeFuncCall [source]
- visit_ScalarLiteral(node: gt4py.cartesian.frontend.nodes.ScalarLiteral) gt4py.cartesian.gtc.gtir.Literal [source]
- visit_StencilDefinition(node: gt4py.cartesian.frontend.nodes.StencilDefinition) gt4py.cartesian.gtc.gtir.Stencil [source]
- visit_TernaryOpExpr(node: gt4py.cartesian.frontend.nodes.TernaryOpExpr) gt4py.cartesian.gtc.gtir.TernaryOp [source]
- visit_UnaryOpExpr(node: gt4py.cartesian.frontend.nodes.UnaryOpExpr) gt4py.cartesian.gtc.gtir.UnaryOp [source]
- visit_VarDecl(node: gt4py.cartesian.frontend.nodes.VarDecl) gt4py.cartesian.gtc.gtir.ScalarDecl [source]
- visit_VarRef(node: gt4py.cartesian.frontend.nodes.VarRef, **kwargs)[source]
- visit_While(node: gt4py.cartesian.frontend.nodes.While) gt4py.cartesian.gtc.gtir.While [source]
- class gt4py.cartesian.frontend.defir_to_gtir.UnrollVectorAssignments[source]
Bases:
gt4py.cartesian.frontend.node_util.IRNodeMapper
- visit_Assign(node: gt4py.cartesian.frontend.nodes.Assign, *, fields_decls: Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl], **kwargs) Union[gt4py.cartesian.gtc.gtir.ParAssignStmt, List[gt4py.cartesian.gtc.gtir.ParAssignStmt]] [source]
- visit_StencilDefinition(node: gt4py.cartesian.frontend.nodes.StencilDefinition, *, fields_decls: Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl], **kwargs) gt4py.cartesian.frontend.nodes.StencilDefinition [source]
- class gt4py.cartesian.frontend.defir_to_gtir.UnrollVectorExpressions[source]
Bases:
gt4py.cartesian.frontend.node_util.IRNodeMapper
- classmethod apply(root, *, expected_dim: Tuple[int, ...], fields_decls: Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl])[source]
- visit_BinOpExpr(node: gt4py.cartesian.frontend.nodes.BinOpExpr, *, fields_decls: Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl], **kwargs)[source]
- visit_FieldRef(node: gt4py.cartesian.frontend.nodes.FieldRef, *, fields_decls: Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl], **kwargs)[source]
- visit_UnaryOpExpr(node: gt4py.cartesian.frontend.nodes.UnaryOpExpr, *, fields_decls: Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl], **kwargs)[source]
gt4py.cartesian.frontend.exceptions module
- exception gt4py.cartesian.frontend.exceptions.GTScriptDataTypeError(name, data_type, message=None, *, loc=None)[source]
Bases:
gt4py.cartesian.frontend.exceptions.GTScriptSyntaxError
- exception gt4py.cartesian.frontend.exceptions.GTScriptDefinitionError(name, value, message=None, *, loc=None)[source]
Bases:
gt4py.cartesian.frontend.exceptions.GTScriptSyntaxError
- exception gt4py.cartesian.frontend.exceptions.GTScriptSymbolError(name, message=None, *, loc=None)[source]
Bases:
gt4py.cartesian.frontend.exceptions.GTScriptSyntaxError
- exception gt4py.cartesian.frontend.exceptions.GTScriptValueError(name, value, message=None, *, loc=None)[source]
Bases:
gt4py.cartesian.frontend.exceptions.GTScriptDefinitionError
gt4py.cartesian.frontend.gtscript_frontend module
- class gt4py.cartesian.frontend.gtscript_frontend.AssertionChecker(context: Dict[str, Any], source: str)[source]
Bases:
ast.NodeTransformer
Check assertions and remove from the AST for further parsing.
- class gt4py.cartesian.frontend.gtscript_frontend.AxisIntervalParser(axis_name: str, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.utils.meta.ASTPass
Parse Python AST interval syntax in the form of a Slice.
Corner cases: ast.Ellipsis refers to the entire interval, and if an ast.Subscript is passed, this parses its slice attribute.
- classmethod apply(node: Union[ast.Ellipsis, ast.Slice, ast.Subscript, ast.Constant], axis_name: str, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None) gt4py.cartesian.frontend.nodes.AxisInterval [source]
- static slice_from_value(node: ast.Expr) ast.Slice [source]
Create an ast.Slice node from a general ast.Expr node.
- visit_BinOp(node: ast.BinOp) Union[gt4py.cartesian.gtscript.AxisIndex, gt4py.cartesian.frontend.nodes.AxisBound, int] [source]
- visit_Constant(node: ast.Constant) Optional[Union[int, gt4py.cartesian.gtscript.AxisIndex]] [source]
- visit_Name(node: ast.Name) gt4py.cartesian.frontend.nodes.VarRef [source]
- visit_Subscript(node: ast.Subscript) gt4py.cartesian.frontend.nodes.AxisBound [source]
- visit_UnaryOp(node: ast.UnaryOp) gt4py.cartesian.frontend.nodes.AxisBound [source]
- class gt4py.cartesian.frontend.gtscript_frontend.CallInliner(context: dict, call_stack: Optional[Set[str]] = None)[source]
Bases:
ast.NodeTransformer
Inlines calls to gtscript.function calls.
Calls to NativeFunctions (intrinsic math functions) are kept in the IR and dealt with in the IRMaker.
- __call__(func_node: ast.FunctionDef)[source]
Call self as a function.
- classmethod apply(func_node: ast.FunctionDef, context: dict, *, call_stack: Optional[Set[str]] = None)[source]
- visit_Assert(node: ast.Assert)[source]
- visit_Assign(node: ast.Assign)[source]
- visit_FunctionDef(node: ast.FunctionDef)[source]
- class gt4py.cartesian.frontend.gtscript_frontend.CollectLocalSymbolsAstVisitor[source]
Bases:
ast.NodeVisitor
- __call__(node: ast.FunctionDef)[source]
Call self as a function.
- classmethod apply(node: ast.FunctionDef)[source]
- visit_Assign(node: ast.Assign)[source]
- class gt4py.cartesian.frontend.gtscript_frontend.CompiledIfInliner(context: Dict[str, Any], stencil_name: str)[source]
Bases:
ast.NodeTransformer
- class gt4py.cartesian.frontend.gtscript_frontend.GTScriptFrontend[source]
Bases:
gt4py.cartesian.frontend.base.Frontend
- classmethod generate(definition, externals, options)[source]
Generate a StencilDefinition from a stencil Python function.
- Raises
GTScriptSyntaxError – If there is a parsing error.
GTScriptDefinitionError – If types are misused in the definition.
TypeError – If there is an error in resolving external types.
- classmethod get_stencil_id(qualified_name, definition, externals, options_id)[source]
Create a StencilID object that contains a unique hash for the stencil.
Notes
This method seems to no longer be used through StencilBuilder.
- Returns
An object that contains the qualified name and unique hash.
- Return type
- Raises
GTSyntaxError – If there is a parsing error.
TypeError – If there is a error resolving external types.
- classmethod prepare_stencil_definition(definition, externals)[source]
Annotate the stencil function if not already done so.
- Raises
GTSyntaxError – If there is a parsing error.
TypeError – If there is a error resolving external types.
- class gt4py.cartesian.frontend.gtscript_frontend.GTScriptParser(definition, *, options, externals=None)[source]
Bases:
ast.NodeVisitor
- CONST_VALUE_TYPES = (<class 'bool'>, <class 'numpy.bool_'>, <class 'int'>, <class 'numpy.int8'>, <class 'numpy.int16'>, <class 'numpy.int32'>, <class 'numpy.int64'>, <class 'float'>, <class 'numpy.float32'>, <class 'numpy.float64'>, <class 'function'>, <class 'NoneType'>, <class 'gt4py.cartesian.gtscript.AxisIndex'>, <class 'gt4py.cartesian.gtscript.Axis'>)
- class gt4py.cartesian.frontend.gtscript_frontend.IRMaker(fields: dict, parameters: dict, local_symbols: dict, *, domain: gt4py.cartesian.frontend.nodes.Domain, temp_decls: Optional[Dict[str, gt4py.cartesian.frontend.nodes.FieldDecl]] = None)[source]
Bases:
ast.NodeVisitor
- visit_Add(node: ast.Add) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_And(node: ast.And) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Assign(node: ast.Assign) list [source]
- visit_Attribute(node: ast.Attribute)[source]
- visit_AugAssign(node: ast.AugAssign)[source]
Implement left <op>= right in terms of left = left <op> right.
- visit_BinOp(node: ast.BinOp) gt4py.cartesian.frontend.nodes.BinOpExpr [source]
- visit_BoolOp(node: ast.BoolOp) gt4py.cartesian.frontend.nodes.BinOpExpr [source]
- visit_Compare(node: ast.Compare) gt4py.cartesian.frontend.nodes.BinOpExpr [source]
- visit_Constant(node: ast.Constant) Union[gt4py.cartesian.frontend.nodes.ScalarLiteral, gt4py.cartesian.frontend.nodes.BuiltinLiteral, gt4py.cartesian.frontend.nodes.Cast] [source]
- visit_Div(node: ast.Div) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Eq(node: ast.Eq) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_FunctionDef(node: ast.FunctionDef) List[gt4py.cartesian.frontend.nodes.ComputationBlock] [source]
- visit_Gt(node: ast.Gt) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_GtE(node: ast.GtE) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_IfExp(node: ast.IfExp) gt4py.cartesian.frontend.nodes.TernaryOpExpr [source]
- visit_Lt(node: ast.Lt) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_LtE(node: ast.LtE) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_MatMult(node: ast.MatMult) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Mod(node: ast.Mod) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Mult(node: ast.Mult) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Name(node: ast.Name) gt4py.cartesian.frontend.nodes.Ref [source]
- visit_Not(node: ast.Not) gt4py.cartesian.frontend.nodes.UnaryOperator [source]
- visit_NotEq(node: ast.NotEq) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Or(node: ast.And) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Pow(node: ast.Pow) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Sub(node: ast.Sub) gt4py.cartesian.frontend.nodes.BinaryOperator [source]
- visit_Subscript(node: ast.Subscript)[source]
- visit_UAdd(node: ast.UAdd) gt4py.cartesian.frontend.nodes.UnaryOperator [source]
- visit_USub(node: ast.USub) gt4py.cartesian.frontend.nodes.UnaryOperator [source]
- visit_UnaryOp(node: ast.UnaryOp)[source]
- class gt4py.cartesian.frontend.gtscript_frontend.ParsingContext(value)[source]
Bases:
enum.Enum
An enumeration.
- COMPUTATION = 2
- CONTROL_FLOW = 1
- class gt4py.cartesian.frontend.gtscript_frontend.ReturnReplacer[source]
Bases:
gt4py.cartesian.utils.meta.ASTTransformPass
- classmethod apply(ast_object: ast.AST, target_node: ast.AST) None [source]
Ensure that there is only a single return statement (can still return a tuple).
- visit_Return(node: ast.Return, *, target_node: ast.AST) ast.Assign [source]
- class gt4py.cartesian.frontend.gtscript_frontend.ValueInliner(context)[source]
Bases:
ast.NodeTransformer
- __call__(func_node: ast.FunctionDef)[source]
Call self as a function.
- classmethod apply(func_node: ast.FunctionDef, context: dict)[source]
- visit_Attribute(node: ast.Attribute)[source]
- visit_FunctionDef(node: ast.FunctionDef)[source]
- visit_ImportFrom(node: ast.ImportFrom)[source]
gt4py.cartesian.frontend.node_util module
- class gt4py.cartesian.frontend.node_util.IRNodeMapper[source]
Bases:
object
- generic_visit(node: gt4py.cartesian.frontend.nodes.Node, **kwargs)[source]
- visit(node: gt4py.cartesian.frontend.nodes.Node, **kwargs)[source]
- class gt4py.cartesian.frontend.node_util.IRNodeVisitor[source]
Bases:
object
- generic_visit(node: gt4py.cartesian.frontend.nodes.Node, **kwargs)[source]
- visit(node: gt4py.cartesian.frontend.nodes.Node, **kwargs)[source]
- gt4py.cartesian.frontend.node_util.NOTHING = NOTHING
Marker value used to avoid confusion with None (specially in contexts where None could be a valid value)
- gt4py.cartesian.frontend.node_util.iter_attributes(node: gt4py.cartesian.frontend.nodes.Node)[source]
Yield a tuple of
(attrib_name, value)
for each attribute innode.attributes
that is present on node.
- gt4py.cartesian.frontend.node_util.iter_nodes_of_type(root_node: gt4py.cartesian.frontend.nodes.Node, node_type: Type) Generator[gt4py.cartesian.frontend.nodes.Node, None, None] [source]
Yield an iterator over the nodes of node_type inside root_node in DFS order.
- gt4py.cartesian.frontend.node_util.location_to_source_location(loc: Optional[gt4py.cartesian.frontend.nodes.Location]) Optional[gt4py.eve.concepts.SourceLocation] [source]
gt4py.cartesian.frontend.nodes module
Implementation of the intermediate representations used in GT4Py.
Definitions
- Empty
Empty node value (None is a valid Python value)
- InvalidBranch
Sentinel value for wrongly build conditional expressions
- Builtin enumeration (
Builtin
) Named Python constants [NONE, FALSE, TRUE]
- DataType enumeration (
DataType
) Native numeric data types [INVALID, AUTO, DEFAULT, BOOL, INT8, INT16, INT32, INT64, FLOAT32, FLOAT64]
- UnaryOperator enumeration (
UnaryOperator
) Unary operators [POS, NEG, NOT]
- BinaryOperator enumeration (
BinaryOperator
) Binary operators [ADD, SUB, MUL, DIV, POW, AND, OR, EQ, NE, LT, LE, GT, GE]
- NativeFunction enumeration (
NativeFunction
) Native function identifier [ABS, MAX, MIN, `MOD, SIN, COS, TAN, ARCSIN, ARCCOS, ARCTAN, SQRT, EXP, LOG, ISFINITE, ISINF, ISNAN, FLOOR, CEIL, TRUNC]
- LevelMarker enumeration (
LevelMarker
) Special axis levels [START, END]
- IterationOrder enumeration (
IterationOrder
) Execution order [BACKWARD, PARALLEL, FORWARD]
- Index (
gt4py.definitions.Index
) Multidimensional integer offset [int+]
- Extent (
gt4py.definitions.Extent
) Multidimensional integer extent [(lower: int, upper: int)+]
Definition IR
All nodes have an optional attribute loc [Location(line: int, column: int, scope: str)] storing a reference to the piece of source code which originated the node.
Axis(name: str) Domain(parallel_axes: List[Axis], [sequential_axis: Axis]) # LatLonGrids -> parallel_axes: ["I", "J"], sequential_axis: "K" Literal = ScalarLiteral(value: Any (should match DataType), data_type: DataType) | BuiltinLiteral(value: Builtin) Ref = VarRef(name: str, [index: int]) | FieldRef(name: str, offset: Dict[str, int | Expr]) # Horizontal indices must be ints NativeFuncCall(func: NativeFunction, args: List[Expr], data_type: DataType) Cast(expr: Expr, data_type: DataType) AxisPosition(axis: str, data_type: DataType) AxisIndex(axis: str, endpt: LevelMarker, offset: int, data_type: DataType) Expr = Literal | Ref | NativeFuncCall | Cast | CompositeExpr | InvalidBranch | AxisPosition | AxisIndex CompositeExpr = UnaryOpExpr(op: UnaryOperator, arg: Expr) | BinOpExpr(op: BinaryOperator, lhs: Expr, rhs: Expr) | TernaryOpExpr(condition: Expr, then_expr: Expr, else_expr: Expr) Decl = FieldDecl(name: str, data_type: DataType, axes: List[str], is_api: bool, layout_id: str) | VarDecl(name: str, data_type: DataType, length: int, is_api: bool, [init: Literal]) BlockStmt(stmts: List[Statement]) Statement = Decl | Assign(target: Ref, value: Expr) | If(condition: expr, main_body: BlockStmt, else_body: BlockStmt) | HorizontalIf(intervals: Dict[str, Interval], body: BlockStmt) | While(condition: expr, body: BlockStmt) | BlockStmt AxisBound(level: LevelMarker | VarRef, offset: int) # bound = level + offset # level: LevelMarker = special START or END level # level: VarRef = access to `int` or `[int]` variable holding the run-time value of the level # offset: int AxisInterval(start: AxisBound, end: AxisBound) # start is included # end is excluded ComputationBlock(interval: AxisInterval, iteration_order: IterationOrder, body: BlockStmt) ArgumentInfo(name: str, is_keyword: bool, [default: Any]) StencilDefinition(name: str, domain: Domain, api_signature: List[ArgumentInfo], api_fields: List[FieldDecl], parameters: List[VarDecl], computations: List[ComputationBlock], [externals: Dict[str, Any], sources: Dict[str, str]])
- class gt4py.cartesian.frontend.nodes.ArgumentInfo(*, name: str, is_keyword: bool = False, default: typing.Any = <class 'gt4py.cartesian.frontend.nodes.Empty'>)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.Assign(*, target: gt4py.cartesian.frontend.nodes.Ref, value: gt4py.cartesian.frontend.nodes.Expr, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Statement
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.Axis(*, name: str)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.AxisBound(*, level: gt4py.cartesian.frontend.nodes.LevelMarker, offset: int = 0, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.AxisIndex(*, axis: str, endpt: gt4py.cartesian.frontend.nodes.LevelMarker, offset: int, data_type: gt4py.cartesian.frontend.nodes.DataType = DataType.INT32)[source]
Bases:
gt4py.cartesian.frontend.nodes.Expr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.AxisInterval(*, start: gt4py.cartesian.frontend.nodes.AxisBound, end: gt4py.cartesian.frontend.nodes.AxisBound, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- disjoint_from(other: gt4py.cartesian.frontend.nodes.AxisInterval) bool [source]
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.AxisPosition(*, axis: str, data_type: gt4py.cartesian.frontend.nodes.DataType = DataType.INT32)[source]
Bases:
gt4py.cartesian.frontend.nodes.Expr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.BinOpExpr(*, op: gt4py.cartesian.frontend.nodes.BinaryOperator, lhs: gt4py.cartesian.frontend.nodes.Expr, rhs: gt4py.cartesian.frontend.nodes.Expr, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.CompositeExpr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.BinaryOperator(value)[source]
Bases:
enum.Enum
An enumeration.
- ADD = 1
- AND = 11
- DIV = 4
- EQ = 21
- GE = 26
- GT = 25
- IR_OP_TO_PYTHON_OP = {<BinaryOperator.ADD: 1>: <built-in function add>, <BinaryOperator.SUB: 2>: <built-in function sub>, <BinaryOperator.MUL: 3>: <built-in function mul>, <BinaryOperator.DIV: 4>: <built-in function truediv>, <BinaryOperator.POW: 5>: <built-in function pow>, <BinaryOperator.MOD: 6>: <built-in function mod>, <BinaryOperator.LT: 23>: <built-in function lt>, <BinaryOperator.LE: 24>: <built-in function le>, <BinaryOperator.EQ: 21>: <built-in function eq>, <BinaryOperator.GE: 26>: <built-in function ge>, <BinaryOperator.GT: 25>: <built-in function gt>, <BinaryOperator.NE: 22>: <built-in function ne>}
- IR_OP_TO_PYTHON_SYMBOL = {<BinaryOperator.ADD: 1>: '+', <BinaryOperator.SUB: 2>: '-', <BinaryOperator.MUL: 3>: '*', <BinaryOperator.DIV: 4>: '/', <BinaryOperator.POW: 5>: '**', <BinaryOperator.MOD: 6>: '%', <BinaryOperator.AND: 11>: 'and', <BinaryOperator.OR: 12>: 'or', <BinaryOperator.LT: 23>: '<', <BinaryOperator.LE: 24>: '<=', <BinaryOperator.EQ: 21>: '==', <BinaryOperator.GE: 26>: '>=', <BinaryOperator.GT: 25>: '>', <BinaryOperator.NE: 22>: '!='}
- LE = 24
- LT = 23
- MATMULT = 8
- MOD = 6
- MUL = 3
- NE = 22
- OR = 12
- POW = 5
- SUB = 2
- property python_op
- property python_symbol
- class gt4py.cartesian.frontend.nodes.BlockStmt(*, stmts: List[gt4py.cartesian.frontend.nodes.Statement], loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Statement
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.Builtin(value)[source]
Bases:
enum.Enum
An enumeration.
- FALSE = 0
- NONE = -1
- TRUE = 1
- class gt4py.cartesian.frontend.nodes.BuiltinLiteral(*, value: gt4py.cartesian.frontend.nodes.Builtin, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Literal
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.Cast(*, data_type: gt4py.cartesian.frontend.nodes.DataType, expr: gt4py.cartesian.frontend.nodes.Expr, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Expr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.ComputationBlock(*, interval: gt4py.cartesian.frontend.nodes.AxisInterval, iteration_order: gt4py.cartesian.frontend.nodes.IterationOrder, body: gt4py.cartesian.frontend.nodes.BlockStmt, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.DataType(value)[source]
Bases:
enum.Enum
An enumeration.
- AUTO = 0
- BOOL = 10
- DEFAULT = 1
- FLOAT32 = 104
- FLOAT64 = 108
- INT16 = 12
- INT32 = 14
- INT64 = 18
- INT8 = 11
- INVALID = -1
- NATIVE_TYPE_TO_NUMPY = {<DataType.DEFAULT: 1>: 'float_', <DataType.BOOL: 10>: 'bool', <DataType.INT8: 11>: 'int8', <DataType.INT16: 12>: 'int16', <DataType.INT32: 14>: 'int32', <DataType.INT64: 18>: 'int64', <DataType.FLOAT32: 104>: 'float32', <DataType.FLOAT64: 108>: 'float64'}
- NUMPY_TO_NATIVE_TYPE = {'bool': DataType.BOOL, 'float32': DataType.FLOAT32, 'float64': DataType.FLOAT64, 'float_': DataType.DEFAULT, 'int16': DataType.INT16, 'int32': DataType.INT32, 'int64': DataType.INT64, 'int8': DataType.INT8}
- property dtype
- class gt4py.cartesian.frontend.nodes.Domain(*, parallel_axes: List[gt4py.cartesian.frontend.nodes.Axis], sequential_axis: Optional[gt4py.cartesian.frontend.nodes.Axis] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- property axes
- property axes_names
- property domain_ndims
- property ndims
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.FieldDecl(*, name: str, data_type: gt4py.cartesian.frontend.nodes.DataType, axes: List[str], is_api: bool, data_dims: List[int] = NOTHING, layout_id: str = '_default_', loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Decl
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.FieldRef(*, name: str, offset: Dict[str, Union[int, gt4py.cartesian.frontend.nodes.Expr]], data_index: List[gt4py.cartesian.frontend.nodes.Expr] = NOTHING, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Ref
- classmethod at_center(name: str, axes: Sequence[str], data_index: Optional[List[int]] = None, loc=None)[source]
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.HorizontalIf(*, intervals: Dict[str, gt4py.cartesian.frontend.nodes.AxisInterval], body: gt4py.cartesian.frontend.nodes.BlockStmt)[source]
Bases:
gt4py.cartesian.frontend.nodes.Statement
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.If(*, condition: gt4py.cartesian.frontend.nodes.Expr, main_body: gt4py.cartesian.frontend.nodes.BlockStmt, else_body: Optional[gt4py.cartesian.frontend.nodes.BlockStmt] = None, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Statement
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.IterationOrder(value)[source]
Bases:
enum.Enum
An enumeration.
- BACKWARD = -1
- FORWARD = 1
- PARALLEL = 0
- property symbol
- class gt4py.cartesian.frontend.nodes.LevelMarker(value)[source]
Bases:
enum.Enum
An enumeration.
- END = -1
- START = 0
- class gt4py.cartesian.frontend.nodes.Location(*, line: int, column: int, scope: str = '<source>')[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.NativeFuncCall(*, func: gt4py.cartesian.frontend.nodes.NativeFunction, args: List[gt4py.cartesian.frontend.nodes.Expr], data_type: gt4py.cartesian.frontend.nodes.DataType, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Expr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.NativeFunction(value)[source]
Bases:
enum.Enum
An enumeration.
- ABS = 1
- ARCCOS = 9
- ARCCOSH = 15
- ARCSIN = 8
- ARCSINH = 14
- ARCTAN = 10
- ARCTANH = 16
- CBRT = 21
- CEIL = 26
- COS = 6
- COSH = 12
- EXP = 18
- FLOOR = 25
- GAMMA = 20
- IR_OP_TO_NUM_ARGS = {<NativeFunction.ABS: 1>: 1, <NativeFunction.MIN: 2>: 2, <NativeFunction.MAX: 3>: 2, <NativeFunction.MOD: 4>: 2, <NativeFunction.SIN: 5>: 1, <NativeFunction.COS: 6>: 1, <NativeFunction.TAN: 7>: 1, <NativeFunction.ARCSIN: 8>: 1, <NativeFunction.ARCCOS: 9>: 1, <NativeFunction.ARCTAN: 10>: 1, <NativeFunction.SINH: 11>: 1, <NativeFunction.COSH: 12>: 1, <NativeFunction.TANH: 13>: 1, <NativeFunction.ARCSINH: 14>: 1, <NativeFunction.ARCCOSH: 15>: 1, <NativeFunction.ARCTANH: 16>: 1, <NativeFunction.SQRT: 17>: 1, <NativeFunction.EXP: 18>: 1, <NativeFunction.LOG: 19>: 1, <NativeFunction.GAMMA: 20>: 1, <NativeFunction.CBRT: 21>: 1, <NativeFunction.ISFINITE: 22>: 1, <NativeFunction.ISINF: 23>: 1, <NativeFunction.ISNAN: 24>: 1, <NativeFunction.FLOOR: 25>: 1, <NativeFunction.CEIL: 26>: 1, <NativeFunction.TRUNC: 27>: 1}
- ISFINITE = 22
- ISINF = 23
- ISNAN = 24
- LOG = 19
- MAX = 3
- MIN = 2
- MOD = 4
- SIN = 5
- SINH = 11
- SQRT = 17
- TAN = 7
- TANH = 13
- TRUNC = 27
- property arity
- class gt4py.cartesian.frontend.nodes.ScalarLiteral(*, value: Any, data_type: gt4py.cartesian.frontend.nodes.DataType, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Literal
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.StencilDefinition(*, name: str, domain: gt4py.cartesian.frontend.nodes.Domain, api_signature: List[gt4py.cartesian.frontend.nodes.ArgumentInfo], api_fields: List[gt4py.cartesian.frontend.nodes.FieldDecl], parameters: List[gt4py.cartesian.frontend.nodes.VarDecl], computations: List[gt4py.cartesian.frontend.nodes.ComputationBlock], externals: Optional[Dict[str, Any]] = None, sources: Optional[Dict[str, str]] = None, docstring: str = '', loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Node
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.TernaryOpExpr(*, condition: gt4py.cartesian.frontend.nodes.Expr, then_expr: gt4py.cartesian.frontend.nodes.Expr, else_expr: gt4py.cartesian.frontend.nodes.Expr, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.CompositeExpr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.UnaryOpExpr(*, op: gt4py.cartesian.frontend.nodes.UnaryOperator, arg: gt4py.cartesian.frontend.nodes.Expr, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.CompositeExpr
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.UnaryOperator(value)[source]
Bases:
enum.Enum
An enumeration.
- IR_OP_TO_PYTHON_OP = {<UnaryOperator.POS: 1>: <built-in function pos>, <UnaryOperator.NEG: 2>: <built-in function neg>, <UnaryOperator.NOT: 11>: <built-in function not_>}
- IR_OP_TO_PYTHON_SYMBOL = {<UnaryOperator.POS: 1>: '+', <UnaryOperator.NEG: 2>: '-', <UnaryOperator.NOT: 11>: 'not'}
- NEG = 2
- NOT = 11
- POS = 1
- TRANSPOSED = 5
- property python_op
- property python_symbol
- class gt4py.cartesian.frontend.nodes.VarDecl(*, name: str, data_type: gt4py.cartesian.frontend.nodes.DataType, length: int, is_api: bool, init: Optional[gt4py.cartesian.frontend.nodes.Literal] = None, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Decl
- property is_parameter
- property is_scalar
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.VarRef(*, name: str, index: Optional[int] = None, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Ref
- validate()
Validate this instance’s data attributes.
- class gt4py.cartesian.frontend.nodes.While(*, condition: gt4py.cartesian.frontend.nodes.Expr, body: gt4py.cartesian.frontend.nodes.BlockStmt, loc: Optional[gt4py.cartesian.frontend.nodes.Location] = None)[source]
Bases:
gt4py.cartesian.frontend.nodes.Statement
- validate()
Validate this instance’s data attributes.