Skip to content
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

Add black to pre-commit config #1449

Merged
merged 4 commits into from
Jun 21, 2023
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
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ repos:
- id: check-toml
- id: debug-statements
- id: destroyed-symlinks
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: ["--check", "--diff", "--color"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Pre-commit](https://github.com/IntelPython/dpnp/actions/workflows/pre-commit.yml/badge.svg?branch=master&event=push)](https://github.com/IntelPython/dpnp/actions/workflows/pre-commit.yml)
[![Conda package](https://github.com/IntelPython/dpnp/actions/workflows/conda-package.yml/badge.svg?branch=master&event=push)](https://github.com/IntelPython/dpnp/actions/workflows/conda-package.yml)
[![Coverage Status](https://coveralls.io/repos/github/IntelPython/dpnp/badge.svg?branch=master)](https://coveralls.io/github/IntelPython/dpnp?branch=master)
Expand Down
13 changes: 7 additions & 6 deletions benchmarks/benchmarks/bench_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
# but looks like first execution has additional overheads
# (need to be investigated)
class Elementwise(Benchmark):
executors = {'dpnp': dpnp, 'numpy': numpy}
params = [['dpnp', 'numpy'],
[2**16, 2**20, 2**24],
['float64', 'float32', 'int64', 'int32']
]
param_names = ['executor', 'size', 'dtype']
executors = {"dpnp": dpnp, "numpy": numpy}
params = [
["dpnp", "numpy"],
[2**16, 2**20, 2**24],
["float64", "float32", "int64", "int32"],
]
param_names = ["executor", "size", "dtype"]

def setup(self, executor, size, dtype):
self.np = self.executors[executor]
Expand Down
84 changes: 43 additions & 41 deletions benchmarks/benchmarks/bench_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@


class Eindot(Benchmark):
params = [[dpnp, numpy],
[16, 32, 64, 128, 256, 512, 1024],
['float64', 'float32', 'int64', 'int32']]
param_names = ['executor', 'size', 'dtype']
params = [
[dpnp, numpy],
[16, 32, 64, 128, 256, 512, 1024],
["float64", "float32", "int64", "int32"],
]
param_names = ["executor", "size", "dtype"]

def setup(self, np, size, dtype):
dt = getattr(np, dtype)
Expand Down Expand Up @@ -45,13 +47,13 @@ def time_dot_trans_atc_a(self, np, *args):
np.dot(self.atc, self.a)

def time_einsum_i_ij_j(self, np, *args):
np.einsum('i,ij,j', self.d, self.b, self.c)
np.einsum("i,ij,j", self.d, self.b, self.c)

def time_einsum_ij_jk_a_b(self, np, *args):
np.einsum('ij,jk', self.a, self.b)
np.einsum("ij,jk", self.a, self.b)

def time_einsum_ijk_jil_kl(self, np, *args):
np.einsum('ijk,jil->kl', self.a3, self.b3)
np.einsum("ijk,jil->kl", self.a3, self.b3)

def time_inner_trans_a_a(self, np, *args):
np.inner(self.a, self.a)
Expand Down Expand Up @@ -82,20 +84,19 @@ def time_tensordot_a_b_axes_1_0_0_1(self, np, *args):


class Linalg(Benchmark):
params = [[dpnp, numpy],
['svd', 'pinv', 'det', 'norm'],
TYPES1]
param_names = ['executor', 'op', 'type']
params = [[dpnp, numpy], ["svd", "pinv", "det", "norm"], TYPES1]
param_names = ["executor", "op", "type"]

def setup(self, np, op, typename):
np.seterr(all='ignore')
np.seterr(all="ignore")

self.func = getattr(np.linalg, op)

if op == 'cholesky':
if op == "cholesky":
# we need a positive definite
self.a = np.dot(get_squares_()[typename],
get_squares_()[typename].T)
self.a = np.dot(
get_squares_()[typename], get_squares_()[typename].T
)
else:
self.a = get_squares_()[typename]

Expand All @@ -111,37 +112,38 @@ def time_op(self, np, op, typename):

class Lstsq(Benchmark):
params = [dpnp, numpy]
param_names = ['executor']
param_names = ["executor"]

def setup(self, np):
self.a = get_squares_()['float64']
self.a = get_squares_()["float64"]
self.b = get_indexes_rand()[:100].astype(np.float64)

def time_numpy_linalg_lstsq_a__b_float64(self, np):
np.linalg.lstsq(self.a, self.b, rcond=-1)


# class Einsum(Benchmark):
# param_names = ['dtype']
# params = [[np.float64]]
# def setup(self, dtype):
# self.a = np.arange(2900, dtype=dtype)
# self.b = np.arange(3000, dtype=dtype)
# self.c = np.arange(24000, dtype=dtype).reshape(20, 30, 40)
# self.c1 = np.arange(1200, dtype=dtype).reshape(30, 40)
# self.d = np.arange(10000, dtype=dtype).reshape(10,100,10)

# #outer(a,b): trigger sum_of_products_contig_stride0_outcontig_two
# def time_einsum_outer(self, dtype):
# np.einsum("i,j", self.a, self.b, optimize=True)

# # multiply(a, b):trigger sum_of_products_contig_two
# def time_einsum_multiply(self, dtype):
# np.einsum("..., ...", self.c1, self.c , optimize=True)

# # sum and multiply:trigger sum_of_products_contig_stride0_outstride0_two
# def time_einsum_sum_mul(self, dtype):
# np.einsum(",i...->", 300, self.d, optimize=True)

# # sum and multiply:trigger sum_of_products_stride0_contig_outstride0_two
# def time_einsum_sum_mul2(self, dtype):
# np.einsum("i...,->", self.d, 300, optimize=True)
# param_names = ['dtype']
# params = [[np.float64]]
# def setup(self, dtype):
# self.a = np.arange(2900, dtype=dtype)
# self.b = np.arange(3000, dtype=dtype)
# self.c = np.arange(24000, dtype=dtype).reshape(20, 30, 40)
# self.c1 = np.arange(1200, dtype=dtype).reshape(30, 40)
# self.d = np.arange(10000, dtype=dtype).reshape(10,100,10)

# #outer(a,b): trigger sum_of_products_contig_stride0_outcontig_two
# def time_einsum_outer(self, dtype):
# np.einsum("i,j", self.a, self.b, optimize=True)

# # multiply(a, b):trigger sum_of_products_contig_two
# def time_einsum_multiply(self, dtype):
# np.einsum("..., ...", self.c1, self.c , optimize=True)

# # sum and multiply:trigger sum_of_products_contig_stride0_outstride0_two
# def time_einsum_sum_mul(self, dtype):
# np.einsum(",i...->", 300, self.d, optimize=True)

# # sum and multiply:trigger sum_of_products_stride0_contig_outstride0_two
# def time_einsum_sum_mul2(self, dtype):
# np.einsum("i...,->", self.d, 300, optimize=True)
6 changes: 3 additions & 3 deletions benchmarks/benchmarks/bench_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

# asv run --python=python --quick --bench Sample
class Sample(Benchmark):
executors = {'dpnp': dpnp, 'numpy': numpy}
params = [['dpnp', 'numpy'], [2**16, 2**20, 2**24]]
param_names = ['executor', 'size']
executors = {"dpnp": dpnp, "numpy": numpy}
params = [["dpnp", "numpy"], [2**16, 2**20, 2**24]]
param_names = ["executor", "size"]

def setup(self, executor, size):
self.executor = self.executors[executor]
Expand Down
32 changes: 20 additions & 12 deletions benchmarks/benchmarks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

# a set of interesting types to test
TYPES1 = [
'int16', 'float16',
'int32', 'float32',
'int64', 'float64', 'complex64',
'longfloat', 'complex128',
"int16",
"float16",
"int32",
"float32",
"int64",
"float64",
"complex64",
"longfloat",
"complex128",
]
if 'complex256' in numpy.typeDict:
TYPES1.append('complex256')
if "complex256" in numpy.typeDict:
TYPES1.append("complex256")


def memoize(func):
Expand All @@ -32,13 +37,15 @@ def wrapper():
if not result:
result.append(func())
return result[0]

return wrapper


# values which will be used to construct our sample data matrices
# replicate 10 times to speed up initial imports of this helper
# and generate some redundancy


@memoize
def get_values():
rnd = numpy.random.RandomState(1)
Expand All @@ -49,14 +56,15 @@ def get_values():
@memoize
def get_squares():
values = get_values()
squares = {t: numpy.array(values,
dtype=getattr(numpy, t)).reshape((nx, ny))
for t in TYPES1}
squares = {
t: numpy.array(values, dtype=getattr(numpy, t)).reshape((nx, ny))
for t in TYPES1
}

# adjust complex ones to have non-degenerated imagery part -- use
# original data transposed for that
for t, v in squares.items():
if t.startswith('complex'):
if t.startswith("complex"):
v += v.T * 1j
return squares

Expand Down Expand Up @@ -90,8 +98,8 @@ def get_indexes():
def get_indexes_rand():
rnd = random.Random(1)

indexes_rand = get_indexes().tolist() # copy
rnd.shuffle(indexes_rand) # in-place shuffle
indexes_rand = get_indexes().tolist() # copy
rnd.shuffle(indexes_rand) # in-place shuffle
indexes_rand = numpy.array(indexes_rand)
return indexes_rand

Expand Down
87 changes: 66 additions & 21 deletions benchmarks/pytest_benchmark/test_random.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# cython: language_level=3
# -*- coding: utf-8 -*-
# *****************************************************************************
Expand Down Expand Up @@ -37,36 +36,82 @@
NNUMBERS = 2**26


@pytest.mark.parametrize('function', [dpnp.random.beta, np.random.beta],
ids=['dpnp', 'numpy'])
@pytest.mark.parametrize(
"function", [dpnp.random.beta, np.random.beta], ids=["dpnp", "numpy"]
)
def test_beta(benchmark, function):
result = benchmark.pedantic(target=function, args=(4.0, 5.0, NNUMBERS,),
rounds=ROUNDS, iterations=ITERATIONS)
result = benchmark.pedantic(
target=function,
args=(
4.0,
5.0,
NNUMBERS,
),
rounds=ROUNDS,
iterations=ITERATIONS,
)


@pytest.mark.parametrize('function', [dpnp.random.exponential, np.random.exponential],
ids=['dpnp', 'numpy'])
@pytest.mark.parametrize(
"function",
[dpnp.random.exponential, np.random.exponential],
ids=["dpnp", "numpy"],
)
def test_exponential(benchmark, function):
result = benchmark.pedantic(target=function, args=(4.0, NNUMBERS,),
rounds=ROUNDS, iterations=ITERATIONS)
result = benchmark.pedantic(
target=function,
args=(
4.0,
NNUMBERS,
),
rounds=ROUNDS,
iterations=ITERATIONS,
)


@pytest.mark.parametrize('function', [dpnp.random.gamma, np.random.gamma],
ids=['dpnp', 'numpy'])
@pytest.mark.parametrize(
"function", [dpnp.random.gamma, np.random.gamma], ids=["dpnp", "numpy"]
)
def test_gamma(benchmark, function):
result = benchmark.pedantic(target=function, args=(2.0, 4.0, NNUMBERS,),
rounds=ROUNDS, iterations=ITERATIONS)
result = benchmark.pedantic(
target=function,
args=(
2.0,
4.0,
NNUMBERS,
),
rounds=ROUNDS,
iterations=ITERATIONS,
)


@pytest.mark.parametrize('function', [dpnp.random.normal, np.random.normal],
ids=['dpnp', 'numpy'])
@pytest.mark.parametrize(
"function", [dpnp.random.normal, np.random.normal], ids=["dpnp", "numpy"]
)
def test_normal(benchmark, function):
result = benchmark.pedantic(target=function, args=(0.0, 1.0, NNUMBERS,),
rounds=ROUNDS, iterations=ITERATIONS)
result = benchmark.pedantic(
target=function,
args=(
0.0,
1.0,
NNUMBERS,
),
rounds=ROUNDS,
iterations=ITERATIONS,
)


@pytest.mark.parametrize('function', [dpnp.random.uniform, np.random.uniform],
ids=['dpnp', 'numpy'])
@pytest.mark.parametrize(
"function", [dpnp.random.uniform, np.random.uniform], ids=["dpnp", "numpy"]
)
def test_uniform(benchmark, function):
result = benchmark.pedantic(target=function, args=(0.0, 1.0, NNUMBERS,),
rounds=ROUNDS, iterations=ITERATIONS)
result = benchmark.pedantic(
target=function,
args=(
0.0,
1.0,
NNUMBERS,
),
rounds=ROUNDS,
iterations=ITERATIONS,
)
Loading