class_docstr: An abstract class for models that implement a model with first
  order information, namely gradient information
  
  Attributes
  ----------
  n_coeffs : `int` (read-only)
      Total number of coefficients of the model
  
  n_calls_loss : `int` (read-only)
      Number of times ``loss`` has been called so far
  
  n_passes_over_data : `int` (read-only)
      Number of effective passes through the data
  
  n_calls_grad : `int` (read-only)
      Number of times ``grad`` has been called so far
  
  n_calls_loss_and_grad : `int` (read-only)
      Number of times ``loss_and_grad`` has been called so far
  
  Notes
  -----
  This class should be not used by end-users, it is intended for
  development only.
class_docstr_tok: ["An","abstract","class","for","models","that","implement","a","model","with","first","order","information",",","namely","gradient","information","Attributes","--","--","--","--","--","n_coeffs",":","`","int","`","(","read-only",")","Total","number","of","coefficients","of","the","model","n_calls_loss",":","`","int","`","(","read-only",")","Number","of","times","``","loss","``","has","been","called","so","far","n_passes_over_data",":","`","int","`","(","read-only",")","Number","of","effective","passes","through","the","data","n_calls_grad",":","`","int","`","(","read-only",")","Number","of","times","``","grad","``","has","been","called","so","far","n_calls_loss_and_grad",":","`","int","`","(","read-only",")","Number","of","times","``","loss_and_grad","``","has","been","called","so","far","Notes","--","--","-","This","class","should","be","not","used","by","end-users",",","it","is","intended","for","development","only","."]
docstr: Computes the gradient of the model at ``coeffs``
  
  Parameters
  ----------
  coeffs : `numpy.ndarray`
      Vector where gradient is computed
  
  out : `numpy.ndarray` or `None`
      If `None` a new vector containing the gradient is returned,
      otherwise, the result is saved in ``out`` and returned
  
  Returns
  -------
  output : `numpy.ndarray`
      The gradient of the model at ``coeffs``
  
  Notes
  -----
  The ``fit`` method must be called to give data to the model,
  before using ``grad``. An error is raised otherwise.
docstr_tok: ["Computes","the","gradient","of","the","model","at","``","coeffs","``","Parameters","--","--","--","--","--","coeffs",":","`","numpy.ndarray","`","Vector","where","gradient","is","computed","out",":","`","numpy.ndarray","`","or","`","None","`","If","`","None","`","a","new","vector","containing","the","gradient","is","returned",",","otherwise",",","the","result","is","saved","in","``","out","``","and","returned","Returns","--","--","--","-","output",":","`","numpy.ndarray","`","The","gradient","of","the","model","at","``","coeffs","``","Notes","--","--","-","The","``","fit","``","method","must","be","called","to","give","data","to","the","model",",","before","using","``","grad","``",".","An","error","is","raised","otherwise","."]
code: def grad(
      self, coeffs: np.ndarray, out: np.ndarray = None
  ) -> np.ndarray:
      """Computes the gradient of the model at ``coeffs``
  
      Parameters
      ----------
      coeffs : `numpy.ndarray`
          Vector where gradient is computed
  
      out : `numpy.ndarray` or `None`
          If `None` a new vector containing the gradient is returned,
          otherwise, the result is saved in ``out`` and returned
  
      Returns
      -------
      output : `numpy.ndarray`
          The gradient of the model at ``coeffs``
  
      Notes
      -----
      The ``fit`` method must be called to give data to the model,
      before using ``grad``. An error is raised otherwise.
      """
      if coeffs.dtype != self.dtype:
          warnings.warn(
              "coeffs vector of type {} has been cast to {}".format(
                  coeffs.dtype, self.dtype
              )
          )
          coeffs = coeffs.astype(self.dtype)
  
      if not self._fitted:
          raise ValueError("call ``fit`` before using ``grad``")
  
      if coeffs.shape[0] != self.n_coeffs:
          raise ValueError(
              (
                  "``coeffs`` has size %i while the model"
                  + " expects %i coefficients"
              )
              % (len(coeffs), self.n_coeffs)
          )
  
      if out is not None:
          grad = out
      else:
          grad = np.empty(self.n_coeffs, dtype=self.dtype)
  
      self._inc_attr(N_CALLS_GRAD)
      self._inc_attr(PASS_OVER_DATA, step=self.pass_per_operation[GRAD])
  
      self._grad(coeffs, out=grad)
      return grad
  
file_path: tick/tick/base_model/model_first_order.py
imports: import warnings
  from abc import abstractmethod
  import numpy
  from .None import Model
  from .model import GRAD, LOSS_AND_GRAD, N_CALLS_GRAD, N_CALLS_LOSS_AND_GRAD, PASS_OVER_DATA, N_CALLS_LOSS
label_desc: Use image node_id 3 for calling the ModelFirstOrder obj's underlying member method code with example usage: obj.grad(coeffs, out) and returns: grad