Example #1
0
def exercise_results():
  x = flex.double( range(1,100) )/99.0
  f0 = math.spherical_bessel_array(0,x)
  f1 = math.spherical_bessel_array(1,x)
  f2 = math.spherical_bessel_array(2,x)
  for xx, ff,fff,ffff in zip(x,f0,f1,f2):
    assert abs(ff-j0(xx))/ff < 1e-5
    assert abs(fff-j1(xx))/fff < 1e-5
    assert abs(ffff-j2(xx))/ffff < 1e-5
Example #2
0
def exercise_results():
    x = flex.double(range(1, 100)) / 99.0
    f0 = math.spherical_bessel_array(0, x)
    f1 = math.spherical_bessel_array(1, x)
    f2 = math.spherical_bessel_array(2, x)
    for xx, ff, fff, ffff in zip(x, f0, f1, f2):
        assert abs(ff - j0(xx)) / ff < 1e-5
        assert abs(fff - j1(xx)) / fff < 1e-5
        assert abs(ffff - j2(xx)) / ffff < 1e-5
Example #3
0
def tst_sph_bessel_j1():
  x = flex.double( range(1,200) )/199.0+7.5
  f1 = math.spherical_bessel_array(1,x)
  for xx,ff in zip(x,f1):
    assert abs( ff-j1(xx) )/abs(ff) < 1e-5
    #print xx, ff, j1(xx), abs( ff-j1(xx) )/abs(ff)
  print "OK"
Example #4
0
def tst_sph_bessel_j1():
    x = flex.double(range(1, 200)) / 199.0 + 7.5
    f1 = math.spherical_bessel_array(1, x)
    for xx, ff in zip(x, f1):
        assert abs(ff - j1(xx)) / abs(ff) < 1e-5
        #print xx, ff, j1(xx), abs( ff-j1(xx) )/abs(ff)
    print "OK"
Example #5
0
def spherical_bessel_jn_test(write_output=False):
    from scitbx.math import spherical_bessel_array
    from cudatbx.math.special_functions import cuda_spherical_bessel_jn

    z_size = 10000
    z_max = 200.0
    order = 50
    z = flex.double(z_size)
    for i in xrange(z_size):
        z[i] = z_max * (i + 1) / z_size

    dt = [0.0, 0.0]

    # GPU
    t0 = time.time()
    jn_gpu = cuda_spherical_bessel_jn(order, z)
    t1 = time.time()
    dt[0] = t1 - t0
    if write_output:
        f = open('jn_gpu.dat', 'w')
        for i in xrange(order + 1):
            for j in xrange(z_size):
                f.write('%f %f\n' % (z[j], jn_gpu[i * z_size + j]))
            f.write('&\n')
        f.close()

    # CPU
    jn_cpu = [None for i in xrange(order + 1)]
    t0 = time.time()
    for n in xrange(order + 1):
        jn_cpu[n] = spherical_bessel_array(n, z)
    t1 = time.time()
    dt[1] = t1 - t0
    if write_output:
        f = open('jn_cpu.dat', 'w')
        for i in xrange(order + 1):
            for j in xrange(z_size):
                f.write('%f %f\n' % (z[j], jn_cpu[i][j]))
            f.write('&\n')
        f.close()

    # difference
    d_jn = [None for i in xrange(order + 1)]
    for n in xrange(order + 1):
        d_jn[n] = jn_cpu[n] - jn_gpu[n * z_size:n * z_size + z_size]
        for i in xrange(z_size):
            assert (approx_equal(d_jn[n][i] * d_jn[n][i], 0.0, eps=1.0e-6))
    if write_output:
        f = open('d_jn.dat', 'w')
        for i in xrange(order + 1):
            for j in xrange(z_size):
                f.write('%f %f\n' % (z[j], d_jn[i][j]))
            f.write('&\n')
        f.close()

    return dt
def spherical_bessel_jn_test(write_output = False):
  from scitbx.math import spherical_bessel_array
  from cudatbx.math.special_functions import cuda_spherical_bessel_jn

  z_size = 10000
  z_max = 200.0
  order = 50
  z = flex.double(z_size)
  for i in xrange(z_size):
    z[i] = z_max * (i+1)/z_size

  dt = [0.0,0.0]

  # GPU
  t0 = time.time()
  jn_gpu = cuda_spherical_bessel_jn(order,z)
  t1 = time.time()
  dt[0] = t1 - t0
  if write_output:
    f = open('jn_gpu.dat','w')
    for i in xrange(order+1):
      for j in xrange(z_size):
        f.write('%f %f\n'%(z[j],jn_gpu[i*z_size + j]))
      f.write('&\n')
    f.close()

  # CPU
  jn_cpu = [ None for i in xrange(order+1) ]
  t0 = time.time()
  for n in xrange(order+1):
    jn_cpu[n] = spherical_bessel_array(n,z)
  t1 = time.time()
  dt[1] = t1 - t0
  if write_output:
    f = open('jn_cpu.dat','w')
    for i in xrange(order+1):
      for j in xrange(z_size):
        f.write('%f %f\n'%(z[j],jn_cpu[i][j]))
      f.write('&\n')
    f.close()

  # difference
  d_jn = [ None for i in xrange(order+1) ]
  for n in xrange(order+1):
    d_jn[n] = jn_cpu[n] - jn_gpu[n*z_size:n*z_size + z_size]
    for i in xrange(z_size):
      assert( approx_equal(d_jn[n][i]*d_jn[n][i],0.0,eps=1.0e-6) )
  if write_output:
    f = open('d_jn.dat','w')
    for i in xrange(order+1):
      for j in xrange(z_size):
        f.write('%f %f\n'%(z[j],d_jn[i][j]))
      f.write('&\n')
    f.close()

  return dt
def tst_sph_zeroes(l, n):
    z = math.sph_bessel_j_zeroes(l, n)
    fz = math.spherical_bessel_array(l, z)
    for ff in fz:
        assert abs(ff) < 1e-8
Example #8
0
def exercise_interfaces():
  assert approx_equal(math.spherical_bessel(1, 2), 0.43539777498)
  assert approx_equal(math.spherical_bessel_array(1, flex.double([2])),
    [0.43539777498])
Example #9
0
def exercise_interfaces():
    assert approx_equal(math.spherical_bessel(1, 2), 0.43539777498)
    assert approx_equal(math.spherical_bessel_array(1, flex.double([2])),
                        [0.43539777498])