nodes: 0, module; 1, function_definition; 2, function_name:orth_gs; 3, parameters; 4, block; 5, identifier:order; 6, identifier:dist; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, dictionary_splat_pattern; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, return_statement; 19, identifier:normed; 20, False; 21, identifier:sort; 22, string:"GR"; 23, identifier:cross_truncation; 24, float:1.; 25, identifier:kws; 26, comment:"""
      Gram-Schmidt process for generating orthogonal polynomials.
  
      Args:
          order (int, Poly):
              The upper polynomial order. Alternative a custom polynomial basis
              can be used.
          dist (Dist):
              Weighting distribution(s) defining orthogonality.
          normed (bool):
              If True orthonormal polynomials will be used instead of monic.
          sort (str):
              Ordering argument passed to poly.basis. If custom basis is used,
              argument is ignored.
          cross_truncation (float):
              Use hyperbolic cross truncation scheme to reduce the number of
              terms in expansion.
  
      Returns:
          (Poly):
              The orthogonal polynomial expansion.
  
      Examples:
          >>> Z = chaospy.J(chaospy.Normal(), chaospy.Normal())
          >>> print(chaospy.around(chaospy.orth_gs(2, Z), 4))
          [1.0, q1, q0, q1^2-1.0, q0q1, q0^2-1.0]
      """; 27, assignment; 28, assignment; 29, call; 30, block; 31, else_clause; 32, assignment; 33, assignment; 34, identifier:normed; 35, block; 36, else_clause; 37, call; 38, identifier:logger; 39, call; 40, identifier:dim; 41, call; 42, identifier:isinstance; 43, argument_list; 44, if_statement; 45, expression_statement; 46, block; 47, identifier:basis; 48, call; 49, identifier:polynomials; 50, list; 51, for_statement; 52, block; 53, attribute; 54, argument_list; 55, attribute; 56, argument_list; 57, identifier:len; 58, argument_list; 59, identifier:order; 60, identifier:int; 61, comparison_operator:order == 0; 62, block; 63, assignment; 64, expression_statement; 65, identifier:list; 66, argument_list; 67, subscript; 68, identifier:idx; 69, call; 70, comment:# orthogonalize polynomial:; 71, block; 72, expression_statement; 73, for_statement; 74, attribute; 75, identifier:Poly; 76, identifier:polynomials; 77, keyword_argument; 78, keyword_argument; 79, identifier:logging; 80, identifier:getLogger; 81, identifier:__name__; 82, identifier:dist; 83, identifier:order; 84, integer:0; 85, return_statement; 86, identifier:basis; 87, call; 88, assignment; 89, identifier:basis; 90, identifier:basis; 91, integer:0; 92, identifier:range; 93, argument_list; 94, for_statement; 95, comment:# normalize:; 96, expression_statement; 97, if_statement; 98, expression_statement; 99, expression_statement; 100, assignment; 101, identifier:idx; 102, call; 103, comment:# orthogonalize polynomial:; 104, block; 105, identifier:chaospy; 106, identifier:poly; 107, identifier:dim; 108, identifier:dim; 109, identifier:shape; 110, tuple; 111, call; 112, attribute; 113, argument_list; 114, identifier:basis; 115, identifier:order; 116, integer:1; 117, call; 118, identifier:idy; 119, call; 120, block; 121, assignment; 122, comparison_operator:norms <= 0; 123, block; 124, assignment; 125, call; 126, identifier:norms; 127, list; 128, identifier:range; 129, argument_list; 130, for_statement; 131, expression_statement; 132, if_statement; 133, expression_statement; 134, call; 135, attribute; 136, argument_list; 137, attribute; 138, identifier:basis; 139, integer:0; 140, identifier:order; 141, identifier:dim; 142, identifier:sort; 143, keyword_argument; 144, identifier:len; 145, argument_list; 146, identifier:range; 147, argument_list; 148, expression_statement; 149, expression_statement; 150, identifier:norms; 151, call; 152, identifier:norms; 153, integer:0; 154, expression_statement; 155, break_statement; 156, subscript; 157, binary_operator:basis[idx] / numpy.sqrt(norms); 158, attribute; 159, argument_list; 160, float:1.; 161, integer:1; 162, call; 163, identifier:idy; 164, call; 165, block; 166, call; 167, comparison_operator:norms[-1] <= 0; 168, block; 169, call; 170, identifier:len; 171, argument_list; 172, attribute; 173, identifier:Poly; 174, integer:1; 175, keyword_argument; 176, identifier:chaospy; 177, identifier:poly; 178, identifier:cross_truncation; 179, identifier:cross_truncation; 180, identifier:basis; 181, identifier:idx; 182, assignment; 183, assignment; 184, attribute; 185, argument_list; 186, call; 187, identifier:basis; 188, identifier:idx; 189, subscript; 190, call; 191, identifier:polynomials; 192, identifier:append; 193, subscript; 194, identifier:len; 195, argument_list; 196, identifier:range; 197, argument_list; 198, expression_statement; 199, expression_statement; 200, attribute; 201, argument_list; 202, subscript; 203, integer:0; 204, expression_statement; 205, break_statement; 206, attribute; 207, argument_list; 208, identifier:polynomials; 209, identifier:chaospy; 210, identifier:poly; 211, identifier:dim; 212, identifier:dim; 213, identifier:orth; 214, call; 215, subscript; 216, binary_operator:basis[idx] - polynomials[idy]*orth; 217, attribute; 218, identifier:E; 219, binary_operator:polynomials[-1]**2; 220, identifier:dist; 221, dictionary_splat; 222, attribute; 223, argument_list; 224, identifier:basis; 225, identifier:idx; 226, attribute; 227, argument_list; 228, identifier:basis; 229, identifier:idx; 230, identifier:basis; 231, identifier:idx; 232, assignment; 233, assignment; 234, identifier:norms; 235, identifier:append; 236, call; 237, identifier:norms; 238, unary_operator; 239, call; 240, identifier:polynomials; 241, identifier:append; 242, subscript; 243, attribute; 244, argument_list; 245, identifier:basis; 246, identifier:idx; 247, subscript; 248, binary_operator:polynomials[idy]*orth; 249, identifier:chaospy; 250, identifier:descriptives; 251, subscript; 252, integer:2; 253, identifier:kws; 254, identifier:logger; 255, identifier:warning; 256, string:"Warning: Polynomial cutoff at term %d"; 257, identifier:idx; 258, identifier:numpy; 259, identifier:sqrt; 260, identifier:norms; 261, identifier:orth; 262, call; 263, subscript; 264, binary_operator:basis[idx] - polynomials[idy] * orth / norms[idy]; 265, attribute; 266, argument_list; 267, integer:1; 268, attribute; 269, argument_list; 270, identifier:basis; 271, identifier:idx; 272, attribute; 273, identifier:E; 274, binary_operator:basis[idx]*polynomials[idy]; 275, identifier:dist; 276, dictionary_splat; 277, identifier:basis; 278, identifier:idx; 279, subscript; 280, identifier:orth; 281, identifier:polynomials; 282, unary_operator; 283, attribute; 284, argument_list; 285, identifier:basis; 286, identifier:idx; 287, subscript; 288, binary_operator:polynomials[idy] * orth / norms[idy]; 289, attribute; 290, identifier:E; 291, binary_operator:polynomials[-1]**2; 292, identifier:dist; 293, dictionary_splat; 294, identifier:logger; 295, identifier:warning; 296, string:"Warning: Polynomial cutoff at term %d"; 297, identifier:idx; 298, identifier:chaospy; 299, identifier:descriptives; 300, subscript; 301, subscript; 302, identifier:kws; 303, identifier:polynomials; 304, identifier:idy; 305, integer:1; 306, attribute; 307, identifier:E; 308, binary_operator:basis[idx]*polynomials[idy]; 309, identifier:dist; 310, dictionary_splat; 311, identifier:basis; 312, identifier:idx; 313, binary_operator:polynomials[idy] * orth; 314, subscript; 315, identifier:chaospy; 316, identifier:descriptives; 317, subscript; 318, integer:2; 319, identifier:kws; 320, identifier:basis; 321, identifier:idx; 322, identifier:polynomials; 323, identifier:idy; 324, identifier:chaospy; 325, identifier:descriptives; 326, subscript; 327, subscript; 328, identifier:kws; 329, subscript; 330, identifier:orth; 331, identifier:norms; 332, identifier:idy; 333, identifier:polynomials; 334, unary_operator; 335, identifier:basis; 336, identifier:idx; 337, identifier:polynomials; 338, identifier:idy; 339, identifier:polynomials; 340, identifier:idy; 341, integer:1
code: def orth_gs(order, dist, normed=False, sort="GR", cross_truncation=1., **kws):
      """
      Gram-Schmidt process for generating orthogonal polynomials.
  
      Args:
          order (int, Poly):
              The upper polynomial order. Alternative a custom polynomial basis
              can be used.
          dist (Dist):
              Weighting distribution(s) defining orthogonality.
          normed (bool):
              If True orthonormal polynomials will be used instead of monic.
          sort (str):
              Ordering argument passed to poly.basis. If custom basis is used,
              argument is ignored.
          cross_truncation (float):
              Use hyperbolic cross truncation scheme to reduce the number of
              terms in expansion.
  
      Returns:
          (Poly):
              The orthogonal polynomial expansion.
  
      Examples:
          >>> Z = chaospy.J(chaospy.Normal(), chaospy.Normal())
          >>> print(chaospy.around(chaospy.orth_gs(2, Z), 4))
          [1.0, q1, q0, q1^2-1.0, q0q1, q0^2-1.0]
      """
      logger = logging.getLogger(__name__)
      dim = len(dist)
  
      if isinstance(order, int):
          if order == 0:
              return chaospy.poly.Poly(1, dim=dim)
          basis = chaospy.poly.basis(
              0, order, dim, sort, cross_truncation=cross_truncation)
      else:
          basis = order
  
      basis = list(basis)
  
      polynomials = [basis[0]]
  
      if normed:
          for idx in range(1, len(basis)):
  
              # orthogonalize polynomial:
              for idy in range(idx):
                  orth = chaospy.descriptives.E(
                      basis[idx]*polynomials[idy], dist, **kws)
                  basis[idx] = basis[idx] - polynomials[idy]*orth
  
              # normalize:
              norms = chaospy.descriptives.E(polynomials[-1]**2, dist, **kws)
              if norms <= 0:
                  logger.warning("Warning: Polynomial cutoff at term %d", idx)
                  break
              basis[idx] = basis[idx] / numpy.sqrt(norms)
  
              polynomials.append(basis[idx])
  
      else:
  
          norms = [1.]
          for idx in range(1, len(basis)):
  
              # orthogonalize polynomial:
              for idy in range(idx):
                  orth = chaospy.descriptives.E(
                      basis[idx]*polynomials[idy], dist, **kws)
                  basis[idx] = basis[idx] - polynomials[idy] * orth / norms[idy]
  
              norms.append(
                  chaospy.descriptives.E(polynomials[-1]**2, dist, **kws))
              if norms[-1] <= 0:
                  logger.warning("Warning: Polynomial cutoff at term %d", idx)
                  break
  
              polynomials.append(basis[idx])
  
      return chaospy.poly.Poly(polynomials, dim=dim, shape=(len(polynomials),))