cge_modeling.base.utilities.flat_array_to_variable_dict#
- cge_modeling.base.utilities.flat_array_to_variable_dict(x, objects, coords)#
Convert a flat array to a dictionary of variables and parameters.
- Parameters:
- x: np.ndarray
Flat array containing all variable and parameters in the model. The ordering is assumed to match the ordering given by list passed to the objects argument, with multidimensional objects flattened in row-major order.
- objects: list[Union[Variable, Parameter]]
List of variables and parameters
- coords: dict[str, list[str]]
Dictionary of coordinates mapping dimension names to lists of labels associated with that dimension.
- Returns:
- d:
dict[str,np.ndarray] Dictionary mapping variable and parameter names to numpy arrays containing the values of those variables and parameters.
- d:
Notes
This function is the inverse of variable_dict_to_flat_array.
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.
Examples