def empty(cls, key_type, value_type): """Create a new empty Dict with *key_type* and *value_type* as the types for the keys and values of the dictionary respectively. """ if config.DISABLE_JIT: return dict() else: return cls(dcttype=DictType(key_type, value_type))
def _assert_record_type(self,typ): if(typ not in self.hist_structs): typ_cls = REGISTERED_TYPES[typ] #Type : (op_id, _hist, shape, arg_types, vmap) struct_typ = self.hist_structs[typ] = Tuple([i8, i8[::1], i8[::1], ListType(unicode_type), DictType(typ_cls,i8)]) self.hists[typ] = self.hists.get(typ,Dict.empty(i8,ListType(struct_typ))) return self.hist_structs[typ]
# else: # s = NULL*(l+1) # for i in range(l): # _set_code_point(s,i,x[i]) # return s[:l] @njit(cache=False) def enumerize_nb_objs(inp, out, enumerize_f, string_enums, number_enums, string_backmap, number_backmap, enum_counter): for k, v in inp.items(): out[k] = enumerize_f(v, string_enums, number_enums, string_backmap, number_backmap, enum_counter) attr_map_i_type = DictType(i8, i8) attr_map_type = DictType(i8, attr_map_i_type) attr_maps_type = DictType(unicode_type, attr_map_type) bool_array = u1[:] elm_present_type = DictType(unicode_type, bool_array) VectInversionData = namedtuple('VectInversionData', [ 'element_names', 'slice_nominal', 'slice_continous', 'width_nominal', 'width_continous', 'attr_records' ]) # NBVectInversionData = NamedTuple([elm_present_type,UniTuple(i8,2),UniTuple(i8,2),i8,i8,attr_map_type],VectInversionData) NBVectInversionData = NamedTuple( [ListType(unicode_type), i8[::1], i8[::1], i8, i8, i8[:, ::1]], VectInversionData) # elm_present_by_type, type_slices_nominal, type_slices_continuous, type_widths_nominal, type_widths_continous, attr_maps_by_type):
def unravel_indicies(indicies, shape): sizes = np.zeros(len(shape), dtype=np.int64) result = np.zeros(len(shape), dtype=np.int64) sizes[-1] = 1 for i in range(len(shape) - 2, -1, -1): sizes[i] = sizes[i + 1] * shape[i + 1] out = np.empty((len(indicies),len(shape)), dtype=np.int64) for j,index in enumerate(indicies): remainder = index for i in range(len(shape)): out[j,i] = remainder // sizes[i] remainder %= sizes[i] return out i8_i8_dict = DictType(i8,i8) i8_arr = i8[:] @njit(nogil=True,fastmath=True,cache=True, locals={"arg_ind":i8[::1],"arg_uids":i8[::1]}) def retrace_back_one(goals, records, u_vds, hist_elems, max_depth, max_solutions=1): unq_arg_inds = Dict.empty(unicode_type, i8_i8_dict) pos_by_typ = Dict.empty(unicode_type, i8) solution_quota = float(max_solutions-len(goals)) if max_solutions else np.inf #Go through each goal in goals, and find applications of operations # which resulted in each subgoal. Add the indicies of args of each # goal satisficing operation application to the set of subgoals for # the next iteration. for goal in goals: n_goal_solutions = 0 hist_elems_k = List.empty_list(HE) hist_elems.append(hist_elems_k)
_x = str(x) _assert_map(_x, enums, backmap, counter) out[i] = enums[_x] return out @njit(cache=False) def enumerize_nb_objs(inp, out, enumerize_f, string_enums, number_enums, string_backmap, number_backmap, enum_counter): for k, v in inp.items(): _assert_map(k, string_enums, string_backmap, enum_counter) out[k] = enumerize_f(v, string_enums, number_enums, string_backmap, number_backmap, enum_counter) attr_map_i_type = DictType(i8, i8) attr_map_type = DictType(i8, attr_map_i_type) attr_maps_type = DictType(unicode_type, attr_map_type) bool_array = u1[:] elm_present_type = DictType(unicode_type, bool_array) VectInversionData = namedtuple('VectInversionData', [ 'element_names', 'slice_nominal', 'slice_continous', 'width_nominal', 'width_continous', 'attr_records' ]) # NBVectInversionData = NamedTuple([elm_present_type,UniTuple(i8,2),UniTuple(i8,2),i8,i8,attr_map_type],VectInversionData) NBVectInversionData = NamedTuple( [ListType(unicode_type), i8[::1], i8[::1], i8, i8, i8[:, ::1]], VectInversionData) # elm_present_by_type, type_slices_nominal, type_slices_continuous, type_widths_nominal, type_widths_continous, attr_maps_by_type):
from .molecule import Molecule array32 = float32[:] @jitclass({ "mols": ListType(Molecule.class_type.instance_type), "sdf_file": string, "ref_chgs_file": string, "emp_chgs_file": string, "num_of_mols": int64, "num_of_ats": int64, "num_of_bonds": int64, "ref_chgs": float32[:], "emp_chgs": float32[:], "emp_ats_types_chgs": DictType(string, float32[:]), "ref_ats_types_chgs": DictType(string, float32[:]), "all_ats_ids": int16[:], "ats_types": ListType(string), "bonds_types": ListType(string) }) class SetOfMolecules: def __init__(self, mols, sdf_file, ats_types, bonds_types): self.mols = mols self.sdf_file = sdf_file self.num_of_mols = len(self.mols) self.num_of_ats = np.sum( np.array([mol.num_of_ats for mol in self.mols], dtype=int64)) self.num_of_bonds = np.sum( np.array([mol.num_of_bonds for mol in self.mols], dtype=int64)) self.ats_types = ats_types # prepsat po fixu
from cre.fact import BaseFact, BaseFactType, cast_fact from cre.utils import lower_setattr, _cast_structref, _meminfo_from_struct, decode_idrec, encode_idrec, \ _pointer_from_struct, _pointer_from_struct_incref, _struct_from_pointer, _decref_pointer from cre.vector import new_vector, VectorType from cre.caching import import_from_cached, source_in_cache, source_to_cache BASE_T_ID_STACK_SIZE = 16 BASE_F_ID_STACK_SIZE = 64 BASE_FACT_SET_SIZE = 64 BASE_CHANGE_QUEUE_SIZE = 2048 #### KB Data Definition #### i8_arr = i8[:] u1_arr = u1[:] str_to_bool_dict = DictType(unicode_type, u1_arr) two_str = UniTuple(unicode_type, 2) two_str_set = DictType(two_str, u1) meminfo_type = types.MemInfoPointer(types.voidptr) basefact_list = ListType(BaseFactType) i8_arr = i8[:] kb_data_fields = [ #Vector<*Vector<*BaseFact>> i.e. 2D vector that holds pointers to facts ("facts", VectorType), #<- will be arr of pointers to vectors #Vector<*Vector<i8>> i.e. 2D vector that holds retracted f_ids ("retracted_f_ids", VectorType), # ("empty_f_id_heads" , i8[:]), ("n_types", i8), ("names_to_idrecs", DictType(unicode_type, u8)),