Skip to content

Extend pre-commit checks #1183

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

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 45 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[flake8]
extend-ignore =
E203, # whitespace before ':' (currently conflicts with black formatting)
E501, # line too long
F401, # module imported but unused
F403, # ‘from module import *’ used; unable to detect undefined names
F405, # name may be undefined, or defined from star imports: module
F821, # undefined name name
W505, # doc line too long (105 > 80 characters)
D100, # missing docstring in public module
D101, # missing docstring in public class
D102, # missing docstring in public method
D103, # missing docstring in public function
D104, # missing docstring in public package
D105, # missing docstring in magic method
D107, # missing docstring in __init__
D202, # no blank lines allowed after function docstring
D400, # first line should end with a period
D401, # first line should be in imperative mood
D414 # section has no content

per-file-ignores =
# module level import not at top of file:
__init__.py: E402
# do not use bare 'except':
dpnp/random/dpnp_iface_random.py: E722, B001
# function definition does not bind loop variable
tests/third_party/cupy/sorting_tests/test_count.py: B023
# 1 blank line required between summary line and description
dpnp/dpnp_iface.py: D205
tests/tests_perf/math_tests/test_trigonometric.py: D205

filename = *.py, *.pyx
max_line_length = 80
max-doc-length = 80
show-source = True

exclude =
.git,
__pycache__,
version.py

# Print detailed statistic if any issue detected
count = True
statistics = True
8 changes: 5 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- uses: pre-commit/[email protected]
52 changes: 51 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,58 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/PyCQA/bandit
rev: '1.7.0'
rev: '1.7.4'
hooks:
- id: bandit
pass_filenames: false
args: ["-r", "dpnp", "-lll"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-case-conflict
- id: check-toml
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
args: ["--check", "--diff", "--color"]
language_version: python3.9
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
args: ["--check-only", "--diff"]
additional_dependencies: [colorama]
- id: isort
name: isort (cython)
types: [cython]
args: ["--check-only", "--diff"]
additional_dependencies: [colorama]
- repo: https://gitlab.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
args: ["--config=.flake8"]
additional_dependencies:
- flake8-docstrings==1.6.0
- flake8-bugbear==22.8.23
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: ["-i"]
22 changes: 11 additions & 11 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Copyright (c) 2016-2020, Intel Corporation
Copyright (c) 2016-2022, Intel Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
15 changes: 9 additions & 6 deletions benchmarks/benchmarks/bench_elementwise.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy

import dpnp

from .common import Benchmark


Expand All @@ -8,12 +10,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
89 changes: 46 additions & 43 deletions benchmarks/benchmarks/bench_linalg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from .common import Benchmark, get_squares_, get_indexes_rand, TYPES1

import numpy

import dpnp

from .common import TYPES1, Benchmark, get_indexes_rand, get_squares_


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 +48,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 +85,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 +113,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)
8 changes: 5 additions & 3 deletions benchmarks/benchmarks/bench_random.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import numpy

import dpnp

from .common import Benchmark


# 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
Loading