CUTEstProblem.sgrad

CUTEstProblem.sgrad(x, index=None)

Evaluate the sparse gradient of the objective function or sparse gradient of the i-th constraint.

# gradient of objective
g = problem.grad(x)
# gradient of i-th constraint
g = problem.grad(x, index=i)

The vector g is of type scipy.sparse.coo_matrix. For unconstrained problems, g is formed from a dense matrix due to CUTEst limitations.

For small problems, problem.grad returns dense matrices.

This calls CUTEst routine CUTEst_ugr or CUTEST_cisgr.

Parameters:
  • x (numpy.ndarray with shape (n,)) – input vector

  • index (int, optional) – which constraint to evaluate. Must be in 0..self.m-1.

Returns:

sparse gradient of objective or sparse gradient of i-th constraint at x

Return type:

scipy.sparse.coo_matrix(n,)