Exemplo n.º 1
0
def test_kmeans():
  n = 200
  d = 4
  X = np.random.randn(n*d).reshape(n,d)
  k = 2
  niters = 10
  assignments = np.random.randint(0, k, size = n)
  parakeet_C = parakeet_kmeans(X, k, niters, assignments)
  python_C = python_kmeans(X, k, niters, assignments)
  assert eq(parakeet_C.shape, python_C.shape), \
      "Got back wrong shape, expect %s but got %s" % \
      (python_C.shape, parakeet_C.shape)
  assert eq(parakeet_C, python_C), \
      "Expected %s but got %s" % (python_C, parakeet_C)
Exemplo n.º 2
0
def test_set_1d_step_slice_to_const():
    x = np.array([1,2,3,4,5,6]) 
    x2 = x.copy()
    idx = slice(2,4,2)
    y = 0
    x[idx] = y
    setidx(x2, idx, y)
    assert testing_helpers.eq(x, x2)
Exemplo n.º 3
0
def test_set_1d_negative_slice():
    x = np.array([1,2,3,4,5,6]) 
    x2 = x.copy()
    idx = slice(4,2,-1)
    y = [10, 20]
    x[idx] = y
    setidx(x2, idx, y)
    assert testing_helpers.eq(x, x2), "Expected %s but got %s" % (x, x2)
Exemplo n.º 4
0
def test_sqr_dist():
  z = a[0]
  def run_sqr_dist(c):
    return sqr_dist(z, c)
  par_rslt = parakeet.each(run_sqr_dist, a)
  py_rslt = np.array(map(run_sqr_dist, a))
  assert testing_helpers.eq(par_rslt, py_rslt), \
      "Expected %s but got %s" % (py_rslt, par_rslt)
Exemplo n.º 5
0
def test_black_scholes():
  x1 = (False, 10.0, 10.0, 2.0, 2.0, 2.0)
  x2 = (True, 10.0, 10.0, 2.0, 2.0, 2.0)
  xs = [x1, x2]
  for x in xs:
    par_rslt = black_scholes_parakeet(*x)
    py_rslt = black_scholes(*x)
    assert eq(par_rslt, py_rslt)
Exemplo n.º 6
0
def test_set_1d_simple_slice():
    x = np.array([1,2,3,4,5,6]) 
    x2 = x.copy()
    idx = slice(2,4)
    y = [10, 20]
    print x[idx]
    x[idx] = y
    setidx(x2, idx, y)
    assert testing_helpers.eq(x, x2), "Expected %s but got %s" % (x, x2)
Exemplo n.º 7
0
def test_rule30():
  output = init.copy()
  cur = init
  zero_array = np.array([0])
  indices = np.arange(1,size+1)
  for _ in range(size/2):
    extended = np.concatenate((zero_array, cur, zero_array))

    def run_rule30(i):
      return rule30(extended, i)
    parakeet_iter = parakeet.map(run_rule30, indices)
    cur = np.array(map(run_rule30, indices))
    assert eq(parakeet_iter, cur), \
       "Parakeet result (%s) didn't match Python result(%s)" % \
       (parakeet_iter, cur)
    output = np.vstack((output,cur))
Exemplo n.º 8
0
def test_rule30():
    output = init.copy()
    cur = init
    zero_array = np.array([0])
    indices = np.arange(1, size + 1)
    for _ in range(size / 2):
        extended = np.concatenate((zero_array, cur, zero_array))

        def run_rule30(i):
            return rule30(extended, i)

        parakeet_iter = parakeet.map(run_rule30, indices)
        cur = np.array(map(run_rule30, indices))
        assert eq(parakeet_iter, cur), \
           "Parakeet result (%s) didn't match Python result(%s)" % \
           (parakeet_iter, cur)
        output = np.vstack((output, cur))
Exemplo n.º 9
0
def test_add1():
  result = each(add11d, int_vec)
  expected = int_vec + 1
  assert testing_helpers.eq(result, expected), \
      "Expected %s, got %s" % (expected, result)
Exemplo n.º 10
0
def test_2d_reduce():
  par_rslt = reduce_2d(a)
  np_rslt = np.sum(a, 0)
  assert testing_helpers.eq(par_rslt, np_rslt), \
    "Expected %s but got %s" % (np_rslt, par_rslt)
Exemplo n.º 11
0
def test_avg2d():
    x = np.random.randn(20, 30)
    testing_helpers.eq(x.mean(), avg2d(x))
Exemplo n.º 12
0
def test_add1_external_map():
  parakeet_result = each(add1_scalar, ints_1d)
  python_result = ints_1d + 1
  assert eq(parakeet_result, python_result), \
         "Python %s != Parakeet %s" % (python_result, parakeet_result)
Exemplo n.º 13
0
def test_avg2d():
    x = np.random.randn(20, 30)
    testing_helpers.eq(x.mean(), avg2d(x))
Exemplo n.º 14
0
def test_add1():
    result = each(add11d, int_vec)
    expected = int_vec + 1
    assert testing_helpers.eq(result, expected), \
        "Expected %s, got %s" % (expected, result)
Exemplo n.º 15
0
def test_2d_reduce():
    par_rslt = reduce_2d(a)
    np_rslt = np.sum(a, 0)
    assert testing_helpers.eq(par_rslt, np_rslt), \
      "Expected %s but got %s" % (np_rslt, par_rslt)
Exemplo n.º 16
0
def test_identity():
  x = np.ones((1,1,2,1))
  def get_idx(idx):
    return x[idx]
  y = parakeet.imap(get_idx, x.shape)
  assert eq(x,y)
Exemplo n.º 17
0
def test_fprop():
  parakeet_result = fprop(network, X[0])
  print "Parakeet result", parakeet_result
  python_result = fprop_python(network, X[0])
  print "Python result", python_result
  assert testing_helpers.eq(parakeet_result, python_result)
Exemplo n.º 18
0
def test_fprop():
    parakeet_result = fprop(network, X[0])
    print "Parakeet result", parakeet_result
    python_result = fprop_python(network, X[0])
    print "Python result", python_result
    assert testing_helpers.eq(parakeet_result, python_result)