code: def tanh(self):
      r"""Computes the hyperbolic tangent function using the identity
  
      .. math::
          tanh(x) = 2\sigma(2x) - 1
  
      If a valid method is given, this function will compute tanh using that method:
  
      "chebyshev" - computes tanh via Chebyshev approximation with truncation.
  
      .. math::
          tanh(x) = \sum_{j=1}^terms c_{2j - 1} P_{2j - 1} (x / maxval)
  
      where c_i is the ith Chebyshev series coefficient and P_i is ith polynomial.
      The approximation is truncated to +/-1 outside [-1, 1].
  
      Args:
          terms (int): highest degree of Chebyshev polynomials.
                          Must be even and at least 6.
      """
      method = cfg.functions.sigmoid_tanh_method
  
      if method == "reciprocal":
          return self.mul(2).sigmoid().mul(2).sub(1)
      elif method == "chebyshev":
          terms = cfg.functions.sigmoid_tanh_terms
          coeffs = crypten.common.util.chebyshev_series(
              torch.tanh, 1, terms
          )[1::2]
          tanh_polys = _chebyshev_polynomials(self, terms)
          tanh_polys_flipped = (
              tanh_polys.unsqueeze(dim=-1)
              .transpose(0, -1)
              .squeeze(dim=0)
          )
          out = tanh_polys_flipped.matmul(coeffs)
  
          # truncate outside [-maxval, maxval]
          return out.hardtanh()
      else:
          raise ValueError(f"Unrecognized method {method} for tanh")
  
file_path: CrypTen/crypten/common/functions/approximations.py
imports: import math
  import crypten
  import torch
  from crypten.config import cfg
label_desc: Use image node_id 11 for calling a global function with example usage: tanh() and returns: self, out