Ejemplo n.º 1
0
def exercise_random_permutation_in_place():
  from libtbx.math_utils import random_permutation_in_place
  import random
  random.seed(0)
  l = range(8)
  for i_trial in xrange(10):
    random_permutation_in_place(list=l)
    if (l != range(8)):
      break
  else:
    raise AssertionError
  assert sorted(l) == range(8)
Ejemplo n.º 2
0
def exercise_random_permutation_in_place():
    from libtbx.math_utils import random_permutation_in_place
    import random
    random.seed(0)
    l = range(8)
    for i_trial in xrange(10):
        random_permutation_in_place(list=l)
        if (l != range(8)):
            break
    else:
        raise AssertionError
    assert sorted(l) == range(8)
Ejemplo n.º 3
0
def exercise_given_members_size(array_alignment, n, n_trials=10):
    from libtbx.math_utils import random_permutation_in_place
    import random
    random.seed(0)
    i_mbrs = list(range(n))
    for i_trial in range(n_trials):
        random_permutation_in_place(list=i_mbrs)
        #
        pair0 = i_mbrs[0], random.randrange(n + 5)
        pairs = []
        for i in range(1, n):
            pair1 = i_mbrs[i], random.randrange(n + 5)
            if (random.random() < 0.5):
                pairs.append((pair0, pair1))
            else:
                pairs.append((pair1, pair0))
        diffs0 = check_array_alignment(array_alignment, n, pairs)
        for i_redundant in range(3):
            i = random.randrange(n)
            j = random.randrange(n)
            d = random.randrange(n + 5)
            pairs.append(((i, diffs0[j] - diffs0[i] + d), (j, d)))
        diffs0_r = check_array_alignment(array_alignment, n, pairs)
        assert diffs0 == diffs0_r
        #
        diffs_in = [0]
        for i in range(n - 1):
            diffs_in.append(random.randrange(n + 5))
        random_permutation_in_place(list=diffs_in)
        all_pairs = []
        for i in range(n):
            for j in range(3):
                sh = random.randrange(n + 5)
                all_pairs.append(((i, sh), (i, sh)))
        for i in range(n - 1):
            for j in range(i + 1, n):
                sh = random.randrange(n + 5)
                i0 = i_mbrs[i]
                a0 = diffs_in[i0] + sh
                i1 = i_mbrs[j]
                a1 = diffs_in[i1] + sh
                all_pairs.append(((i0, a0), (i1, a1)))
                all_pairs.append(((i1, a1), (i0, a0)))
        random_permutation_in_place(list=all_pairs)
        check_array_alignment(array_alignment, n, all_pairs)
    #
    # non-sensical inputs to exercise stability (e.g. asserts)
    for i_trial in range(n_trials):
        pairs = []
        for i_pair in range(n + 2):
            i0 = random.randrange(n)
            o0 = random.randrange(n + 5)
            i1 = random.randrange(n)
            o1 = random.randrange(n + 5)
            pairs.append(((i0, o0), (i1, o1)))
            try:
                check_array_alignment(array_alignment, n, pairs)
            except RuntimeError as e:
                pass
def exercise_given_members_size(array_alignment, n, n_trials=10):
  from libtbx.math_utils import random_permutation_in_place
  import random
  random.seed(0)
  i_mbrs = range(n)
  for i_trial in xrange(n_trials):
    random_permutation_in_place(list=i_mbrs)
    #
    pair0 = i_mbrs[0], random.randrange(n+5)
    pairs = []
    for i in xrange(1,n):
      pair1 = i_mbrs[i], random.randrange(n+5)
      if (random.random() < 0.5):
        pairs.append((pair0, pair1))
      else:
        pairs.append((pair1, pair0))
    diffs0 = check_array_alignment(array_alignment, n, pairs)
    for i_redundant in xrange(3):
      i = random.randrange(n)
      j = random.randrange(n)
      d = random.randrange(n+5)
      pairs.append(((i,diffs0[j]-diffs0[i]+d), (j,d)))
    diffs0_r = check_array_alignment(array_alignment, n, pairs)
    assert diffs0 == diffs0_r
    #
    diffs_in = [0]
    for i in xrange(n-1):
      diffs_in.append(random.randrange(n+5))
    random_permutation_in_place(list=diffs_in)
    all_pairs = []
    for i in xrange(n):
      for j in xrange(3):
        sh = random.randrange(n+5)
        all_pairs.append(((i,sh), (i,sh)))
    for i in xrange(n-1):
      for j in xrange(i+1,n):
        sh = random.randrange(n+5)
        i0 = i_mbrs[i]
        a0 = diffs_in[i0] + sh
        i1 = i_mbrs[j]
        a1 = diffs_in[i1] + sh
        all_pairs.append(((i0,a0), (i1,a1)))
        all_pairs.append(((i1,a1), (i0,a0)))
    random_permutation_in_place(list=all_pairs)
    check_array_alignment(array_alignment, n, all_pairs)
  #
  # non-sensical inputs to exercise stability (e.g. asserts)
  for i_trial in xrange(n_trials):
    pairs = []
    for i_pair in xrange(n+2):
      i0 = random.randrange(n)
      o0 = random.randrange(n+5)
      i1 = random.randrange(n)
      o1 = random.randrange(n+5)
      pairs.append(((i0,o0), (i1,o1)))
      try:
        check_array_alignment(array_alignment, n, pairs)
      except RuntimeError, e:
        pass