def _make(subClass, coreInfo, styles, subExpressions): if subClass != ExprTuple: MakeNotImplemented(subClass) if len(coreInfo) != 1 or coreInfo[0] != 'ExprTuple': raise ValueError("Expecting ExprTuple coreInfo to contain " "exactly one item: 'ExprTuple'") return ExprTuple(*subExpressions).withStyles(**styles)
def _make(subClass, coreInfo, styles, subExpressions): if subClass != Iter: MakeNotImplemented(subClass) if len(coreInfo) != 1 or coreInfo[0] != 'Iter': raise ValueError( "Expecting Iter coreInfo to contain exactly one item: 'Iter'") return Iter(*subExpressions).withStyles(**styles)
def _make(sub_class, core_info, sub_expressions, *, styles): if sub_class != IndexedVar: MakeNotImplemented(sub_class) if len(core_info) != 1 or core_info[0] != 'IndexedVar': raise ValueError( "Expecting IndexedVar core_info to contain exactly" " one item: 'IndexedVar'") return IndexedVar(*sub_expressions, styles=styles)
def _make(sub_class, core_info, sub_expressions, *, styles): if sub_class != ExprArray: raise MakeNotImplemented(sub_class) if len(core_info) != 1 or core_info[0] != 'ExprTuple': raise ValueError("An ExprArray is an ExprTuple of ExprTuples, " "so the ExprArray core_info should contain " "exactly one item: 'ExprTuple'") return ExprArray(*sub_expressions, styles=styles)
def _make(subClass, coreInfo, styles, subExpressions): if subClass != NamedExprs: MakeNotImplemented(subClass) if coreInfo[0] != 'NamedExprs': raise ValueError("Expecting NamedExprs coreInfo[0] to be 'NamedExprs'") keys = coreInfo[1:] if len(subExpressions) != len(keys): raise ValueError("The number of sub-expressions, " + str(len(subExpressions)), ", expected to match the number of the NamedExprs' keys, ", str(len(keys))) return NamedExprs([(key,subExpression) for key, subExpression in zip(keys, subExpressions)]).withStyles(**styles)
def _make(subClass, coreInfo, styles, subExpressions): if len(coreInfo) != 1 or coreInfo[0] != 'Lambda': raise ValueError( "Expecting Lambda coreInfo to contain exactly one item: 'Lambda'" ) if subClass != Lambda: raise MakeNotImplemented(subClass) parameters, body, conditions = subExpressions return Lambda(parameters, body, conditions).withStyles(**styles)
def _make(sub_class, core_info, sub_expressions): if len(core_info) != 1 or core_info[0] != 'Conditional': raise ValueError( "Expecting Conditional core_info to contain exactly " ":one item: 'Conditional'") if sub_class != Conditional: raise MakeNotImplemented(sub_class) if len(sub_expressions) != 2: raise ValueError( "Expecting Conditional to have two sub-expressions.") value, condition = sub_expressions return Conditional(value, condition)
def _make(subClass, coreInfo, styles, subExpressions): if subClass != Indexed: MakeNotImplemented(subClass) if len(coreInfo) != 2 or coreInfo[0] != 'Indexed': raise ValueError( "Expecting Indexed coreInfo to contain exactly two items: 'Indexed' and the integer 'base'" ) try: base = int(coreInfo[1]) except: raise ValueError("Expecting 'base' to be an integer") return Indexed(*subExpressions, base=base).withStyles(**styles)
def _make(subClass, coreInfo, styles, subExpressions): if subClass != ExprArray: MakeNotImplemented(subClass) if len(coreInfo) != 3: raise ValueError("Expecting ExprArray coreInfo to contain exactly 3 items: 'ExprArray', the number of dimensions, and the indexed locations") if coreInfo[0] != 'ExprArray': raise ValueError("Expecting ExprArray coreInfo[0] to be 'ExprArray'") ndims = literal_eval(coreInfo[1]) indexed_loc_strs = coreInfo[2].split(';') # coordinate-sorting relations in each dimension sorting_relations = subExpressions[:ndims] indexed_tensor = {literal_eval(indexed_loc_str):element for indexed_loc_str, element in zip(indexed_loc_strs, subExpressions[ndims+1:])} tensor = {ExprArray.tensorLocation(indexed_loc, sorting_relations):element for indexed_loc, element in indexed_tensor.items()} return ExprArray(tensor).withStyles(**styles)
def _make(subClass, coreInfo, styles, subExpressions, genericExpr=None): if len(coreInfo) != 1 or coreInfo[0] != 'Lambda': raise ValueError( "Expecting Lambda coreInfo to contain exactly one item: 'Lambda'" ) if subClass != Lambda: raise MakeNotImplemented(subClass) if len(subExpressions) == 3: parameters, body, conditions = subExpressions else: parameters, body = subExpressions conditions = tuple() return Lambda(parameters, body, conditions, _generic_expr=genericExpr).withStyles(**styles)
def _make(sub_class, core_info, sub_expressions): if sub_class != NamedExprs: MakeNotImplemented(sub_class) if core_info[0] != 'NamedExprs': raise ValueError( "Expecting NamedExprs core_info[0] to be 'NamedExprs'") keys = [key.replace(':', ',') for key in core_info[1:]] if len(sub_expressions) != len(keys): raise ValueError( "The number of sub-expressions, " + str(len(sub_expressions)), ", expected to match the number of the NamedExprs' keys, ", str(len(keys))) return NamedExprs([ (key, sub_expression) for key, sub_expression in zip(keys, sub_expressions) ])