Skip to content

Add gitleaks and shellcheck to pre-commit configuration #1689

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 4 commits into from
Feb 5, 2024
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
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ repos:
hooks:
- id: clang-format
args: ["-i"]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
hooks:
- id: gitleaks
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
76 changes: 38 additions & 38 deletions benchmarks/pytest_benchmark/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# dpnp/benchmarks/pytest_benchmark/
## Prerequisites
* pytest >= 6.1.1
* pytest-benchmark >= 3.4.1
## Running benchmark tests
```bash
pytest benchmarks/ --benchmark-json=results.json
```
Running tests and saving the current run into `STORAGE`, see [1]
```bash
pytest benchmarks/ --benchmark-json=results.json --benchmark-autosave
```
## Creating `.csv` report
```bash
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
```
## Optional: creating histogram
Note: make sure that `pytest-benchmark[histogram]` installed
```bash
# example
pip install pytest-benchmark[histogram]
pytest -vv benchmarks/ --benchmark-autosave --benchmark-histogram
pytest-benchmark compare .benchmarks/Linux-CPython-3.7-64bit/* --histogram
```
## Advanced running example
```
pytest benchmarks/ --benchmark-columns='min, max, mean, stddev, median, rounds, iterations' --benchmark-json=results.json --benchmark-autosave
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
```
[1] https://pytest-benchmark.readthedocs.io/en/latest/usage.html
# dpnp/benchmarks/pytest_benchmark/

## Prerequisites
* pytest >= 6.1.1
* pytest-benchmark >= 3.4.1


## Running benchmark tests
```bash
pytest benchmarks/ --benchmark-json=results.json
```
Running tests and saving the current run into `STORAGE`, see [1]
```bash
pytest benchmarks/ --benchmark-json=results.json --benchmark-autosave
```

## Creating `.csv` report
```bash
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
```

## Optional: creating histogram
Note: make sure that `pytest-benchmark[histogram]` installed
```bash
# example
pip install pytest-benchmark[histogram]
pytest -vv benchmarks/ --benchmark-autosave --benchmark-histogram
pytest-benchmark compare .benchmarks/Linux-CPython-3.7-64bit/* --histogram
```

## Advanced running example
```
pytest benchmarks/ --benchmark-columns='min, max, mean, stddev, median, rounds, iterations' --benchmark-json=results.json --benchmark-autosave
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
```


[1] https://pytest-benchmark.readthedocs.io/en/latest/usage.html
234 changes: 117 additions & 117 deletions benchmarks/pytest_benchmark/test_random.py
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
# cython: language_level=3
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2024, Intel Corporation
# All rights reserved.
#
# 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,
# 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
# 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
# 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
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************
import numpy as np
import pytest
import dpnp
ROUNDS = 30
ITERATIONS = 4
NNUMBERS = 2**26
@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,
)
@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,
)
@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,
)
@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,
)
@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,
)
# cython: language_level=3
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2016-2024, Intel Corporation
# All rights reserved.
#
# 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,
# 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
# 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
# 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
# THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

import numpy as np
import pytest

import dpnp

ROUNDS = 30
ITERATIONS = 4

NNUMBERS = 2**26


@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,
)


@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,
)


@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,
)


@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,
)


@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,
)
22 changes: 13 additions & 9 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${BUILD_PREFIX}/lib"

# Intel LLVM must cooperate with compiler and sysroot from conda
echo "--gcc-toolchain=${BUILD_PREFIX} --sysroot=${BUILD_PREFIX}/${HOST}/sysroot -target ${HOST}" > icpx_for_conda.cfg
export ICPXCFG="$(pwd)/icpx_for_conda.cfg"
export ICXCFG="$(pwd)/icpx_for_conda.cfg"

ICPXCFG="$(pwd)/icpx_for_conda.cfg"
export ICPXCFG

ICXCFG="$(pwd)/icpx_for_conda.cfg"
export ICXCFG

export CMAKE_GENERATOR="Ninja"
export TBB_ROOT_HINT=$PREFIX
export DPL_ROOT_HINT=$PREFIX
export MKL_ROOT_HINT=$PREFIX
SKBUILD_ARGS="-- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
SKBUILD_ARGS="${SKBUILD_ARGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
SKBUILD_ARGS=(-- "-DCMAKE_C_COMPILER:PATH=icx" "-DCMAKE_CXX_COMPILER:PATH=icpx" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")
SKBUILD_ARGS=("${SKBUILD_ARGS[@]}" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON")

# Build wheel package
if [ "$CONDA_PY" == "36" ]; then
WHEELS_BUILD_ARGS="-p manylinux1_x86_64"
WHEELS_BUILD_ARGS=("-p" "manylinux1_x86_64")
else
WHEELS_BUILD_ARGS="-p manylinux2014_x86_64"
WHEELS_BUILD_ARGS=("-p" "manylinux2014_x86_64")
fi
if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then
$PYTHON setup.py install bdist_wheel ${WHEELS_BUILD_ARGS} ${SKBUILD_ARGS}
cp dist/dpnp*.whl ${WHEELS_OUTPUT_FOLDER}
$PYTHON setup.py install bdist_wheel "${WHEELS_BUILD_ARGS[@]}" "${SKBUILD_ARGS[@]}"
cp dist/dpnp*.whl "${WHEELS_OUTPUT_FOLDER}"
else
$PYTHON setup.py install ${SKBUILD_ARGS}
$PYTHON setup.py install "${SKBUILD_ARGS[@]}"
fi
9 changes: 6 additions & 3 deletions conda-recipe/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ fi

# if DPCPPROOT is specified (work with custom DPCPP)
if [ -n "${DPCPPROOT}" ]; then
. ${DPCPPROOT}/env/vars.sh
# shellcheck source=/dev/null
. "${DPCPPROOT}"/env/vars.sh
fi

# if MKLROOT is specified (work with custom math library)
if [ -n "${MKLROOT}" ]; then
. ${MKLROOT}/env/vars.sh
# shellcheck source=/dev/null
. "${MKLROOT}"/env/vars.sh
fi

# have to activate while SYCL CPU device/driver needs paths
# if TBBROOT is specified
if [ -n "${TBBROOT}" ]; then
. ${TBBROOT}/env/vars.sh
# shellcheck source=/dev/null
. "${TBBROOT}"/env/vars.sh
fi
Loading