Example #1
0
 def test_invalid_uses(self):
     with self.assertRaisesRegex(ValueError, "cannot register"):
         structref.register(types.StructRef)
     with self.assertRaisesRegex(ValueError, "cannot register"):
         structref.define_boxing(types.StructRef, MyStruct)
    @property
    def pred_node(self):
        return pterm_get_pred_node(self)


@njit(cach=True)
def pterm_get_str_val(self):
    return self.str_val


@njit(cach=True)
def pterm_get_pred_node(self):
    return self.pred_node


define_boxing(PTermTypeTemplate, PTerm)
PTermType = PTermTypeTemplate(pterm_fields)


@njit(cache=True)
def alpha_pterm_ctor(pn, left_var, op_str, right_var):
    st = new(PTermType)
    st.pred_node = pn
    st.str_val = str(
        left_var
    ) + " " + op_str + " " + "?"  #base_str + "?"#TODO str->float needs to work
    st.var_base_ptrs = (left_var.base_ptr, 0)
    st.negated = False
    st.is_alpha = True
    st.is_linked = False
    return st
Example #3
0
    override_config,
)


@structref.register
class MySimplerStructType(types.StructRef):
    """
    Test associated with this type represent the lowest level uses of structref.
    """
    pass


my_struct_ty = MySimplerStructType(
    fields=[("values", types.intp[:]), ("counter", types.intp)])

structref.define_boxing(MySimplerStructType, structref.StructRefProxy)


class MyStruct(structref.StructRefProxy):
    def __new__(cls, values, counter):
        # Define this method to customize the constructor.
        # The default takes `*args`. Customizing allow the use of keyword-arg.
        # The impl of the method calls `StructRefProxy.__new__`
        return structref.StructRefProxy.__new__(cls, values, counter)

    # The below defines wrappers for attributes and methods manually

    @property
    def values(self):
        return get_values(self)
Example #4
0

@njit(cache=True)
def var_get_deref_attrs(self):
    return self.deref_attrs

@njit(cache=True)
def var_get_alias(self):
    return self.alias

@njit(cache=True)
def var_get_fact_type_name(self):
    return self.fact_type_name

# Manually define the boxing to avoid constructor overloading
define_boxing(VarTypeTemplate,Var)


var_type_cache = {}
def get_var_definition(fact_type, head_type):
    t = (fact_type, head_type)
    if(t not in var_type_cache):
        d = {**var_fields_dict,**{'fact_type':fact_type, 'head_type':head_type}}
        struct_type = VarTypeTemplate([(k,v) for k,v, in d.items()])
        var_type_cache[t] = struct_type
        return struct_type
    else:
        return var_type_cache[t]

@njit(cache=True)
def var_ctor(var_struct_type, fact_type_name, alias):