def evaluate(self, interpreter_state, args): func_term = args[0] func_type = FuncType(VecType(1), VecType(1)) arg_term = args[1].get() result = np.zeros(self.n) for i in range(self.n): arg_val = VectorTerm(np.array([arg_term[i]])) result_term = interpreter_state.blind_apply( func_term, func_type, arg_val, VecType(1)) result[i] = result_term.get()[0] return VectorTerm(result)
def evaluate(self, interpreter_state, args): func_val = args[0] accum_val = args[1] list_args = args[2].get() unary_func_type = FuncType(VecType(1), VecType(1)) binary_func_type = FuncType(VecType(1), unary_func_type) for i in range(self.n): arg_val = VectorTerm(np.array([list_args[i]])) curry_man = interpreter_state.blind_apply(func_val, binary_func_type, arg_val, VecType(1)) accum_val = interpreter_state.blind_apply(curry_man, unary_func_type, accum_val, VecType(1)) return accum_val
def evaluate(self, interpreter_state, args): first_func = args[1] first_func_type = FuncType(VecType(self.n), VecType(self.m)) second_func = args[0] second_func_type = FuncType(VecType(self.m), VecType(self.p)) arg_value = args[2] arg_type = VecType(self.n) middle_value = interpreter_state.blind_apply(first_func, first_func_type, arg_value, arg_type) middle_type = VecType(self.m) return interpreter_state.blind_apply(second_func, second_func_type, middle_value, middle_type)
def required_arg_types(self): return [ FuncType(VecType(self.m), VecType(self.p)), FuncType(VecType(self.n), VecType(self.m)), VecType(self.n) ]
def ret_type(self): return VecType(self.n)
def required_arg_types(self): return [VecType(self.n), VecType(self.m)]
def required_arg_types(self): return [FuncType(VecType(1), VecType(1)), VecType(self.n)]
def required_arg_types(self): return [VecType(1)]
def get_compose_type(n, m, p): return FuncType( FuncType(VecType(m), VecType(p)), FuncType(FuncType(VecType(n), VecType(m)), FuncType(VecType(n), VecType(p))))
term_app = TermApplication(func_ptr, arg_ptr) result_ptr = func_table.evaluate(self, term_app) return result_ptr def blind_apply(self, func_val, func_type, arg_val, arg_type): func_space = self.get_type_space(func_type) arg_space = self.get_type_space(arg_type) func_ptr = func_space.get_pointer(func_val) arg_ptr = arg_space.get_pointer(arg_val) result_ptr = self.apply_ptrs(func_ptr, arg_ptr) return result_ptr.get_term() DIM = 10 scalar_t = VecType(1) vector_t = VecType(DIM) unary_vec_func_t = FuncType(vector_t, vector_t) binary_vec_func_t = FuncType(vector_t, unary_vec_func_t) unary_scalar_func_t = FuncType(scalar_t, scalar_t) binary_scalar_func_t = FuncType(scalar_t, unary_scalar_func_t) map_func_t = FuncType(unary_scalar_func_t, unary_vec_func_t) vector_to_scalar_func_t = FuncType(vector_t, scalar_t) reduce_func_t = FuncType(binary_scalar_func_t, FuncType(scalar_t, vector_to_scalar_func_t)) fill_func_t = FuncType(scalar_t, vector_t) interpreter_state = InterpreterState() interpreter_state.add_type(map_func_t) interpreter_state.add_type(fill_func_t)