code: def _check_grad_measurement_matrices(dM, state_dim, grad_params_no, measurement_dim, which = 'dH'):
          
  
          if dM is None:
              if which == 'dH':
                  dM=np.zeros((measurement_dim ,state_dim,grad_params_no))
              elif  which == 'dR':
                  dM=np.zeros((measurement_dim,measurement_dim,grad_params_no))
          elif isinstance(dM, np.ndarray):
              if state_dim == 1:
                  if len(dM.shape) < 3:
                      dM.shape = (1,1,1)
              else:
                  if len(dM.shape) < 3:
                       if which == 'dH':
                          dM.shape = (measurement_dim,state_dim,1)
                       elif  which == 'dR':
                          dM.shape = (measurement_dim,measurement_dim,1)
          elif isinstance(dM, np.int):
              if state_dim > 1:
                  raise ValueError("When computing likelihood gradient wrong dH dimension.")
              else:
                  dM = np.ones((1,1,1)) * dM
  
  #        if not isinstance(dM, types.FunctionType):
  #            f_dM = lambda k: dM
  #        else:
  #            f_dM = dM
  
          return dM
docs: Function checks (mostly check dimensions) matrices for marginal likelihood
          gradient parameters calculation. It check dH, dR matrices.
  
          Input:
          -------------
              dM: None, scaler or 3D matrix
                  It is supposed to be
                  (measurement_dim ,state_dim,grad_params_no) for "dH" matrix.
                  (measurement_dim,measurement_dim,grad_params_no) for "dR"
  
                  If None then zero matrix is assumed. If scalar then the function
                  checks consistency with "state_dim" and "grad_params_no".
  
              state_dim: int
                  State dimensionality
  
              grad_params_no: int
                  How many parrameters of likelihood gradient in total.
  
              measurement_dim: int
                  Dimensionality of measurements.
  
              which: string
                  'dH' or 'dR'
  
  
          Output:
          --------------
              function of (k) which returns the parameters matrix.