code: def sparse_mux(sel, vals):
      
      import numbers
  
      max_val = 2**len(sel) - 1
      if SparseDefault in vals:
          default_val = vals[SparseDefault]
          del vals[SparseDefault]
          for i in range(max_val + 1):
              if i not in vals:
                  vals[i] = default_val
  
      for key in vals.keys():
          if not isinstance(key, numbers.Integral):
              raise pyrtl.PyrtlError("value %s nust be either an integer or 'default'" % str(key))
          if key < 0 or key > max_val:
              raise pyrtl.PyrtlError("value %s is out of range of the sel wire" % str(key))
  
      return _sparse_mux(sel, vals)
docs: Mux that avoids instantiating unnecessary mux_2s when possible.
  
      :param WireVector sel: Select wire, determines what is selected on a given cycle
      :param dictionary vals: dictionary of values at mux inputs (of type `{int:WireVector}`)
      :return: WireVector that signifies the change
  
      This mux supports not having a full specification. Indices that are not
      specified are treated as don't-cares
  
      It also supports a specified default value, SparseDefault