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: Computes the quantile level :math:`\alpha` such that
  :math:`q(\alpha) = x`.
  
  Parameters
  ----------
  x
      Tensor of shape gamma.shape
  
  Returns
  -------
  Tensor
      Tensor of shape gamma.shape
docstr_tok: ["Computes","the","quantile","level",":","math",":","`","\\alpha","`","such","that",":","math",":","`","q","(","\\alpha",")","=","x","`",".","Parameters","--","--","--","--","--","x","Tensor","of","shape","gamma.shape","Returns","--","--","--","-","Tensor","Tensor","of","shape","gamma.shape"]
code: def cdf(self, x: Tensor) -> Tensor:
      r"""
      Computes the quantile level :math:`\alpha` such that
      :math:`q(\alpha) = x`.
  
      Parameters
      ----------
      x
          Tensor of shape gamma.shape
  
      Returns
      -------
      Tensor
          Tensor of shape gamma.shape
      """
  
      F = self.F
      gamma, b, knot_positions = self.gamma, self.b, self.knot_positions
  
      quantiles_at_knots = self.quantile_internal(
          knot_positions, axis=-2
      )
  
      # Mask to nullify the terms corresponding to knots larger than l_0,
      # which is the largest knot(quantile level) such that the quantile at
      # l_0, s(l_0) < x.(..., num_pieces)
      mask = F.broadcast_lesser(
          quantiles_at_knots, x.expand_dims(axis=-1)
      )
  
      slope_l0 = F.sum(b * mask, axis=-1, keepdims=False)
  
      # slope_l0 can be zero in which case a_tilde = 0. The following is to
      # circumvent mxnet issue with "where" operator which returns nan even
      # if the statement you are interested in does not result in nan
      # (but the "else" statement evaluates to nan).
      slope_l0_nz = F.where(
          slope_l0 == F.zeros_like(slope_l0), F.ones_like(x), slope_l0
      )
  
      a_tilde = F.where(
          slope_l0 == F.zeros_like(slope_l0),
          F.zeros_like(x),
          (
              x
              - gamma
              + F.sum(
                  b * knot_positions * mask, axis=-1, keepdims=False
              )
          )
          / slope_l0_nz,
      )
  
      return F.broadcast_minimum(F.ones_like(a_tilde), a_tilde)
  
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 8 for calling the PiecewiseLinear obj's underlying member method code with example usage: obj.cdf(x) and returns: F