ptr_int_t = ptr_type(Int64) 
  assert ptr_int_t not in mutable_types, \
      "Didn't expect %s in lowered mutable types %s" % \
      (ptr_int_t, mutable_types)
  assert ptr_bool_t in mutable_types, \
      "Expected %s in lowered mutable_types %s" % (ptr_bool_t, mutable_types)

"""
# Removed this test when I made attributes immutable 
def f():
  x = slice(1, 2, 3)
  x.start = 10
  x.stop = 20
  y = slice(1,2,3)
  if 3 < y.step:
    y.step = y.step + 1
  else:
    y.step = 0

def test_mutable_slice():
  _, typed, _, _ =  testing_helpers.specialize_and_compile(f, [])
  mutable_types = mutability_analysis.find_mutable_types(typed)

  assert len(mutable_types) == 1, mutable_types
  lowered = lowering.apply(typed)
  mutable_types = mutability_analysis.find_mutable_types(lowered)
  assert len(mutable_types) == 1, mutable_types
"""
if __name__ == '__main__':
  run_local_tests()
示例#2
0
import numpy as np

from parakeet.testing_helpers import expect, run_local_tests


def create_const(x):
    return [x, x, x, x]


def test_create_const():
    expect(create_const, [1], np.array([1, 1, 1, 1]))
    expect(create_const, [1.0], np.array([1.0, 1.0, 1.0, 1.0]))
    expect(create_const, [True], np.array([True, True, True, True]))


def test_nested_2d():
    expect(create_const, [np.array([1, 2])],
           np.array([[1, 2], [1, 2], [1, 2], [1, 2]]))
    expect(create_const, [np.array([1.0, 2.0])],
           np.array([[1.0, 2.0], [1.0, 2.0], [1.0, 2.0], [1.0, 2.0]]))
    expect(
        create_const, [np.array([True, False])],
        np.array([[True, False], [True, False], [True, False], [True, False]]))


if __name__ == '__main__':
    run_local_tests()
示例#3
0
from parakeet import testing_helpers


def count_thresh_orig(values, thresh):
    n = 0
    for elt in values:
        n += elt < thresh
    return n


count_thresh = parakeet.jit(count_thresh_orig)


def np_thresh(values, thresh):
    return np.sum(values < thresh)


def par_thresh(values, thresh):
    return parakeet.sum(values < thresh)


def test_count_thresh():
    v = np.array([1.2, 1.4, 5.0, 2, 3])
    parakeet_result = count_thresh(v, 2.0)
    python_result = count_thresh_orig(v, 2.0)
    testing_helpers.expect(count_thresh, [v, 2.0], count_thresh_orig(v, 2.0))


if __name__ == '__main__':
    testing_helpers.run_local_tests()
示例#4
0
import numpy as np
from parakeet import each, testing_helpers

def add1(xi):
  return xi + 1

def add11d(x):
  return each(add1, x)

int_vec = np.arange(128, dtype=np.float).reshape(16,8)

def test_add1():
  result = each(add11d, int_vec)
  expected = int_vec + 1
  assert testing_helpers.eq(result, expected), \
      "Expected %s, got %s" % (expected, result)

if __name__ == '__main__':
  testing_helpers.run_local_tests()