code: def discrete(samples, index=None):
      """impose a discrete set of input values for the selected function
  
      The function's input will be mapped to the given discrete set
  
      Examples:
          >>> @discrete([1.0, 2.0])
          ... def identity(x):
          ...     return x
          ...
          >>> identity([0.123, 1.789, 4.000])
          [1.0, 2.0, 2.0]
  
          >>> @discrete([1,3,5,7], index=(0,3))
          ... def squared(x):
          ...     return [i**2 for i in x]
          ...
          >>> squared([0,2,4,6,8,10])
          [1, 4, 16, 25, 64, 100]
      """
      samples = [asarray(samples)]
      samples[0].sort()
      if isinstance(index, int):
          index = (index,)
      index = [index]
  
      # XXX: refactor to use points_factory(samples)
      def _points(alist):
          alist = asarray(alist)
          alist.sort()
          samples[0] = alist
  
      def _index(alist=None):
          index[0] = alist
  
      # XXX: refactor to use argnear_factory(samples)
      def _argnear(xi):
          arghi = sum(xi > samples[0])
          arglo = max(0, arghi - 1)  # minimum = x[0]
          if arghi == len(samples[0]):
              arghi = arglo  # maximum = x[-1]
          return arglo, arghi
  
      def _near(xi, lo, hi):
          if hi - xi < xi - lo:
              return hi
          return lo
  
      #   argnear = vectorize(_argnear)  #XXX: doesn't pickle well in all cases
      #   near = vectorize(_near)        #XXX: doesn't pickle well in all cases
      def argnear(x):
          # RESULT: (array([0,0,1]),array([0,1,2])) *or* (array(0),array(1))
          flatten = False
          if not len(shape(x)):
              flatten = True
              x = [x]
          result = tuple(i for i in asarray(list(map(_argnear, x))).T)
          if flatten:
              result = tuple(asarray(i[0]) for i in result)
          return result
  
      def near(x, l, h):
          # RESULT: array(3) & array([3, 4])
          a = broadcast(x, l, h)
          has_iterable = a.shape
          x, l, h = tuple(atleast_1d(i) for i in (x, l, h))
          b = broadcast(x, l, h)
          _x, _l, _h = (empty(b.shape), empty(b.shape), empty(b.shape))
          _x.flat = [i for i in x]
          _l.flat = [i for i in l]
          _h.flat = [i for i in h]
          result = asarray(list(map(_near, x, l, h)))
          if not has_iterable:
              result = asarray(result[0])
          return result
  
      def dec(f):
          def func(x, *args, **kwds):
              if isinstance(x, ndarray):
                  xtype = asarray
              else:
                  xtype = type(x)
              arglo, arghi = argnear(x)
              xp = near(x, samples[0][arglo], samples[0][arghi])
              # create a choice array from given indices
              # FIXME: better ways to do the following
              if index[0] is None:
                  mask = ones(xp.size, dtype=bool)
              else:
                  mask = zeros(xp.size, dtype=bool)
                  try:
                      mask[sorted(index[0], key=abs)] = True
                  except IndexError:
                      pass
              xp = xtype(choose(mask, (x, xp)))
              return f(xp, *args, **kwds)
  
          func.samples = _points
          func.index = _index
          return func
  
      return dec
  
imports: from mystic.math.measures import *
  from mystic.math import almostEqual
  from numpy import sum
  from numpy import asfarray, asarray, choose, zeros, ones, ndarray
  from numpy import shape, broadcast, empty, atleast_1d
  from numpy import round, abs
  from random import randrange, shuffle
  from numpy import array, intersect1d, inf, isnan, where, choose, clip
  from numpy.random import uniform, choice
  from numpy import maximum, minimum
  from numpy import round, abs
  from mystic.tools import synchronized, connected
  from mystic.math.discrete import product_measure
label_desc: Use image node_id 16 for calling a global function with example usage: discrete(samples, index) and returns: dec, arglo,  arghi, lo, result, result, func, hi, f