code: def test_derivatives(self):
      pen = self.pen
      x = self.params
  
      ps = np.array([pen.deriv(np.atleast_1d(xi)) for xi in x])
      psn = np.array(
          [approx_fprime(np.atleast_1d(xi), pen.func) for xi in x]
      )
      assert_allclose(ps, psn, rtol=1e-7, atol=1e-8)
  
      ph = np.array([pen.deriv2(np.atleast_1d(xi)) for xi in x])
      phn = np.array(
          [approx_hess(np.atleast_1d(xi), pen.func) for xi in x]
      )
      if ph.ndim == 2:
          # SmoothedSCAD returns only diagonal if hessian if independent
          # TODO should ww allow this also in L@?
          ph = np.array([np.diag(phi) for phi in ph])
      assert_allclose(ph, phn, rtol=1e-7, atol=1e-8)
  
imports: import numpy
  from numpy.testing import assert_allclose, assert_equal
  import statsmodels.base._penalties
  from statsmodels.tools.numdiff import approx_fprime, approx_hess
label_desc: Use image node_id 2 for calling the CheckPenalty obj's underlying member method code with example usage: obj.test_derivatives() without return types