Skip to content

Move tests to root dir. Minor setup refactoring #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions arrayfire/tests/simple/__init__.py

This file was deleted.

27 changes: 0 additions & 27 deletions arrayfire/tests/simple_tests.py

This file was deleted.

27 changes: 27 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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 = [email protected]
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
19 changes: 4 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


#######################################################
# Copyright (c) 2015, ArrayFire
Expand All @@ -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="[email protected]",
name="arrayfire",
version="3.6.20181017",
description="Python bindings for ArrayFire",
license="BSD",
url="http://arrayfire.com",
packages=find_packages()
)
setup()
2 changes: 2 additions & 0 deletions arrayfire/tests/__init__.py → tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
Expand Down
23 changes: 14 additions & 9 deletions arrayfire/tests/__main__.py → tests/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
Expand All @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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")
Expand Down
44 changes: 44 additions & 0 deletions tests/simple/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
]
23 changes: 14 additions & 9 deletions arrayfire/tests/simple/_util.py → tests/simple/_util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
35 changes: 19 additions & 16 deletions arrayfire/tests/simple/algorithm.py → tests/simple/algorithm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python

#######################################################
# Copyright (c) 2015, ArrayFire
# All rights reserved.
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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
Loading