cge_modeling.base.utilities.variable_dict_to_flat_array#

cge_modeling.base.utilities.variable_dict_to_flat_array(d, variable_list, parameter_list)#

Convert a dictionary of variables and parameters to a single long vector.

Parameters:
d: dict[str, np.ndarray]

Data dictionary mapping variable and parameter names to numpy arrays. Numpy arrays can be any dimension, and are assumed to have dims corresponding to their object’s dims.

variable_list: list[Variable]

List of variables in the model

parameter_list: list[Parameter]

List of parameters in the model

Returns:
variables: np.ndarray

A single long vector containing all variables in the model

parameters: np.ndarray

A single long vector containing all parameters in the model

Notes

This function is the inverse of flat_array_to_variable_dict.

The goal of this pair of functions is to hide flattening and concatenation operations from the user. The user should only have to reason about input and outputs in terms of each individual object, without ever having to worry about unifying them into a single long vector or large matrix.

The ordering of the variables and parameters in the output vector is determined by the order of the variables and parameters in the variable_list and parameter_list arguments. Variables are ordered first, followed by parameters. Multidimensional objects are flattened in row-major order.

# TODO: This function cannot currently handle batch dimensions, but it should be able to.