diff --git a/arrayfire/tests/simple/__init__.py b/arrayfire/tests/simple/__init__.py deleted file mode 100644 index 26ed88961..000000000 --- a/arrayfire/tests/simple/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -####################################################### -# Copyright (c) 2015, ArrayFire -# All rights reserved. -# -# This file is distributed under 3-clause BSD license. -# The complete license agreement can be obtained at: -# http://arrayfire.com/licenses/BSD-3-Clause -######################################################## - -from .algorithm import * -from .arith import * -from .array_test import * -from .blas import * -from .data import * -from .device import * -from .image import * -from .index import * -from .interop import * -from .lapack import * -from .signal import * -from .statistics import * -from .random import * -from .sparse import * -from ._util import tests diff --git a/arrayfire/tests/simple_tests.py b/arrayfire/tests/simple_tests.py deleted file mode 100755 index 603ae9f37..000000000 --- a/arrayfire/tests/simple_tests.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/python - -####################################################### -# Copyright (c) 2015, ArrayFire -# All rights reserved. -# -# This file is distributed under 3-clause BSD license. -# The complete license agreement can be obtained at: -# http://arrayfire.com/licenses/BSD-3-Clause -######################################################## - -from __future__ import absolute_import - -from . import simple -import sys - -if __name__ == "__main__": - verbose = False - - if len(sys.argv) > 1: - verbose = int(sys.argv[1]) - - test_list = None - if len(sys.argv) > 2: - test_list = sys.argv[2:] - - simple.tests.run(test_list, verbose) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..6b0fb031d --- /dev/null +++ b/setup.cfg @@ -0,0 +1,27 @@ +[metadata] +name = arrayfire +version = 3.6.20181017 +description = Python bindings for ArrayFire +licence = BSD +long_description = file: README.md +maintainer = Pavan Yalamanchili +maintainer_email = contact@pavanky.com +url = http://arrayfire.com +classifiers = + Programming Language :: Python + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + +[options] +packages = find: + +[options.packages.find] +exclude = + examples + tests + +[flake8] +application-import-names = arrayfire +import-order-style = pep8 +max-line-length = 119 diff --git a/setup.py b/setup.py index 92900cc90..e4d485c30 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python ####################################################### # Copyright (c) 2015, ArrayFire @@ -9,19 +9,8 @@ # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## -from setuptools import setup, find_packages -#from __af_version__ import full_version +# TODO: Look for af libraries during setup -#TODO: -#1) Look for af libraries during setup +from setuptools import setup -setup( - author="Pavan Yalamanchili", - author_email="contact@pavanky.com", - name="arrayfire", - version="3.6.20181017", - description="Python bindings for ArrayFire", - license="BSD", - url="http://arrayfire.com", - packages=find_packages() -) +setup() diff --git a/arrayfire/tests/__init__.py b/tests/__init__.py similarity index 93% rename from arrayfire/tests/__init__.py rename to tests/__init__.py index be7669881..24e9ac759 100644 --- a/arrayfire/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. diff --git a/arrayfire/tests/__main__.py b/tests/__main__.py similarity index 75% rename from arrayfire/tests/__main__.py rename to tests/__main__.py index 468396566..6bed94278 100644 --- a/arrayfire/tests/__main__.py +++ b/tests/__main__.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -10,35 +12,38 @@ from __future__ import absolute_import import sys -from .simple_tests import * + +from . import simple tests = {} tests['simple'] = simple.tests + def assert_valid(name, name_list, name_str): is_valid = any([name == val for val in name_list]) - if not is_valid: - err_str = "The first argument needs to be a %s name\n" % name_str - err_str += "List of supported %ss: %s" % (name_str, str(list(name_list))) - raise RuntimeError(err_str) + if is_valid: + return + err_str = "The first argument needs to be a %s name\n" % name_str + err_str += "List of supported %ss: %s" % (name_str, str(list(name_list))) + raise RuntimeError(err_str) -if __name__ == "__main__": +if __name__ == "__main__": module_name = None num_args = len(sys.argv) - if (num_args > 1): + if num_args > 1: module_name = sys.argv[1].lower() assert_valid(sys.argv[1].lower(), tests.keys(), "module") - if (module_name is None): + if module_name is None: for name in tests: tests[name].run() else: test = tests[module_name] test_list = None - if (num_args > 2): + if num_args > 2: test_list = sys.argv[2:] for test_name in test_list: assert_valid(test_name.lower(), test.keys(), "test") diff --git a/tests/simple/__init__.py b/tests/simple/__init__.py new file mode 100644 index 000000000..4950136e3 --- /dev/null +++ b/tests/simple/__init__.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +####################################################### +# Copyright (c) 2015, ArrayFire +# All rights reserved. +# +# This file is distributed under 3-clause BSD license. +# The complete license agreement can be obtained at: +# http://arrayfire.com/licenses/BSD-3-Clause +######################################################## + +from ._util import tests +from .algorithm import simple_algorithm +from .arith import simple_arith +from .array_test import simple_array +from .blas import simple_blas +from .data import simple_data +from .device import simple_device +from .image import simple_image +from .index import simple_index +from .interop import simple_interop +from .lapack import simple_lapack +from .random import simple_random +from .signal import simple_signal +from .sparse import simple_sparse +from .statistics import simple_statistics + +__all__ = [ + "tests", + "simple_algorithm", + "simple_arith", + "simple_array", + "simple_blas", + "simple_data", + "simple_device", + "simple_image", + "simple_index", + "simple_interop", + "simple_lapack", + "simple_random", + "simple_signal", + "simple_sparse", + "simple_statistics" +] diff --git a/arrayfire/tests/simple/_util.py b/tests/simple/_util.py similarity index 88% rename from arrayfire/tests/simple/_util.py rename to tests/simple/_util.py index cda7c84a8..2275cf2fc 100644 --- a/arrayfire/tests/simple/_util.py +++ b/tests/simple/_util.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -6,13 +8,13 @@ # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## -import traceback + import logging -import arrayfire as af import sys +import traceback -class _simple_test_dict(dict): +class _simple_test_dict(dict): def __init__(self): self.print_str = "Simple %16s: %s" self.failed = False @@ -21,7 +23,7 @@ def __init__(self): def run(self, name_list=None, verbose=False): test_list = name_list if name_list is not None else self.keys() for key in test_list: - self.print_log = '' + self.print_log = "" try: test = self[key] except KeyError: @@ -31,27 +33,30 @@ def run(self, name_list=None, verbose=False): try: test(verbose) print(self.print_str % (key, "PASSED")) - except Exception as e: + except Exception: print(self.print_str % (key, "FAILED")) self.failed = True - if (not verbose): + if not verbose: print(tests.print_log) logging.error(traceback.format_exc()) - if (self.failed): + if self.failed: sys.exit(1) + tests = _simple_test_dict() + def print_func(verbose): def print_func_impl(*args): - _print_log = '' + _print_log = "" for arg in args: _print_log += str(arg) + '\n' - if (verbose): + if verbose: print(_print_log) tests.print_log += _print_log return print_func_impl + def display_func(verbose): return print_func(verbose) diff --git a/arrayfire/tests/simple/algorithm.py b/tests/simple/algorithm.py similarity index 74% rename from arrayfire/tests/simple/algorithm.py rename to tests/simple/algorithm.py index 5528da3b0..5b40d6916 100644 --- a/arrayfire/tests/simple/algorithm.py +++ b/tests/simple/algorithm.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,18 +10,19 @@ ######################################################## import arrayfire as af + from . import _util -def simple_algorithm(verbose = False): + +def simple_algorithm(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) + print_func = _util.print_func(verbose) a = af.randu(3, 3) k = af.constant(1, 3, 3, dtype=af.Dtype.u32) af.eval(k) - print_func(af.sum(a), af.product(a), af.min(a), af.max(a), - af.count(a), af.any_true(a), af.all_true(a)) + print_func(af.sum(a), af.product(a), af.min(a), af.max(a), af.count(a), af.any_true(a), af.all_true(a)) display_func(af.sum(a, 0)) display_func(af.sum(a, 1)) @@ -58,27 +60,27 @@ def simple_algorithm(verbose = False): b = (a > 0.1) * a c = (a > 0.4) * a d = b / c - print_func(af.sum(d)); - print_func(af.sum(d, nan_val=0.0)); - display_func(af.sum(d, dim=0, nan_val=0.0)); + print_func(af.sum(d)) + print_func(af.sum(d, nan_val=0.0)) + display_func(af.sum(d, dim=0, nan_val=0.0)) - val,idx = af.sort_index(a, is_ascending=True) + val, idx = af.sort_index(a, is_ascending=True) display_func(val) display_func(idx) - val,idx = af.sort_index(a, is_ascending=False) + val, idx = af.sort_index(a, is_ascending=False) display_func(val) display_func(idx) - b = af.randu(3,3) - keys,vals = af.sort_by_key(a, b, is_ascending=True) + b = af.randu(3, 3) + keys, vals = af.sort_by_key(a, b, is_ascending=True) display_func(keys) display_func(vals) - keys,vals = af.sort_by_key(a, b, is_ascending=False) + keys, vals = af.sort_by_key(a, b, is_ascending=False) display_func(keys) display_func(vals) - c = af.randu(5,1) - d = af.randu(5,1) + c = af.randu(5, 1) + d = af.randu(5, 1) cc = af.set_unique(c, is_sorted=False) dd = af.set_unique(af.sort(d), is_sorted=True) display_func(cc) @@ -90,4 +92,5 @@ def simple_algorithm(verbose = False): display_func(af.set_intersect(cc, cc, is_unique=True)) display_func(af.set_intersect(cc, cc, is_unique=False)) -_util.tests['algorithm'] = simple_algorithm + +_util.tests["algorithm"] = simple_algorithm diff --git a/arrayfire/tests/simple/arith.py b/tests/simple/arith.py similarity index 89% rename from arrayfire/tests/simple/arith.py rename to tests/simple/arith.py index 84c291aec..306b93fff 100644 --- a/arrayfire/tests/simple/arith.py +++ b/tests/simple/arith.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,13 +10,14 @@ ######################################################## import arrayfire as af + from . import _util -def simple_arith(verbose = False): + +def simple_arith(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) - a = af.randu(3,3) + a = af.randu(3, 3) b = af.constant(4, 3, 3) display_func(a) display_func(b) @@ -29,7 +31,6 @@ def simple_arith(verbose = False): display_func(a + 2) display_func(3 + a) - c = a - b d = a d -= b @@ -99,7 +100,7 @@ def simple_arith(verbose = False): display_func(a == 0.5) display_func(0.5 == a) - a = af.randu(3,3,dtype=af.Dtype.u32) + a = af.randu(3, 3, dtype=af.Dtype.u32) b = af.constant(4, 3, 3, dtype=af.Dtype.u32) display_func(a & b) @@ -132,17 +133,17 @@ def simple_arith(verbose = False): display_func(a) display_func(af.cast(a, af.Dtype.c32)) - display_func(af.maxof(a,b)) - display_func(af.minof(a,b)) + display_func(af.maxof(a, b)) + display_func(af.minof(a, b)) display_func(af.clamp(a, 0, 1)) display_func(af.clamp(a, 0, b)) display_func(af.clamp(a, b, 1)) - display_func(af.rem(a,b)) + display_func(af.rem(a, b)) - a = af.randu(3,3) - 0.5 - b = af.randu(3,3) - 0.5 + a = af.randu(3, 3) - 0.5 + b = af.randu(3, 3) - 0.5 display_func(af.abs(a)) display_func(af.arg(a)) @@ -161,7 +162,7 @@ def simple_arith(verbose = False): display_func(af.atan2(a, b)) c = af.cplx(a) - d = af.cplx(a,b) + d = af.cplx(a, b) display_func(c) display_func(d) display_func(af.real(d)) @@ -193,8 +194,8 @@ def simple_arith(verbose = False): display_func(af.sqrt(a)) display_func(af.cbrt(a)) - a = af.round(5 * af.randu(3,3) - 1) - b = af.round(5 * af.randu(3,3) - 1) + a = af.round(5 * af.randu(3, 3) - 1) + b = af.round(5 * af.randu(3, 3) - 1) display_func(af.factorial(a)) display_func(af.tgamma(a)) @@ -205,7 +206,7 @@ def simple_arith(verbose = False): a = af.randu(5, 1) b = af.randu(1, 5) - c = af.broadcast(lambda x,y: x+y, a, b) + c = af.broadcast(lambda x, y: x+y, a, b) display_func(a) display_func(b) display_func(c) @@ -216,4 +217,5 @@ def test_add(aa, bb): display_func(test_add(a, b)) -_util.tests['arith'] = simple_arith + +_util.tests["arith"] = simple_arith diff --git a/arrayfire/tests/simple/array_test.py b/tests/simple/array_test.py similarity index 88% rename from arrayfire/tests/simple/array_test.py rename to tests/simple/array_test.py index 0c6ab5262..b2a787940 100644 --- a/arrayfire/tests/simple/array_test.py +++ b/tests/simple/array_test.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -8,13 +9,16 @@ # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## -import arrayfire as af import array as host + +import arrayfire as af + from . import _util + def simple_array(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) + print_func = _util.print_func(verbose) a = af.Array([1, 2, 3]) display_func(a) @@ -30,15 +34,14 @@ def simple_array(verbose=False): print_func(a.is_complex(), a.is_real(), a.is_double(), a.is_single()) print_func(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool()) - - a = af.Array(host.array('i', [4, 5, 6])) + a = af.Array(host.array("i", [4, 5, 6])) display_func(a) print_func(a.elements(), a.type(), a.dims(), a.numdims()) print_func(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row()) print_func(a.is_complex(), a.is_real(), a.is_double(), a.is_single()) print_func(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool()) - a = af.Array(host.array('I', [7, 8, 9] * 3), (3,3)) + a = af.Array(host.array("I", [7, 8, 9] * 3), (3, 3)) display_func(a) print_func(a.elements(), a.type(), a.dims(), a.numdims()) print_func(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row()) @@ -49,7 +52,7 @@ def simple_array(verbose=False): for n in range(a.elements()): print_func(c[n]) - c,s = a.to_ctype(True, True) + c, s = a.to_ctype(True, True) for n in range(a.elements()): print_func(c[n]) print_func(s) @@ -62,4 +65,5 @@ def simple_array(verbose=False): print_func(a.is_sparse()) -_util.tests['array'] = simple_array + +_util.tests["array"] = simple_array diff --git a/arrayfire/tests/simple/blas.py b/tests/simple/blas.py similarity index 56% rename from arrayfire/tests/simple/blas.py rename to tests/simple/blas.py index fd58d18d9..f04049a93 100644 --- a/arrayfire/tests/simple/blas.py +++ b/tests/simple/blas.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,19 +10,21 @@ ######################################################## import arrayfire as af + from . import _util + def simple_blas(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) - a = af.randu(5,5) - b = af.randu(5,5) + a = af.randu(5, 5) + b = af.randu(5, 5) + + display_func(af.matmul(a, b)) + display_func(af.matmul(a, b, af.MATPROP.TRANS)) + display_func(af.matmul(a, b, af.MATPROP.NONE, af.MATPROP.TRANS)) - display_func(af.matmul(a,b)) - display_func(af.matmul(a,b,af.MATPROP.TRANS)) - display_func(af.matmul(a,b,af.MATPROP.NONE, af.MATPROP.TRANS)) + b = af.randu(5, 1) + display_func(af.dot(b, b)) - b = af.randu(5,1) - display_func(af.dot(b,b)) -_util.tests['blas'] = simple_blas +_util.tests["blas"] = simple_blas diff --git a/arrayfire/tests/simple/data.py b/tests/simple/data.py similarity index 72% rename from arrayfire/tests/simple/data.py rename to tests/simple/data.py index 86b900baf..d80f9e125 100644 --- a/arrayfire/tests/simple/data.py +++ b/tests/simple/data.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,20 +10,21 @@ ######################################################## import arrayfire as af + from . import _util + def simple_data(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) - display_func(af.constant(100, 3,3, dtype=af.Dtype.f32)) - display_func(af.constant(25, 3,3, dtype=af.Dtype.c32)) - display_func(af.constant(2**50, 3,3, dtype=af.Dtype.s64)) - display_func(af.constant(2+3j, 3,3)) - display_func(af.constant(3+5j, 3,3, dtype=af.Dtype.c32)) + display_func(af.constant(100, 3, 3, dtype=af.Dtype.f32)) + display_func(af.constant(25, 3, 3, dtype=af.Dtype.c32)) + display_func(af.constant(2**50, 3, 3, dtype=af.Dtype.s64)) + display_func(af.constant(2+3j, 3, 3)) + display_func(af.constant(3+5j, 3, 3, dtype=af.Dtype.c32)) display_func(af.range(3, 3)) - display_func(af.iota(3, 3, tile_dims=(2,2))) + display_func(af.iota(3, 3, tile_dims=(2, 2))) display_func(af.identity(3, 3, 1, 2, af.Dtype.b8)) display_func(af.identity(3, 3, dtype=af.Dtype.c32)) @@ -35,15 +37,14 @@ def simple_data(verbose=False): display_func(b) display_func(c) - display_func(af.diag(b, extract = False)) - display_func(af.diag(c, 1, extract = False)) + display_func(af.diag(b, extract=False)) + display_func(af.diag(c, 1, extract=False)) display_func(af.join(0, a, a)) display_func(af.join(1, a, a, a)) display_func(af.tile(a, 2, 2)) - display_func(af.reorder(a, 1, 0)) display_func(af.shift(a, -1, 1)) @@ -61,7 +62,7 @@ def simple_data(verbose=False): display_func(af.upper(a, False)) display_func(af.upper(a, True)) - a = af.randu(5,5) + a = af.randu(5, 5) display_func(af.transpose(a)) af.transpose_inplace(a) display_func(a) @@ -71,4 +72,5 @@ def simple_data(verbose=False): af.replace(a, a > 0.3, -0.3) display_func(a) -_util.tests['data'] = simple_data + +_util.tests["data"] = simple_data diff --git a/arrayfire/tests/simple/device.py b/tests/simple/device.py similarity index 79% rename from arrayfire/tests/simple/device.py rename to tests/simple/device.py index 279fa3168..f677c5e2a 100644 --- a/arrayfire/tests/simple/device.py +++ b/tests/simple/device.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,11 +10,13 @@ ######################################################## import arrayfire as af + from . import _util + def simple_device(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) + print_func = _util.print_func(verbose) print_func(af.device_info()) print_func(af.get_device_count()) print_func(af.is_dbl_supported()) @@ -35,19 +38,19 @@ def simple_device(verbose=False): a = af.randu(100, 100) af.sync(dev) mem_info = af.device_mem_info() - assert(mem_info['alloc']['buffers'] == 1 + mem_info_old['alloc']['buffers']) - assert(mem_info[ 'lock']['buffers'] == 1 + mem_info_old[ 'lock']['buffers']) + assert(mem_info["alloc"]["buffers"] == 1 + mem_info_old["alloc"]["buffers"]) + assert(mem_info["lock"]["buffers"] == 1 + mem_info_old["lock"]["buffers"]) af.set_device(curr_dev) - a = af.randu(10,10) + a = af.randu(10, 10) display_func(a) dev_ptr = af.get_device_ptr(a) print_func(dev_ptr) b = af.Array(src=dev_ptr, dims=a.dims(), dtype=a.dtype(), is_device=True) display_func(b) - c = af.randu(10,10) + c = af.randu(10, 10) af.lock_array(c) af.unlock_array(c) @@ -64,10 +67,11 @@ def simple_device(verbose=False): print_func(d) print_func(af.set_manual_eval_flag(True)) - assert(af.get_manual_eval_flag() == True) + assert(af.get_manual_eval_flag()) print_func(af.set_manual_eval_flag(False)) - assert(af.get_manual_eval_flag() == False) + assert(not af.get_manual_eval_flag()) display_func(af.is_locked_array(a)) -_util.tests['device'] = simple_device + +_util.tests["device"] = simple_device diff --git a/arrayfire/tests/simple/image.py b/tests/simple/image.py similarity index 84% rename from arrayfire/tests/simple/image.py rename to tests/simple/image.py index 9c7887ebb..1489e94dc 100644 --- a/arrayfire/tests/simple/image.py +++ b/tests/simple/image.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,23 +10,24 @@ ######################################################## import arrayfire as af + from . import _util -def simple_image(verbose = False): + +def simple_image(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) a = 10 * af.randu(6, 6) - a3 = 10 * af.randu(5,5,3) + a3 = 10 * af.randu(5, 5, 3) - dx,dy = af.gradient(a) + dx, dy = af.gradient(a) display_func(dx) display_func(dy) display_func(af.resize(a, scale=0.5)) display_func(af.resize(a, odim0=8, odim1=8)) - t = af.randu(3,2) + t = af.randu(3, 2) display_func(af.transform(a, t)) display_func(af.rotate(a, 3.14)) display_func(af.translate(a, 1, 1)) @@ -50,7 +52,7 @@ def simple_image(verbose = False): display_func(af.regions(af.round(a) > 3)) - dx,dy = af.sobel_derivatives(a) + dx, dy = af.sobel_derivatives(a) display_func(dx) display_func(dy) display_func(af.sobel_filter(a)) @@ -66,7 +68,7 @@ def simple_image(verbose = False): display_func(af.color_space(a, af.CSPACE.RGB, af.CSPACE.GRAY)) - a = af.randu(6,6) + a = af.randu(6, 6) b = af.unwrap(a, 2, 2, 2, 2) c = af.wrap(b, 6, 6, 2, 2, 2, 2) display_func(a) @@ -74,13 +76,14 @@ def simple_image(verbose = False): display_func(c) display_func(af.sat(a)) - a = af.randu(10,10,3) + a = af.randu(10, 10, 3) display_func(af.rgb2ycbcr(a)) display_func(af.ycbcr2rgb(a)) a = af.randu(10, 10) - b = af.canny(a, low_threshold = 0.2, high_threshold = 0.8) + b = af.canny(a, low_threshold=0.2, high_threshold=0.8) display_func(af.anisotropic_diffusion(a, 0.125, 1.0, 64, af.FLUX.QUADRATIC, af.DIFFUSION.GRAD)) -_util.tests['image'] = simple_image + +_util.tests["image"] = simple_image diff --git a/arrayfire/tests/simple/index.py b/tests/simple/index.py similarity index 69% rename from arrayfire/tests/simple/index.py rename to tests/simple/index.py index 7ebde6eb3..a0b0cc757 100644 --- a/arrayfire/tests/simple/index.py +++ b/tests/simple/index.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -7,14 +8,17 @@ # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## + +import array as host + import arrayfire as af from arrayfire import ParallelRange -import array as host + from . import _util + def simple_index(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) a = af.randu(5, 5) display_func(a) b = af.Array(a) @@ -22,16 +26,16 @@ def simple_index(verbose=False): c = a.copy() display_func(c) - display_func(a[0,0]) + display_func(a[0, 0]) display_func(a[0]) display_func(a[:]) - display_func(a[:,:]) - display_func(a[0:3,]) - display_func(a[-2:-1,-1]) + display_func(a[:, :]) + display_func(a[0:3, ]) + display_func(a[-2:-1, -1]) display_func(a[0:5]) display_func(a[0:5:2]) - idx = af.Array(host.array('i', [0, 3, 2])) + idx = af.Array(host.array("i", [0, 3, 2])) display_func(idx) aa = a[idx] display_func(aa) @@ -40,42 +44,42 @@ def simple_index(verbose=False): display_func(a) a[0] = af.randu(1, 5) display_func(a) - a[:] = af.randu(5,5) + a[:] = af.randu(5, 5) display_func(a) - a[:,-1] = af.randu(5,1) + a[:, -1] = af.randu(5, 1) display_func(a) a[0:5:2] = af.randu(3, 5) display_func(a) - a[idx, idx] = af.randu(3,3) + a[idx, idx] = af.randu(3, 3) display_func(a) - - a = af.randu(5,1) - b = af.randu(5,1) + a = af.randu(5, 1) + b = af.randu(5, 1) display_func(a) display_func(b) - for ii in ParallelRange(1,3): + for ii in ParallelRange(1, 3): a[ii] = b[ii] display_func(a) - for ii in ParallelRange(2,5): + for ii in ParallelRange(2, 5): b[ii] = 2 display_func(b) - a = af.randu(3,2) + a = af.randu(3, 2) rows = af.constant(0, 1, dtype=af.Dtype.s32) - b = a[:,rows] + b = a[:, rows] display_func(b) for r in rows: display_func(r) - display_func(b[:,r]) + display_func(b[:, r]) a = af.randu(3) c = af.randu(3) - b = af.constant(1,3,dtype=af.Dtype.b8) + b = af.constant(1, 3, dtype=af.Dtype.b8) display_func(a) a[b] = c display_func(a) -_util.tests['index'] = simple_index + +_util.tests["index"] = simple_index diff --git a/arrayfire/tests/simple/interop.py b/tests/simple/interop.py similarity index 68% rename from arrayfire/tests/simple/interop.py rename to tests/simple/interop.py index ee924c6fa..f07e6a770 100644 --- a/arrayfire/tests/simple/interop.py +++ b/tests/simple/interop.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,72 +10,73 @@ ######################################################## import arrayfire as af + from . import _util -def simple_interop(verbose = False): + +def simple_interop(verbose=False): if af.AF_NUMPY_FOUND: import numpy as np n = np.random.random((5,)) a = af.to_array(n) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) n2[:] = 0 a.to_ndarray(n2) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3)) + n = np.random.random((5, 3)) a = af.to_array(n) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) n2[:] = 0 a.to_ndarray(n2) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3,2)) + n = np.random.random((5, 3, 2)) a = af.to_array(n) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) n2[:] = 0 a.to_ndarray(n2) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3,2,2)) + n = np.random.random((5, 3, 2, 2)) a = af.to_array(n) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) n2[:] = 0 a.to_ndarray(n2) - assert((n==n2).all()) + assert((n == n2).all()) - if af.AF_PYCUDA_FOUND and af.get_active_backend() == 'cuda': - import pycuda.autoinit + if af.AF_PYCUDA_FOUND and af.get_active_backend() == "cuda": import pycuda.gpuarray as cudaArray n = np.random.random((5,)) c = cudaArray.to_gpu(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3)) + n = np.random.random((5, 3)) c = cudaArray.to_gpu(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3,2)) + n = np.random.random((5, 3, 2)) c = cudaArray.to_gpu(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3,2,2)) + n = np.random.random((5, 3, 2, 2)) c = cudaArray.to_gpu(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - if af.AF_PYOPENCL_FOUND and af.backend.name() == 'opencl': - # This needs fixing upstream + if af.AF_PYOPENCL_FOUND and af.backend.name() == "opencl": + # TODO: This needs fixing upstream # https://github.com/arrayfire/arrayfire/issues/1728 # import pyopencl as cl @@ -107,33 +109,32 @@ def simple_interop(verbose = False): # assert((n==n2).all()) pass - if af.AF_NUMBA_FOUND and af.get_active_backend() == 'cuda': - - import numba + if af.AF_NUMBA_FOUND and af.get_active_backend() == "cuda": from numba import cuda n = np.random.random((5,)) c = cuda.to_device(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3)) + n = np.random.random((5, 3)) c = cuda.to_device(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3,2)) + n = np.random.random((5, 3, 2)) c = cuda.to_device(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) - n = np.random.random((5,3,2,2)) + n = np.random.random((5, 3, 2, 2)) c = cuda.to_device(n) a = af.to_array(c) n2 = np.array(a) - assert((n==n2).all()) + assert((n == n2).all()) + -_util.tests['interop'] = simple_interop +_util.tests["interop"] = simple_interop diff --git a/arrayfire/tests/simple/lapack.py b/tests/simple/lapack.py similarity index 78% rename from arrayfire/tests/simple/lapack.py rename to tests/simple/lapack.py index e3c3dbbb2..e27fb6bc0 100644 --- a/arrayfire/tests/simple/lapack.py +++ b/tests/simple/lapack.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -7,15 +8,18 @@ # The complete license agreement can be obtained at: # http://arrayfire.com/licenses/BSD-3-Clause ######################################################## + import arrayfire as af + from . import _util + def simple_lapack(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) - a = af.randu(5,5) + print_func = _util.print_func(verbose) + a = af.randu(5, 5) - l,u,p = af.lu(a) + l, u, p = af.lu(a) display_func(l) display_func(u) @@ -26,9 +30,9 @@ def simple_lapack(verbose=False): display_func(a) display_func(p) - a = af.randu(5,3) + a = af.randu(5, 3) - q,r,t = af.qr(a) + q, r, t = af.qr(a) display_func(q) display_func(r) @@ -39,16 +43,16 @@ def simple_lapack(verbose=False): display_func(a) a = af.randu(5, 5) - a = af.matmulTN(a, a.copy()) + 10 * af.identity(5,5) + a = af.matmulTN(a, a.copy()) + 10 * af.identity(5, 5) - R,info = af.cholesky(a) + R, info = af.cholesky(a) display_func(R) print_func(info) af.cholesky_inplace(a) display_func(a) - a = af.randu(5,5) + a = af.randu(5, 5) ai = af.inverse(a) display_func(a) @@ -74,11 +78,12 @@ def simple_lapack(verbose=False): print_func(af.norm(a, af.NORM.MATRIX_INF)) print_func(af.norm(a, af.NORM.MATRIX_L_PQ, 1, 1)) - a = af.randu(10,10) + a = af.randu(10, 10) display_func(a) - u,s,vt = af.svd(a) + u, s, vt = af.svd(a) display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt)) - u,s,vt = af.svd_inplace(a) + u, s, vt = af.svd_inplace(a) display_func(af.matmul(af.matmul(u, af.diag(s, 0, False)), vt)) -_util.tests['lapack'] = simple_lapack + +_util.tests["lapack"] = simple_lapack diff --git a/arrayfire/tests/simple/random.py b/tests/simple/random.py similarity index 91% rename from arrayfire/tests/simple/random.py rename to tests/simple/random.py index 544389836..5152cb4e0 100644 --- a/arrayfire/tests/simple/random.py +++ b/tests/simple/random.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,11 +10,12 @@ ######################################################## import arrayfire as af + from . import _util + def simple_random(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) display_func(af.randu(3, 3, 1, 2)) display_func(af.randu(3, 3, 1, 2, af.Dtype.b8)) @@ -35,4 +37,5 @@ def simple_random(verbose=False): engine.set_seed(100) assert(engine.get_seed() == 100) -_util.tests['random'] = simple_random + +_util.tests["random"] = simple_random diff --git a/arrayfire/tests/simple/signal.py b/tests/simple/signal.py similarity index 89% rename from arrayfire/tests/simple/signal.py rename to tests/simple/signal.py index fa8036dc2..d92526488 100644 --- a/arrayfire/tests/simple/signal.py +++ b/tests/simple/signal.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,24 +10,25 @@ ######################################################## import arrayfire as af + from . import _util + def simple_signal(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) signal = af.randu(10) - x_new = af.randu(10) + x_new = af.randu(10) x_orig = af.randu(10) - display_func(af.approx1(signal, x_new, xp = x_orig)) + display_func(af.approx1(signal, x_new, xp=x_orig)) signal = af.randu(3, 3) - x_new = af.randu(3, 3) + x_new = af.randu(3, 3) x_orig = af.randu(3, 3) - y_new = af.randu(3, 3) + y_new = af.randu(3, 3) y_orig = af.randu(3, 3) - display_func(af.approx2(signal, x_new, y_new, xp = x_orig, yp = y_orig)) + display_func(af.approx2(signal, x_new, y_new, xp=x_orig, yp=y_orig)) a = af.randu(8, 1) display_func(a) @@ -106,7 +108,6 @@ def simple_signal(verbose=False): display_func(af.convolve(a, b)) display_func(af.fft_convolve(a, b)) - b = af.randu(3, 1) x = af.randu(10, 1) a = af.randu(2, 1) @@ -117,4 +118,5 @@ def simple_signal(verbose=False): display_func(af.medfilt2(a)) display_func(af.medfilt(a)) -_util.tests['signal'] = simple_signal + +_util.tests["signal"] = simple_signal diff --git a/arrayfire/tests/simple/sparse.py b/tests/simple/sparse.py similarity index 88% rename from arrayfire/tests/simple/sparse.py rename to tests/simple/sparse.py index 89315dfb1..bda87dfb7 100644 --- a/arrayfire/tests/simple/sparse.py +++ b/tests/simple/sparse.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,11 +10,13 @@ ######################################################## import arrayfire as af + from . import _util + def simple_sparse(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) + print_func = _util.print_func(verbose) dd = af.randu(5, 5) ds = dd * (dd > 0.5) @@ -25,4 +28,5 @@ def simple_sparse(verbose=False): print_func(af.sparse_get_nnz(sp)) print_func(af.sparse_get_storage(sp)) -_util.tests['sparse'] = simple_sparse + +_util.tests["sparse"] = simple_sparse diff --git a/arrayfire/tests/simple/statistics.py b/tests/simple/statistics.py similarity index 82% rename from arrayfire/tests/simple/statistics.py rename to tests/simple/statistics.py index d7d5a63d4..2815af335 100644 --- a/arrayfire/tests/simple/statistics.py +++ b/tests/simple/statistics.py @@ -1,4 +1,5 @@ -#!/usr/bin/python +#!/usr/bin/env python + ####################################################### # Copyright (c) 2015, ArrayFire # All rights reserved. @@ -9,11 +10,13 @@ ######################################################## import arrayfire as af + from . import _util + def simple_statistics(verbose=False): display_func = _util.display_func(verbose) - print_func = _util.print_func(verbose) + print_func = _util.print_func(verbose) a = af.randu(5, 5) b = af.randu(5, 5) @@ -47,10 +50,11 @@ def simple_statistics(verbose=False): data = af.iota(5, 3) k = 3 dim = 0 - order = af.TOPK.DEFAULT # defaults to af.TOPK.MAX - assert(dim == 0) # topk currently supports first dim only - values,indices = af.topk(data, k, dim, order) + order = af.TOPK.DEFAULT # defaults to af.TOPK.MAX + assert(dim == 0) # topk currently supports first dim only + values, indices = af.topk(data, k, dim, order) display_func(values) display_func(indices) -_util.tests['statistics'] = simple_statistics + +_util.tests["statistics"] = simple_statistics