parameters: (x, config=None, value_type=sgf2n, reverse=False)
return_statement: return config
docstring: Simulate secure shuffling with Waksman network for 2 players.
      WARNING: This is not a properly secure implementation but has roughly the right complexity.
  
      Returns the network switching config so it may be re-used later.
docstring_summary: Simulate secure shuffling with Waksman network for 2 players.
      WARNING: This is not a properly secure implementation but has roughly the right complexity.
docstring_tokens: Simulate secure shuffling with Waksman network for 2 players . WARNING : This is not a properly secure implementation but has roughly the right complexity .
function: def shuffle(x, config=None, value_type=sgf2n, reverse=False):
      """ Simulate secure shuffling with Waksman network for 2 players.
      WARNING: This is not a properly secure implementation but has roughly the right complexity.
  
      Returns the network switching config so it may be re-used later.  """
      n = len(x)
      m = 2**int(math.ceil(math.log(n, 2)))
      if config is None:
          config = config_shuffle(n, value_type)
  
      if isinstance(x, list):
          if isinstance(x[0], list):
              length = len(x[0])
              for i in range(length):
                  xi = Array(m, value_type.reg_type)
                  for j in range(n):
                      xi[j] = x[j][i]
                  for j in range(n, m):
                      xi[j] = value_type(0)
                  iter_waksman(xi, config, reverse=reverse)
                  iter_waksman(xi, config, reverse=reverse)
          else:
              xa = Array(m, value_type.reg_type)
              for i in range(n):
                  xa[i] = x[i]
              for i in range(n, m):
                  xa[i] = value_type(0)
              iter_waksman(xa, config, reverse=reverse)
              iter_waksman(xa, config, reverse=reverse)
      elif isinstance(x, Array):
          if len(x) != m and config is None:
              raise CompilerError('Non-power of 2 Array input not yet supported')
          iter_waksman(x, config, reverse=reverse)
          iter_waksman(x, config, reverse=reverse)
      else:
          raise CompilerError('Invalid type for shuffle:', type(x))
  
      return config
function_tokens: def shuffle ( x , config = None , value_type = sgf2n , reverse = False ) : n = len ( x ) m = 2 ** int ( math . ceil ( math . log ( n , 2 ) ) ) if config is None : config = config_shuffle ( n , value_type ) if isinstance ( x , list ) : if isinstance ( x [ 0 ] , list ) : length = len ( x [ 0 ] ) for i in range ( length ) : xi = Array ( m , value_type . reg_type ) for j in range ( n ) : xi [ j ] = x [ j ] [ i ] for j in range ( n , m ) : xi [ j ] = value_type ( 0 ) iter_waksman ( xi , config , reverse = reverse ) iter_waksman ( xi , config , reverse = reverse ) else : xa = Array ( m , value_type . reg_type ) for i in range ( n ) : xa [ i ] = x [ i ] for i in range ( n , m ) : xa [ i ] = value_type ( 0 ) iter_waksman ( xa , config , reverse = reverse ) iter_waksman ( xa , config , reverse = reverse ) elif isinstance ( x , Array ) : if len ( x ) != m and config is None : raise CompilerError ( 'Non-power of 2 Array input not yet supported' ) iter_waksman ( x , config , reverse = reverse ) iter_waksman ( x , config , reverse = reverse ) else : raise CompilerError ( 'Invalid type for shuffle:' , type ( x ) ) return config