code: def impose_measure(npts, tracking={}, noweight={}):
      """generate a function, that constrains measure positions and weights
  
      npts is a tuple of the product_measure dimensionality
  
      tracking is a dict of collapses, or a tuple of dicts of collapses.
      a tracking collapse is a dict of {measure: {pairs of indices}}, where the
      pairs of indices are where the positions will be constrained to have the
      same value, and the weight from the second index in the pair will be removed
      and added to the weight of the first index
  
      noweight is a dict of collapses, or a tuple of dicts of collapses.
      a noweight collapse is a dict of {measure: {indices}), where the
      indices are where the measure will be constrained to have zero weight
  
      Examples:
          >>> pos = {0: {(0,1)}, 1:{(0,2)}}
          >>> wts = {0: {1}, 1: {1, 2}}
          >>> npts = (3,3)
          >>>
          >>> @impose_measure(npts, pos)
          ... def same(x):
          ...   return x
          ...
          >>> same([.5, 0., .5, 2., 4., 6., .25, .5, .25, 6., 4., 2.])
          [0.5, 0.0, 0.5, 2.0, 2.0, 6.0, 0.5, 0.5, 0.0, 5.0, 3.0, 5.0]
          >>> same([1./3, 1./3, 1./3, 1., 2., 3., 1./3, 1./3, 1./3, 1., 2., 3.])
          [0.6666666666666666, 0.0, 0.3333333333333333, 1.3333333333333335, 1.3333333333333335, 3.3333333333333335, 0.6666666666666666, 0.3333333333333333, 0.0, 1.6666666666666667, 2.666666666666667, 1.6666666666666667]
          >>>
          >>> @impose_measure(npts, {}, wts)
          ... def doit(x):
          ...   return x
          ...
          >>> doit([.5, 0., .5, 2., 4., 6., .25, .5, .25, 6., 4., 2.])
          [0.5, 0.0, 0.5, 2.0, 4.0, 6.0, 1.0, 0.0, 0.0, 4.0, 2.0, 0.0]
          >>> doit([1./3, 1./3, 1./3, 1., 2., 3., 1./3, 1./3, 1./3, 1., 2., 3.])
          [0.5, 0.0, 0.5, 1.0, 2.0, 3.0, 1.0, 0.0, 0.0, 2.0, 3.0, 4.0]
          >>>
          >>> @impose_measure(npts, pos, wts)
          ... def both(x):
          ...   return x
          ...
          >>> both([1./3, 1./3, 1./3, 1., 2., 3., 1./3, 1./3, 1./3, 1., 2., 3.])
          [0.66666666666666663, 0.0, 0.33333333333333331, 1.3333333333333335, 1.3333333333333335, 3.3333333333333335, 1.0, 0.0, 0.0, 2.0, 3.0, 2.0]
      """
      # takes a dict of collapses, or a tuple of dicts of collapses
      if type(tracking) is dict:
          tracking = (tracking,)
      if type(noweight) is dict:
          noweight = (noweight,)
  
      def dec(f):
          def func(x, *args, **kwds):
              # populate a product measure with params
              c = product_measure()
              c.load(x, npts)
              # apply all collapses
              for clps in tracking:
                  for k, v in clps.items():
                      c[k].positions, c[k].weights = impose_collapse(
                          v, c[k].positions, c[k].weights
                      )
              for clps in noweight:
                  for k, v in clps.items():
                      c[k].positions, c[k].weights = impose_unweighted(
                          v, c[k].positions, c[k].weights, False
                      )
              # convert to params and apply function
              return f(c.flatten(), *args, **kwds)
  
          func.__wrapped__ = f  # XXX: getattr(f, '__wrapped__', f) ?
          func.__doc__ = f.__doc__
          func.npts = npts
          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 32 for calling a global function with example usage: impose_measure(npts, tracking, noweight) and returns: dec, func, f