code: def _compute_partials(
      samples, concentration, rate, log_rate, log_space
  ):
      """Shared partials between forward and reverse mode."""
      if log_space:
          # The function is log(gamma_sample(conc, rate, log_rate)).
          # So:
          # d log(gamma_sample(..)) / d conc
          #   = (d gamma_sample(..) / d conc) / gamma_sample(..)
          # d log(gamma_sample(..)) / d rate
          #   = d log(gamma_sample(.., rate=1) / rate) / d rate
          #   = d (log(gamma_sample(.., rate=1)) - log(rate)) / d rate
          #   = d (-log(rate)) / d rate
          #   = - 1. / rate
          # d log(gamma_sample(..)) / d log_rate
          #   = d (log(gamma_sample(.., rate=1)) - log_rate) / d log_rate
          #   = d (- log_rate) / d log_rate
          #   = -1.
          partial_rate = 0.0
          partial_log_rate = 0.0
          if log_rate is not None:
              exp_samples_rate = tf.math.exp(samples + log_rate)
              partial_log_rate = -1.0
          elif rate is not None:
              exp_samples_rate = tf.math.exp(samples) * rate
              partial_rate = -1.0 / rate
          else:
              exp_samples_rate = tf.math.exp(samples)
          partial_concentration = (
              tf.raw_ops.RandomGammaGrad(
                  alpha=concentration, sample=exp_samples_rate
              )
              / exp_samples_rate
          )
  
      else:
          partial_rate = 0.0
          partial_log_rate = 0.0
          if log_rate is not None:
              # d gamma_sample(exp(log_rate)) / d log_rate
              #   = d gamma_sample(rate) / d rate * d exp(log_rate) / d log_rate
              #   = d gamma_sample(rate) / d rate * exp(log_rate)
              #   = d gamma_sample(rate) / d rate * rate
              # Note that d gamma_sample(rate) / d rate = -gamma_sample(rate) / rate
              # So d gamma_sample(exp(log_rate)) / d log_rate = -gamma_sample(rate)
              rate = tf.math.exp(log_rate)
              partial_log_rate = -samples
          elif rate is not None:
              partial_rate = -samples / rate
          else:
              rate = 1.0
          partial_concentration = (
              tf.raw_ops.RandomGammaGrad(
                  alpha=concentration, sample=samples * rate
              )
              / rate
          )
  
      return partial_concentration, partial_rate, partial_log_rate
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import batched_rejection_sampler
  from tensorflow_probability.python.internal import custom_gradient
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import implementation_selection
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math import generic
  from tensorflow_probability.python.math import special
  from tensorflow_probability.python.util.deferred_tensor import DeferredTensor
label_desc: Use image node_id 7 for calling a global function with example usage: _compute_partials(samples, concentration, rate, log_rate, log_space) and returns: partial_concentration,  partial_rate,  partial_log_rate