From ac7320c44a7836f67933952c66c8f9622ff67605 Mon Sep 17 00:00:00 2001 From: maximilianschaller <79449026+maxschaller@users.noreply.github.com> Date: Sun, 21 Apr 2024 16:07:03 -0700 Subject: [PATCH] Simplified function calls. --- cvxpygen/solvers.py | 6 +----- cvxpygen/utils.py | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cvxpygen/solvers.py b/cvxpygen/solvers.py index ad29075..5c747f4 100644 --- a/cvxpygen/solvers.py +++ b/cvxpygen/solvers.py @@ -721,11 +721,7 @@ def __init__(self, data, p_prob, enable_settings): ), 'AbcGh': ParameterUpdateLogic( update_pending_logic=UpdatePendingLogic(['A', 'b', 'G'], '||', ['c', 'h']), - function_call=f'{{prefix}}cpg_copy_A();\n' - f' {{prefix}}cpg_copy_b();\n' - f' {{prefix}}cpg_copy_c();\n' - f' {{prefix}}cpg_copy_G();\n' - f' {{prefix}}cpg_copy_h();\n' + function_call=f'{{prefix}}cpg_copy_all();\n' f' ECOS_updateData({{prefix}}ecos_workspace, {{prefix}}Canon_Params_conditioning.G->x, {"0" if canon_constants["p"] == 0 else "{prefix}Canon_Params_conditioning.A->x"}' f', {{prefix}}Canon_Params_conditioning.c, {{prefix}}Canon_Params_conditioning.h, {"0" if canon_constants["p"] == 0 else "{prefix}Canon_Params_conditioning.b"})' ), diff --git a/cvxpygen/utils.py b/cvxpygen/utils.py index 50bc226..3a9b931 100644 --- a/cvxpygen/utils.py +++ b/cvxpygen/utils.py @@ -849,20 +849,22 @@ def write_solve_def(f, configuration, variable_info, dual_variable_info, paramet if solver_interface.inmemory_preconditioning: f.write('// Copy canonical parameters for preconditioning\n') for p_id, size in parameter_canon.p_id_to_size.items(): - f.write(f'void {configuration.prefix}cpg_copy_{p_id}(){{\n') - if size == 1: - f.write(f' {configuration.prefix}Canon_Params_conditioning.{p_id} = {configuration.prefix}Canon_Params.{p_id};\n') - elif size > 1: - f.write(f' for (i=0; i<{size}; i++){{\n') - if p_id.isupper(): - f.write(f' {configuration.prefix}Canon_Params_conditioning.{p_id}->x[i] = {configuration.prefix}Canon_Params.{p_id}->x[i];\n') - else: - f.write(f' {configuration.prefix}Canon_Params_conditioning.{p_id}[i] = {configuration.prefix}Canon_Params.{p_id}[i];\n') - f.write(' }\n') - f.write('}\n\n') + if p_id != 'd': + f.write(f'void {configuration.prefix}cpg_copy_{p_id}(){{\n') + if size == 1: + f.write(f' {configuration.prefix}Canon_Params_conditioning.{p_id} = {configuration.prefix}Canon_Params.{p_id};\n') + elif size > 1: + f.write(f' for (i=0; i<{size}; i++){{\n') + if p_id.isupper(): + f.write(f' {configuration.prefix}Canon_Params_conditioning.{p_id}->x[i] = {configuration.prefix}Canon_Params.{p_id}->x[i];\n') + else: + f.write(f' {configuration.prefix}Canon_Params_conditioning.{p_id}[i] = {configuration.prefix}Canon_Params.{p_id}[i];\n') + f.write(' }\n') + f.write('}\n\n') f.write(f'void {configuration.prefix}cpg_copy_all(){{\n') for p_id in parameter_canon.p.keys(): - f.write(f' {configuration.prefix}cpg_copy_{p_id}();\n') + if p_id != 'd': + f.write(f' {configuration.prefix}cpg_copy_{p_id}();\n') f.write('}\n\n') f.write('// Solve via canonicalization, canonical solve, retrieval\n') @@ -947,6 +949,13 @@ def write_solve_prot(f, configuration, variable_info, dual_variable_info, parame f.write('\n// Retrieve solver information\n') f.write(f'extern void {configuration.prefix}cpg_retrieve_info();\n') + if solver_interface.inmemory_preconditioning: + f.write('\n// Copy canonical parameters for preconditioning\n') + for p_id in parameter_canon.p_id_to_size.keys(): + if p_id != 'd': + f.write(f'extern void {configuration.prefix}cpg_copy_{p_id}();\n') + f.write(f'extern void {configuration.prefix}cpg_copy_all();\n') + f.write('\n// Solve via canonicalization, canonical solve, retrieval\n') f.write(f'extern void {configuration.prefix}cpg_solve();\n')