pyepo.utils

Package-wide utility functions

Functions

objective_offset(→ float)

Bare objective constant of a compiled DSL problem.

costToNumpy(→ numpy.ndarray)

Normalize a cost vector to a numpy array, detaching torch tensors as needed.

Module Contents

pyepo.utils.objective_offset(model: pyepo.model.opt.optModel) float

Bare objective constant of a compiled DSL problem.

Parameters:

model – optimization model

Returns:

objective constant, 0.0 for models without one

Return type:

float

pyepo.utils.costToNumpy(c: numpy.ndarray | torch.Tensor | list, dtype: Any = np.float32) numpy.ndarray

Normalize a cost vector to a numpy array, detaching torch tensors as needed.

Parameters:
  • c – cost vector

  • dtype – target dtype when c is not already a tensor; torch tensors are converted via .detach().cpu().numpy() and keep their existing dtype.

Returns:

numpy cost vector

Return type:

np.ndarray