From fd55f95f43d8a595e2a29871576214c7ee22e69a Mon Sep 17 00:00:00 2001 From: GitHub Action <52708150+marcpinet@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:45:24 +0200 Subject: [PATCH 1/3] refactor: make utils functions more robust --- neuralnetlib/utils.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/neuralnetlib/utils.py b/neuralnetlib/utils.py index a2121a4..0f63c58 100644 --- a/neuralnetlib/utils.py +++ b/neuralnetlib/utils.py @@ -20,8 +20,10 @@ def dict_with_list_to_dict_with_ndarray(d: dict) -> dict: return d -def shuffle(x, y, random_state: int = None) -> tuple: +def shuffle(x: np.ndarray, y: np.ndarray, random_state: int = None) -> tuple: """Shuffles the data along the first axis.""" + x = np.array(x) + y = np.array(y) rng = np.random.default_rng(random_state if random_state is not None else int(time.time_ns())) indices = rng.permutation(len(x)) return x[indices], y[indices] @@ -44,23 +46,28 @@ def progress_bar(current: int, total: int, width: int = 30, message: str = "") - sys.stdout.flush() -def train_test_split(x, y, test_size: float = 0.2, random_state: int = None) -> tuple: +def train_test_split(x: np.ndarray, y: np.ndarray, test_size: float = 0.2, random_state: int = None) -> tuple: """ Splits the data into training and test sets. Args: - x (np.ndarray): input data - y (np.ndarray): target data + x (np.ndarray or list): input data + y (np.ndarray or list): target data test_size (float): the proportion of the dataset to include in the test split random_state (int): seed for the random number generator Returns: - tuple: x_train, x_test, y_train, y_test + tuple: (x_train, x_test, y_train, y_test) """ + x = np.array(x) + y = np.array(y) rng = np.random.default_rng(random_state if random_state is not None else int(time.time_ns())) indices = np.arange(len(x)) rng.shuffle(indices) split_index = int(len(x) * (1 - test_size)) - x_train, x_test = x[indices[:split_index]], x[indices[split_index:]] - y_train, y_test = y[indices[:split_index]], y[indices[split_index:]] + x_train = x[indices[:split_index]] + x_test = x[indices[split_index:]] + y_train = y[indices[:split_index]] + y_test = y[indices[split_index:]] return x_train, x_test, y_train, y_test + From f9afba44cbf4069fc4f55a619b81e3e1dc891f27 Mon Sep 17 00:00:00 2001 From: GitHub Action <52708150+marcpinet@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:45:40 +0200 Subject: [PATCH 2/3] ci: bump version to 2.4.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a6eb256..627326d 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='neuralnetlib', - version='2.4.1', + version='2.4.2', author='Marc Pinet', description='A simple convolutional neural network library with only numpy as dependency', long_description=open('README.md', encoding="utf-8").read(), From 74669894316270f7167f0b1fe2b13d67ac7c8c76 Mon Sep 17 00:00:00 2001 From: GitHub Action <52708150+marcpinet@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:47:47 +0200 Subject: [PATCH 3/3] ci: remove useless develop option (changed my mind) --- .github/workflows/pypi.yml | 32 ++------------------------------ .github/workflows/release.yml | 4 ++-- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index c66f617..e11d5ae 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -43,7 +43,7 @@ jobs: publish: needs: check-version-changed - if: needs.check-version-changed.outputs.version_changed == 'true' && github.ref == 'refs/heads/main' + if: needs.check-version-changed.outputs.version_changed == 'true' runs-on: ubuntu-latest steps: - name: Check out code @@ -62,32 +62,4 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python setup.py sdist bdist_wheel - twine upload dist/* - - publish-dev: - needs: check-version-changed - if: needs.check-version-changed.outputs.version_changed == 'true' && github.ref == 'refs/heads/develop' - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Get version - id: get_version - run: | - echo "VERSION=$(python setup.py --version)" >> $GITHUB_OUTPUT - - name: Build and publish dev version - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - VERSION="${{ steps.get_version.outputs.VERSION }}-dev" - python setup.py sdist bdist_wheel - twine upload --repository-url https://test.pypi.org/legacy/ dist/*$VERSION* + twine upload dist/* \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5810d04..b1447e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: release: needs: check-version-changed - if: needs.check-version-changed.outputs.version_changed == 'true' && github.ref == 'refs/heads/main' + if: needs.check-version-changed.outputs.version_changed == 'true' runs-on: ubuntu-latest steps: - name: Checkout Repository @@ -86,4 +86,4 @@ jobs: tag_name: v${{ steps.get_version.outputs.VERSION }} body: ${{ steps.generate_release_notes.outputs.RELEASE_NOTES }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file