class_docstr: Piecewise linear distribution.
  
  This class represents the *quantile function* (i.e., the inverse CDF)
  associated with the a distribution, as a continuous, non-decreasing,
  piecewise linear function defined in the [0, 1] interval:
  
  .. math::
      q(x; \gamma, b, d) = \gamma + \sum_{l=0}^L b_l (x_l - d_l)_+
  
  where the input :math:`x \in [0,1]` and the parameters are
  
  - :math:`\gamma`: intercept at 0
  - :math:`b`: differences of the slopes in consecutive pieces
  - :math:`d`: knot positions
  
  Parameters
  ----------
  gamma
      Tensor containing the intercepts at zero
  slopes
      Tensor containing the slopes of each linear piece.
      All coefficients must be positive.
      Shape: ``(*gamma.shape, num_pieces)``
  knot_spacings
      Tensor containing the spacings between knots in the splines.
      All coefficients must be positive and sum to one on the last axis.
      Shape: ``(*gamma.shape, num_pieces)``
  F
class_docstr_tok: ["Piecewise","linear","distribution",".","This","class","represents","the","*","quantile","function","*","(","i.e.",",","the","inverse","CDF",")","associated","with","the","a","distribution",",","as","a","continuous",",","non-decreasing",",","piecewise","linear","function","defined","in","the","[","0",",","1","]","interval",":","..","math",":",":","q","(","x",";","\\gamma",",","b",",","d",")","=","\\gamma","+","\\sum_","{","l=0","}","^L","b_l","(","x_l","-","d_l",")","_+","where","the","input",":","math",":","`","x","\\in","[","0,1","]","`","and","the","parameters","are","-",":","math",":","`","\\gamma","`",":","intercept","at","0","-",":","math",":","`","b","`",":","differences","of","the","slopes","in","consecutive","pieces","-",":","math",":","`","d","`",":","knot","positions","Parameters","--","--","--","--","--","gamma","Tensor","containing","the","intercepts","at","zero","slopes","Tensor","containing","the","slopes","of","each","linear","piece",".","All","coefficients","must","be","positive",".","Shape",":","``","(","*","gamma.shape",",","num_pieces",")","``","knot_spacings","Tensor","containing","the","spacings","between","knots","in","the","splines",".","All","coefficients","must","be","positive","and","sum","to","one","on","the","last","axis",".","Shape",":","``","(","*","gamma.shape",",","num_pieces",")","``","F"]
docstr: Evaluates the quantile function at the quantile levels contained in
  `x`.
  
  Parameters
  ----------
  x
      Tensor of shape ``*gamma.shape`` if axis=None, or containing an
      additional axis on the specified position, otherwise.
  axis
      Index of the axis containing the different quantile levels which
      are to be computed.
  
  Returns
  -------
  Tensor
      Quantiles tensor, of the same shape as x.
docstr_tok: ["Evaluates","the","quantile","function","at","the","quantile","levels","contained","in","`","x","`",".","Parameters","--","--","--","--","--","x","Tensor","of","shape","``","*","gamma.shape","``","if","axis=None",",","or","containing","an","additional","axis","on","the","specified","position",",","otherwise",".","axis","Index","of","the","axis","containing","the","different","quantile","levels","which","are","to","be","computed",".","Returns","--","--","--","-","Tensor","Quantiles","tensor",",","of","the","same","shape","as","x","."]
code: def quantile_internal(
      self, x: Tensor, axis: Optional[int] = None
  ) -> Tensor:
      r"""
      Evaluates the quantile function at the quantile levels contained in
      `x`.
  
      Parameters
      ----------
      x
          Tensor of shape ``*gamma.shape`` if axis=None, or containing an
          additional axis on the specified position, otherwise.
      axis
          Index of the axis containing the different quantile levels which
          are to be computed.
  
      Returns
      -------
      Tensor
          Quantiles tensor, of the same shape as x.
      """
  
      F = self.F
  
      # shapes of self
      # self.gamma: (*batch_shape)
      # self.knot_positions, self.b: (*batch_shape, num_pieces)
  
      # axis=None - passed at inference when num_samples is None
      # The shape of x is (*batch_shape).
      # The shapes of the parameters should be:
      # gamma: (*batch_shape), knot_positions, b: (*batch_shape, num_pieces)
      # They match the self. counterparts so no reshaping is needed
  
      # axis=0 - passed at inference when num_samples is not None
      # The shape of x is (num_samples, *batch_shape).
      # The shapes of the parameters should be:
      # gamma: (num_samples, *batch_shape), knot_positions, b:
      # (num_samples, *batch_shape, num_pieces), They do not match the self.
      # counterparts and we need to expand the axis=0 to all of them.
  
      # axis=-2 - passed at training when we evaluate quantiles at
      # knot_positions in order to compute a_tilde
      # The shape of x is shape(x) = shape(knot_positions) =
      # (*batch_shape, num_pieces).
      # The shape of the parameters shopuld be:
      # gamma: (*batch_shape, 1), knot_positions: (*batch_shape, 1,
      # num_pieces), b: (*batch_shape, 1, num_pieces) They do not match the
      # self. counterparts and we need to expand axis=-1 for gamma and
      # axis=-2 for the rest.
  
      if axis is not None:
          gamma = self.gamma.expand_dims(axis=axis if axis == 0 else -1)
          knot_positions = self.knot_positions.expand_dims(axis=axis)
          b = self.b.expand_dims(axis=axis)
      else:
          gamma, knot_positions, b = (
              self.gamma,
              self.knot_positions,
              self.b,
          )
  
      x_minus_knots = F.broadcast_minus(
          x.expand_dims(axis=-1), knot_positions
      )
  
      quantile = F.broadcast_add(
          gamma,
          F.sum(F.broadcast_mul(b, F.relu(x_minus_knots)), axis=-1),
      )
  
      return quantile
  
imports: from typing import Dict, List, Optional, Tuple, Union, cast
  import mxnet
  import numpy
  from gluonts.core.component import validated
  from gluonts.mx import Tensor
  from gluonts.mx.util import cumsum
  from .bijection import AffineTransformation, Bijection
  from .distribution import Distribution, getF
  from .distribution_output import ArgProj, DistributionOutput
  from .transformed_distribution import TransformedDistribution
label_desc: Use image node_id 10 for calling the PiecewiseLinear obj's underlying member method code with example usage: obj.quantile_internal(x, axis) and returns: quantile