class_docstr: .. include:: /global.rst
  
  Please refer to |sobol| for details on this algorithm.
docstr: Generates a new quasi-random Sobol vector with each call.
  
  :param dim_num: number of dimensions of the Sobol vector
  :type dim_num: int
  :param seed: the seed to use to generate the Sobol vector
  :type seed: int
  :returns: the next quasirandom vector and the next seed to use
  
  This was taken from http://people.sc.fsu.edu/~jburkardt/py_src/sobol/sobol.html
  Licensing:
      This code is distributed under the MIT license.
  
  Modified:
      22 February 2011
  
  Author:
      Original MATLAB version by John Burkardt.
      PYTHON version by Corrado Chisari
docstr_tok: ["Generates","a","new","quasi-random","Sobol","vector","with","each","call",".",":","param","dim_num",":","number","of","dimensions","of","the","Sobol","vector",":","type","dim_num",":","int",":","param","seed",":","the","seed","to","use","to","generate","the","Sobol","vector",":","type","seed",":","int",":","returns",":","the","next","quasirandom","vector","and","the","next","seed","to","use","This","was","taken","from","http",":","\/\/people.sc.fsu.edu\/~jburkardt\/py_src\/sobol\/sobol.html","Licensing",":","This","code","is","distributed","under","the","MIT","license",".","Modified",":","22","February","2011","Author",":","Original","MATLAB","version","by","John","Burkardt",".","PYTHON","version","by","Corrado","Chisari"]
code: def i4_sobol(dim_num, seed):
      """
      Generates a new quasi-random Sobol vector with each call.
  
      :param dim_num: number of dimensions of the Sobol vector
      :type dim_num: int
      :param seed: the seed to use to generate the Sobol vector
      :type seed: int
      :returns: the next quasirandom vector and the next seed to use
  
      This was taken from http://people.sc.fsu.edu/~jburkardt/py_src/sobol/sobol.html
      Licensing:
          This code is distributed under the MIT license.
  
      Modified:
          22 February 2011
  
      Author:
          Original MATLAB version by John Burkardt.
          PYTHON version by Corrado Chisari
  
      """
      global atmost
      global dim_max
      global dim_num_save
      global initialized
      global lastq
      global log_max
      global maxcol
      global poly
      global recipd
      global seed_save
      global v
  
      if not "initialized" in globals().keys():
          initialized = 0
          dim_num_save = -1
  
      if not initialized or dim_num != dim_num_save:
          initialized = 1
          dim_max = 40
          dim_num_save = -1
          log_max = 30
          seed_save = -1
          #
          #    Initialize (part of) V.
          #
          v = [[0] * dim_max for _ in irange(log_max)]
          v[0][0:40] = [
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
              1,
          ]
  
          v[1][2:40] = [
              1,
              3,
              1,
              3,
              1,
              3,
              3,
              1,
              3,
              1,
              3,
              1,
              3,
              1,
              1,
              3,
              1,
              3,
              1,
              3,
              1,
              3,
              3,
              1,
              3,
              1,
              3,
              1,
              3,
              1,
              1,
              3,
              1,
              3,
              1,
              3,
              1,
              3,
          ]
  
          v[2][3:40] = [
              7,
              5,
              1,
              3,
              3,
              7,
              5,
              5,
              7,
              7,
              1,
              3,
              3,
              7,
              5,
              1,
              1,
              5,
              3,
              3,
              1,
              7,
              5,
              1,
              3,
              3,
              7,
              5,
              1,
              1,
              5,
              7,
              7,
              5,
              1,
              3,
              3,
          ]
  
          v[3][5:40] = [
              1,
              7,
              9,
              13,
              11,
              1,
              3,
              7,
              9,
              5,
              13,
              13,
              11,
              3,
              15,
              5,
              3,
              15,
              7,
              9,
              13,
              9,
              1,
              11,
              7,
              5,
              15,
              1,
              15,
              11,
              5,
              3,
              1,
              7,
              9,
          ]
  
          v[4][7:40] = [
              9,
              3,
              27,
              15,
              29,
              21,
              23,
              19,
              11,
              25,
              7,
              13,
              17,
              1,
              25,
              29,
              3,
              31,
              11,
              5,
              23,
              27,
              19,
              21,
              5,
              1,
              17,
              13,
              7,
              15,
              9,
              31,
              9,
          ]
  
          v[5][13:40] = [
              37,
              33,
              7,
              5,
              11,
              39,
              63,
              27,
              17,
              15,
              23,
              29,
              3,
              21,
              13,
              31,
              25,
              9,
              49,
              33,
              19,
              29,
              11,
              19,
              27,
              15,
              25,
          ]
  
          v[6][19:40] = [
              13,
              33,
              115,
              41,
              79,
              17,
              29,
              119,
              75,
              73,
              105,
              7,
              59,
              65,
              21,
              3,
              113,
              61,
              89,
              45,
              107,
          ]
  
          v[7][37:40] = [7, 23, 39]
          #
          #    Set POLY.
          #
          poly = [
              1,
              3,
              7,
              11,
              13,
              19,
              25,
              37,
              59,
              47,
              61,
              55,
              41,
              67,
              97,
              91,
              109,
              103,
              115,
              131,
              193,
              137,
              145,
              143,
              241,
              157,
              185,
              167,
              229,
              171,
              213,
              191,
              253,
              203,
              211,
              239,
              247,
              285,
              369,
              299,
          ]
  
          atmost = 2**log_max - 1
          #
          #    Find the number of bits in ATMOST.
          #
          maxcol = Sobol.i4_bit_hi1(atmost)
          #
          #    Initialize row 1 of V.
          #
          #        v[0,0:maxcol] = 1
          for i in irange(maxcol):
              v[i][0] = 1
  
      #
      #    Things to do only if the dimension changed.
      #
      if dim_num != dim_num_save:
          #
          #    Check parameters.
          #
          if dim_num < 1 or dim_max < dim_num:
              raise ValueError(
                  "I4_SOBOL - Fatal error! The spatial dimension DIM_NUM should satisfy: 1 <= DIM_NUM <= %d, But this input value is DIM_NUM = %d"
                  % (dim_max, dim_num)
              )
  
          dim_num_save = dim_num
          #
          #    Initialize the remaining rows of V.
          #
          for i in irange(2, dim_num + 1):
              #
              #    The bits of the integer POLY(I) gives the form of polynomial I.
              #
              #    Find the degree of polynomial I from binary encoding.
              #
              j = poly[i - 1]
              m = 0
              while 1:
                  j = math.floor(j / 2.0)
                  if j <= 0:
                      break
                  m = m + 1
              #
              #    Expand this bit pattern to separate components of the logical array INCLUD.
              #
              j = poly[i - 1]
              includ = [0 for _ in irange(m)]
              for k in irange(m, 0, -1):
                  j2 = math.floor(j / 2.0)
                  includ[k - 1] = j != 2 * j2
                  j = j2
              #
              #    Calculate the remaining elements of row I as explained
              #    in Bratley and Fox, section 2.
              #
              for j in irange(m + 1, maxcol + 1):
                  newv = v[j - m - 1][i - 1]
                  l = 1
                  for k in irange(1, m + 1):
                      l = 2 * l
                      if includ[k - 1]:
                          newv = Sobol.bitwise_xor(
                              int(newv), int(l * v[j - k - 1][i - 1])
                          )
                  v[j - 1][i - 1] = newv
          #
          #    Multiply columns of V by appropriate power of 2.
          #
          l = 1
          for j in irange(maxcol - 1, 0, -1):
              l = 2 * l
              v[j - 1][0:dim_num] = map(
                  lambda x: x * l, v[j - 1][0:dim_num]
              )
          #
          #    RECIPD is 1/(common denominator of the elements in V).
          #
          recipd = 1.0 / (2 * l)
          lastq = [0 for _ in irange(dim_num)]
  
      seed = int(math.floor(seed))
  
      if seed < 0:
          seed = 0
  
      if seed == 0:
          l = 1
          lastq = [0 for _ in irange(dim_num)]
  
      elif seed == seed_save + 1:
          #
          #    Find the position of the right-hand zero in SEED.
          #
          l = Sobol.i4_bit_lo0(seed)
  
      elif seed <= seed_save:
          seed_save = 0
          l = 1
          lastq = [0 for _ in irange(dim_num)]
  
          for seed_temp in irange(int(seed_save), int(seed)):
              l = Sobol.i4_bit_lo0(seed_temp)
              for i in irange(1, dim_num + 1):
                  lastq[i - 1] = Sobol.bitwise_xor(
                      int(lastq[i - 1]), int(v[l - 1][i - 1])
                  )
  
          l = Sobol.i4_bit_lo0(seed)
  
      elif seed_save + 1 < seed:
          for seed_temp in irange(int(seed_save + 1), int(seed)):
              l = Sobol.i4_bit_lo0(seed_temp)
              for i in irange(1, dim_num + 1):
                  lastq[i - 1] = Sobol.bitwise_xor(
                      int(lastq[i - 1]), int(v[l - 1][i - 1])
                  )
  
          l = Sobol.i4_bit_lo0(seed)
      #
      #    Check that the user is not calling too many times!
      #
      if maxcol < l:
          raise ValueError(
              "I4_SOBOL - Fatal error! Too many calls: MAXCOL = %d, L = %d"
              % (maxcol, l)
          )
      #
      #    Calculate the new components of QUASI.
      #
      quasi = [0 for _ in irange(dim_num)]
      for i in irange(1, dim_num + 1):
          quasi[i - 1] = lastq[i - 1] * recipd
          lastq[i - 1] = Sobol.bitwise_xor(
              int(lastq[i - 1]), int(v[l - 1][i - 1])
          )
  
      seed_save = seed
      seed = seed + 1
  
      return [quasi, seed]
  
imports: import math
  import operator
  import random
  import array
  import functools
  from ..functions import static_key_order
  from .solver_registry import register_solver
  from .util import Solver, _copydoc, uniform_in_bounds
  from .None import util
label_desc: Use image node_id 11 for calling the Sobol obj's underlying member method code with example usage: obj.i4_sobol(dim_num, seed) and returns: list