8000 MATLAB/Python: Add check whether `p_global` is defined, but `global_data` is empty by sandmaennchen · Pull Request #1396 · acados/acados · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MATLAB/Python: Add check whether p_global is defined, but global_data is empty #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions interfaces/acados_matlab_octave/GenerateContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@
global_data_expr_list = cellfun(@(pair) pair{2}, precompute_pairs, 'UniformOutput', false);
self.global_data_expr = cse(vertcat(global_data_expr_list{:}));

% Assert length match
assert(length(self.global_data_expr) == length(self.global_data_sym), ...
sprintf('Length mismatch: %d != %d', length(self.global_data_expr), length(self.global_data_sym)));

if length(self.global_data_expr) == 0
error("The model contains global parameters, but no CasADi function depends on them. This is currently not supported. Please remove p_global from the model definition.")
end

% Add global data as input to all functions
for i = 1:length(self.function_input_output_pairs)
self.function_input_output_pairs{i}{1}{end+1} = self.global_data_sym;
Expand All @@ -197,9 +205,6 @@
% Add function definition
self.add_function_definition(fun_name, {self.p_global}, {self.global_data_expr}, output_dir);

% Assert length match
assert(length(self.global_data_expr) == length(self.global_data_sym), ...
sprintf('Length mismatch: %d != %d', length(self.global_data_expr), length(self.global_data_sym)));
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def __setup_p_global_precompute_fun(self):
self.global_data_sym = ca.vertcat(*global_data_sym_list)
self.global_data_expr = ca.cse(ca.vertcat(*[output for _, output in precompute_pairs]))

assert casadi_length(self.global_data_expr) == casadi_length(self.global_data_sym), f"Length mismatch: {casadi_length(self.global_data_expr)} != {casadi_length(self.global_data_sym)}"

if casadi_length(self.global_data_expr) == 0:
raise Exception("The model contains global parameters, but no CasADi function depends on them. This is currently not supported. Please remove p_global from the model definition.")

# add global data as input to all functions
for i in range(len(self.function_input_output_pairs)):
self.function_input_output_pairs[i][0].append(self.global_data_sym)
Expand All @@ -164,7 +169,6 @@ def __setup_p_global_precompute_fun(self):

# self.print_global_data_summary()

assert casadi_length(self.global_data_expr) == casadi_length(self.global_data_sym), f"Length mismatch: {casadi_length(self.global_data_expr)} != {casadi_length(self.global_data_sym)}"

def finalize(self):
if not is_empty(self.p_global):
Expand Down
Loading
0