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 flake8 to pre-commit config #1453

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

per-file-ignores =
__init__.py: E402, F401
dpnp/dpnp_algo/__init__.py: F401
dpnp/dpnp_algo/__init__.py: F401
dpnp/fft/__init__.py: F401
dpnp/linalg/__init__.py: F401
dpnp/random/__init__.py: F401
dpnp/dpnp_iface.py: D205

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

exclude =
.git,
benchmarks/*.py,
build,
dpnp/to_numba/*.py,
conda.recipe,
tests/*.py,
tests_external/*.py,
version.py,

# Print detailed statistic if any issue detected
count = True
statistics = True
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ repos:
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--config=.flake8"]
additional_dependencies:
- flake8-docstrings==1.7.0
- flake8-bugbear==23.6.5
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
Expand Down
15 changes: 12 additions & 3 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import dpctl
import dpctl.tensor as dpt
import dpctl.tensor._tensor_impl as ti
import numpy
from dpctl.tensor._elementwise_common import BinaryElementwiseFunc

import dpnp
Expand Down Expand Up @@ -67,6 +66,7 @@
def dpnp_add(x1, x2, out=None, order="K"):
"""
Invokes add() from dpctl.tensor implementation for add() function.

TODO: add a pybind11 extension of add() from OneMKL VM where possible
and would be performance effective.

Expand Down Expand Up @@ -111,21 +111,28 @@ def dpnp_add(x1, x2, out=None, order="K"):
def dpnp_divide(x1, x2, out=None, order="K"):
"""
Invokes div() function from pybind11 extension of OneMKL VM if possible.

Otherwise fully relies on dpctl.tensor implementation for divide() function.

"""

def _call_divide(src1, src2, dst, sycl_queue, depends=[]):
def _call_divide(src1, src2, dst, sycl_queue, depends=None):
"""A callback to register in BinaryElementwiseFunc class of dpctl.tensor"""

if depends is None:
depends = []

if vmi._can_call_div(sycl_queue, src1, src2, dst):
# call pybind11 extension for div() function from OneMKL VM
return vmi._div(sycl_queue, src1, src2, dst, depends)
return ti._divide(src1, src2, dst, sycl_queue, depends)

def _call_divide_inplace(lhs, rhs, sycl_queue, depends=[]):
def _call_divide_inplace(lhs, rhs, sycl_queue, depends=None):
"""In place workaround until dpctl.tensor provides the functionality."""

if depends is None:
depends = []

# allocate temporary memory for out array
out = dpt.empty_like(lhs, dtype=dpnp.result_type(lhs.dtype, rhs.dtype))

Expand Down Expand Up @@ -182,6 +189,7 @@ def _call_divide_inplace(lhs, rhs, sycl_queue, depends=[]):
def dpnp_multiply(x1, x2, out=None, order="K"):
"""
Invokes multiply() from dpctl.tensor implementation for multiply() function.

TODO: add a pybind11 extension of mul() from OneMKL VM where possible
and would be performance effective.

Expand Down Expand Up @@ -230,6 +238,7 @@ def dpnp_multiply(x1, x2, out=None, order="K"):
def dpnp_subtract(x1, x2, out=None, order="K"):
"""
Invokes subtract() from dpctl.tensor implementation for subtract() function.

TODO: add a pybind11 extension of sub() from OneMKL VM where possible
and would be performance effective.

Expand Down
80 changes: 34 additions & 46 deletions dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

def _get_unwrapped_index_key(key):
"""
Get an unwrapped index key.

Return a key where each nested instance of DPNP array is unwrapped into USM ndarray
for futher processing in DPCTL advanced indexing functions.

Expand Down Expand Up @@ -109,9 +111,7 @@ def T(self):
return self.transpose()

def to_device(self, target_device):
"""
Transfer array to target device
"""
"""Transfer array to target device."""

return dpnp_array(
shape=self.shape, buffer=self.get_array().to_device(target_device)
Expand Down Expand Up @@ -276,9 +276,7 @@ def __le__(self, other):
return dpnp.less_equal(self, other)

def __len__(self):
"""
Performs the operation __len__.
"""
"""Performs the operation __len__."""

return self._array_obj.__len__()

Expand Down Expand Up @@ -335,7 +333,7 @@ def __rmatmul__(self, other):
return dpnp.matmul(other, self)

def __rmod__(self, other):
return remainder(other, self)
return dpnp.remainder(other, self)

def __rmul__(self, other):
return dpnp.multiply(other, self)
Expand Down Expand Up @@ -499,8 +497,7 @@ def argmin(self, axis=None, out=None):

def argsort(self, axis=-1, kind=None, order=None):
"""
Return an ndarray of indices that sort the array along the
specified axis.
Return an ndarray of indices that sort the array along the specified axis.

Parameters
----------
Expand Down Expand Up @@ -584,10 +581,7 @@ def astype(self, dtype, order="K", casting="unsafe", subok=True, copy=True):
# 'byteswap',

def choose(input, choices, out=None, mode="raise"):
"""
Construct an array from an index array and a set of arrays to choose from.

"""
"""Construct an array from an index array and a set of arrays to choose from."""

return dpnp.choose(input, choices, out, mode)

Expand Down Expand Up @@ -655,7 +649,7 @@ def dot(self, other, out=None):

@property
def dtype(self):
""" """
"""Returns NumPy's dtype corresponding to the type of the array elements."""

return self._array_obj.dtype

Expand Down Expand Up @@ -689,19 +683,13 @@ def fill(self, value):

@property
def flags(self):
"""
Return information about the memory layout of the array.

"""
"""Return information about the memory layout of the array."""

return self._array_obj.flags

@property
def flat(self):
"""
Return a flat iterator, or set a flattened version of self to value.

"""
"""Return a flat iterator, or set a flattened version of self to value."""

return dpnp.flatiter(self)

Expand Down Expand Up @@ -787,10 +775,7 @@ def item(self, id=None):

@property
def itemsize(self):
"""
Size of one array element in bytes.

"""
"""Size of one array element in bytes."""

return self._array_obj.itemsize

Expand All @@ -802,16 +787,12 @@ def max(
initial=numpy._NoValue,
where=numpy._NoValue,
):
"""
Return the maximum along an axis.
"""
"""Return the maximum along an axis."""

return dpnp.max(self, axis, out, keepdims, initial, where)

def mean(self, axis=None, **kwargs):
"""
Returns the average of the array elements.
"""
"""Returns the average of the array elements."""

return dpnp.mean(self, axis=axis, **kwargs)

Expand All @@ -823,27 +804,19 @@ def min(
initial=numpy._NoValue,
where=numpy._NoValue,
):
"""
Return the minimum along a given axis.
"""
"""Return the minimum along a given axis."""

return dpnp.min(self, axis, out, keepdims, initial, where)

@property
def nbytes(self):
"""
Total bytes consumed by the elements of the array.

"""
"""Total bytes consumed by the elements of the array."""

return self._array_obj.nbytes

@property
def ndim(self):
"""
Number of array dimensions.

"""
"""Number of array dimensions."""

return self._array_obj.ndim

Expand All @@ -854,6 +827,8 @@ def nonzero(self):

def partition(self, kth, axis=-1, kind="introselect", order=None):
"""
Return a partitioned copy of an array.

Rearranges the elements in the array in such a way that the value of the
element in kth position is in the position it would be in a sorted array.

Expand Down Expand Up @@ -968,7 +943,10 @@ def shape(self):

@shape.setter
def shape(self, newshape):
"""Set new lengths of axes. A tuple of numbers represents size of each dimention.
"""
Set new lengths of axes.

A tuple of numbers represents size of each dimention.
It involves reshaping without copy. If the array cannot be reshaped without copy,
it raises an exception.

Expand All @@ -980,7 +958,7 @@ def shape(self, newshape):

@property
def size(self):
""" """
"""Number of elements in the array."""

return self._array_obj.size

Expand Down Expand Up @@ -1009,7 +987,17 @@ def std(self, axis=None, dtype=None, out=None, ddof=0, keepdims=False):

@property
def strides(self):
""" """
"""
Get strides of an array.

Returns memory displacement in array elements, upon unit
change of respective index.

E.g. for strides (s1, s2, s3) and multi-index (i1, i2, i3)

a[i1, i2, i3] == (&a[0,0,0])[ s1*s1 + s2*i2 + s3*i3]

"""

return self._array_obj.strides

Expand Down
7 changes: 4 additions & 3 deletions dpnp/dpnp_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"eye",
"full",
"linspace",
"ones" "tril",
"ones",
"tril",
"triu",
"zeros",
]
Expand Down Expand Up @@ -297,15 +298,15 @@ def ones(


def tril(x1, /, *, k=0):
""" "Creates `dpnp_array` as lower triangular part of an input array."""
"""Creates `dpnp_array` as lower triangular part of an input array."""
array_obj = dpt.tril(
x1.get_array() if isinstance(x1, dpnp_array) else x1, k
)
return dpnp_array(array_obj.shape, buffer=array_obj, order="K")


def triu(x1, /, *, k=0):
""" "Creates `dpnp_array` as upper triangular part of an input array."""
"""Creates `dpnp_array` as upper triangular part of an input array."""
array_obj = dpt.triu(
x1.get_array() if isinstance(x1, dpnp_array) else x1, k
)
Expand Down
5 changes: 1 addition & 4 deletions dpnp/dpnp_flatiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

"""
Implementation of flatiter

"""
"""Implementation of flatiter."""

import dpnp

Expand Down
Loading