Ejemplo n.º 1
0
    def exercise_increasing_dimensions(self):
        print("Scaling with m and m/n: ", end=' ')
        n_tests = 0
        for sigma, a in self.matrices():
            m, n = a.focus()
            if self.show_progress:
                if not n_tests: print()
                print((m, n), end=' ')
                sys.stdout.flush()
            svd = self.klass(a, self.accumulate_u, self.accumulate_v)
            if self.show_progress:
                print('!', end=' ')
                sys.stdout.flush()
            sigma = sigma.select(flex.sort_permutation(sigma, reverse=True))
            delta = (svd.sigma - sigma).norm() / sigma.norm() / min(
                m, n) / self.eps
            assert delta < 10
            n_tests += 1

            if not self.exercise_tntbx:
                if self.show_progress: print()
                continue
            svd = tntbx.svd_m_ge_n_double(a)
            if self.show_progress:
                print('!')
                sys.stdout.flush()
            sigma = sigma.select(flex.sort_permutation(sigma, reverse=True))
            delta = ((svd.singular_values() - sigma).norm() / sigma.norm() /
                     min(m, n) / self.eps)
            assert delta < 10
        if self.show_progress: print()
        print("%i done" % n_tests)
Ejemplo n.º 2
0
  def exercise_increasing_dimensions(self):
    print "Scaling with m and m/n: ",
    n_tests = 0
    for sigma, a in self.matrices():
      m, n = a.focus()
      if self.show_progress:
        if not n_tests: print
        print (m,n),
        sys.stdout.flush()
      svd = scitbx.linalg.svd.real(a, self.accumulate_u, self.accumulate_v)
      if self.show_progress:
        print '!',
        sys.stdout.flush()
      sigma = sigma.select(flex.sort_permutation(sigma, reverse=True))
      delta = (svd.sigma - sigma).norm()/sigma.norm()/min(m,n)/self.eps
      assert delta < 10
      n_tests += 1

      if not self.exercise_tntbx:
        if self.show_progress: print
        continue
      svd = tntbx.svd_m_ge_n_double(a)
      if self.show_progress:
        print '!'
        sys.stdout.flush()
      sigma = sigma.select(flex.sort_permutation(sigma, reverse=True))
      delta = ((svd.singular_values() - sigma).norm()
               /sigma.norm()/min(m,n)/self.eps)
      assert delta < 10
    if self.show_progress: print
    print "%i done" % n_tests
Ejemplo n.º 3
0
 def time(self):
     from libtbx.easy_profile import easy_profile
     self.scitbx_report = []
     self.tntbx_report = []
     prof_scitbx = easy_profile(self.klass,
                                file_name='svd.py',
                                func_name='__init__',
                                line=None)
     if tntbx is not None:
         prof_tntbx = easy_profile(lambda m: tntbx.svd_m_ge_n_double(m),
                                   file_name='tst_svd.py',
                                   func_name='<lambda>',
                                   line=None)
     for sigma, a in self.matrices():
         m, n = a.focus()
         if self.show_progress:
             print((m, n), end=' ')
             sys.stdout.flush()
         flops = min(2 * m * n**2 - 2 * n**3 / 3, m * n**2 + n**3)
         runs = max(int(1e4 / flops), 1)
         if tntbx:
             prof_tntbx.runs = runs
             sys.stdout.flush()
             t = prof_tntbx.time(a)
             if self.show_progress:
                 print('!', end=' ')
             self.tntbx_report.append((m, n, t))
         prof_scitbx.runs = runs
         t = prof_scitbx.time(a, accumulate_u=True, accumulate_v=True)
         if self.show_progress:
             print('!')
         self.scitbx_report.append((m, n, t))
     print('scitbx = {')
     print(', '.join(
         ["{%i, %i, %f}" % (m, n, t) for m, n, t in self.scitbx_report]))
     print('};')
     if tntbx:
         print('(***************************************************)')
         print('(***************************************************)')
         print('tntbx = {')
         print(', '.join(
             ["{%i, %i, %f}" % (m, n, t) for m, n, t in self.tntbx_report]))
         print('};')
Ejemplo n.º 4
0
 def time(self):
   from libtbx.easy_profile import easy_profile
   self.scitbx_report = []
   self.tntbx_report = []
   prof_scitbx = easy_profile(scitbx.linalg.svd.real,
                               file_name='svd.py', func_name='__init__',
                               line=None)
   if tntbx is not None:
     prof_tntbx = easy_profile(lambda m: tntbx.svd_m_ge_n_double(m),
                                 file_name='tst_svd.py', func_name='<lambda>',
                                 line=None)
   for sigma, a in self.matrices():
     m, n = a.focus()
     if self.show_progress:
       print (m,n),
       sys.stdout.flush()
     flops = min(2*m*n**2 - 2*n**3/3, m*n**2 + n**3)
     runs = max(int(1e4/flops), 1)
     if tntbx:
       prof_tntbx.runs = runs
       sys.stdout.flush()
       t = prof_tntbx.time(a)
       if self.show_progress:
         print '!',
       self.tntbx_report.append((m, n, t))
     prof_scitbx.runs = runs
     t = prof_scitbx.time(a, accumulate_u=True, accumulate_v=True)
     if self.show_progress:
       print '!'
     self.scitbx_report.append((m, n, t))
   print 'scitbx = {'
   print ', '.join([ "{%i, %i, %f}" % (m, n, t)
                     for m, n, t in self.scitbx_report ])
   print '};'
   if tntbx:
     print '(***************************************************)'
     print '(***************************************************)'
     print 'tntbx = {'
     print ', '.join([ "{%i, %i, %f}" % (m, n, t)
                       for m, n, t in self.tntbx_report ])
     print '};'