-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from valentingol/dev
Initial commit
- Loading branch information
Showing
35 changed files
with
1,343 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
extend-ignore = E203 | ||
exclude = dinosor/_version.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Flake 8 | ||
|
||
on: [push] | ||
|
||
jobs: | ||
flake-lint: | ||
runs-on: ubuntu-latest | ||
name: Flake Lint | ||
steps: | ||
- name: Check out source repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Python environment | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: Lint | ||
uses: py-actions/flake8@v2 | ||
with: | ||
label: Flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: MyPy | ||
|
||
on: [push] | ||
|
||
jobs: | ||
mypy-lint: | ||
runs-on: ubuntu-latest | ||
name: MyPy Lint | ||
steps: | ||
- name: Check out source repository | ||
uses: actions/checkout@v2 | ||
- name: Mypy Check | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install mypy==1.1.1 mypy-extensions==1.0.0 | ||
python -m pip install types-PyYAML | ||
mypy --install-types --non-interactive --config-file pyproject.toml . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Pydocstyle | ||
|
||
on: [push] | ||
|
||
jobs: | ||
pydoc-lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.9 | ||
- name: Install | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pydocstyle | ||
pip install -e . | ||
- name: Analysing the code with pydocstyle | ||
run: | | ||
pydocstyle --convention=numpy . | tee pydocstyle.txt | ||
- name: Check the number of errors | ||
run: | | ||
n_errors=$(wc -l < pydocstyle.txt) | ||
echo "Number of errors in docstrings: $n_errors" | ||
python github_actions_utils/pydocstyle_manager.py --n_errors=$n_errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Ruff | ||
|
||
on: [push] | ||
|
||
jobs: | ||
ruff-lint: | ||
runs-on: ubuntu-latest | ||
name: Ruff Lint | ||
steps: | ||
- name: Check out source repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Python environment | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: Lint | ||
uses: jpetrucciani/ruff-check@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Cache | ||
**_cache | ||
**.pyc | ||
*/__pycache__ | ||
# Env | ||
.env | ||
.venv | ||
env | ||
env.yaml | ||
environment.yml | ||
venv | ||
**.egg-info | ||
# VScode | ||
.vscode | ||
# Temporary files | ||
**/tmp.py | ||
**/tmp.ipynb | ||
# Tests | ||
.coverage | ||
# SCM | ||
src/torch_pca/_version.py | ||
# Doc | ||
build | ||
docs/_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"MD013": { | ||
"line_length": 120 | ||
}, | ||
"MD034": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.3.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
|
||
- repo: https://github.com/pycqa/flake8 | ||
rev: '4.0.1' | ||
hooks: | ||
- id: flake8 | ||
|
||
- repo: https://github.com/pycqa/pydocstyle | ||
rev: '6.1.1' | ||
hooks: | ||
- id: pydocstyle | ||
args: | ||
- --convention=numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# .readthedocs.yaml | ||
# Read the Docs configuration file | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
|
||
version: 2 | ||
|
||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.11" | ||
|
||
sphinx: | ||
configuration: docs/conf.py | ||
|
||
formats: | ||
- epub | ||
|
||
python: | ||
install: | ||
- requirements: docs/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Contributing to My Worflow Template | ||
|
||
Everyone can contribute to Pytorch PCA, and we value everyone’s contributions. | ||
There are several ways to contribute, including: | ||
|
||
- Raising [issue](https://github.com/valentingol/torch_pca/issues) | ||
on the Github repository | ||
|
||
- Proposing [Pull requests](https://github.com/valentingol/torch_pca/pulls) | ||
to the Github repository | ||
|
||
- Contact me by email (valentin.goldite@gmail.com) | ||
|
||
- Create your own repository based on this one and cite it | ||
|
||
## Pull request checklist | ||
|
||
Before proposing a PR you must follow some rule: | ||
|
||
- Pull requests typically comprise a **single git commit**. In preparing a pull | ||
request for review, you may need to squash together multiple commits. | ||
|
||
- Code should work on Python 3.8-3.11 | ||
|
||
- Code should respect [PEP8](https://peps.python.org/pep-0008/) | ||
|
||
- The format of the docstrings follows [Numpy guidline](https://numpydoc.readthedocs.io/en/latest/format.html) | ||
|
||
- It is recommended to use all linters listed in `requirements-dev.txt` | ||
|
||
Before submitting a PR you should run this pipeline: | ||
|
||
```script | ||
sh checks.sh | ||
``` | ||
|
||
**Try to not decrease the global Pylint score** after a pull request. A minimum | ||
of 7.0/10.0 is required but **we preferably want above 9.0/10.0.** | ||
|
||
## Commit message | ||
|
||
Commits should start with an emoji and directly followed by a descriptive and | ||
precise message that starts with a capital letter and should be written in present | ||
tense. E.g: | ||
|
||
*✨: added configuration function* ❌ Bad | ||
|
||
*✨ Add function to save configuration file* ✅ Good | ||
|
||
Emojis not only look great but also makes you rethink what to add to a commit. | ||
The goal is to dedicate each single kind of change to a single commit. Make many | ||
but small commits! | ||
|
||
Emojis of commit message follow mainly the [Gitmoji](https://gitmoji.dev/) guideline | ||
(the different ones start with an asterisk *). The most useful are: | ||
|
||
| Emoji | Description | | ||
| ------------------------------------- | ------------------------------------------------------- | | ||
| 🎉 `:tada:` | Initial commit | | ||
| ✨ `:sparkles:` | New cool feature | | ||
| ➕ `:heavy_plus_sign:` * | Add file and/or folder | | ||
| 🔥 `:fire:` | Remove some code or file | | ||
| 📝 `:memo:` | Add or improve readme, docstring or comments | | ||
| 🐛 `:bug:` | Fix a bug | | ||
| 🎨 `:art:` | Improve style, or format the code | | ||
| ♻️ `:recycle:` | Refactor the code | | ||
| 🚚 `:truck:` | Rename and/or move files and folders | | ||
| 🏗️ `:building_construction:` | Change a part of the repository architecture | | ||
| ✏️ `:pencil2:` | Fix typo | | ||
| ⚙️ `:gear:` * | Add or update configuration file (config/exp.yaml, ...) | | ||
| 🔧 `:wrench:` | Add or update tool configuration (pyproject.toml, ...) | | ||
| 🍱 `:bento:` | Add or update assets | | ||
| 🚀 `:rocket:` * | Improve performance | | ||
| ⚗️ `:alembic:` | Perform experiment | | ||
| 🚸 `:children_crossing:` | Improve user experience | | ||
| 🆙 `:up:` * OR 🔖 `:bookmark:` | Update the version/tag | | ||
| ⬆️ `:arrow_up:` | Upgrade dependency | | ||
| 🚧 `:construction:` | Work in progress | | ||
| 🔀 `:twisted_rightwards_arrows:` | Merge a branch | | ||
| Check [Gitmoji](https://gitmoji.dev/) | *OTHER* | | ||
|
||
Installing the [Gitmoji VSCode extension](https://marketplace.visualstudio.com/items?itemName=seatonjiang.gitmoji-vscode) | ||
can be useful to get the emoji you want quickly. | ||
|
||
## Version and tag numbers | ||
|
||
Version/tag numbers will be assigned according to the [Semantic Versioning scheme](https://semver.org/). | ||
This means, given a version number MAJOR.MINOR.PATCH, we will increment the: | ||
|
||
- MAJOR version when we make incompatible API changes | ||
- MINOR version when we add functionality in a backwards compatible manner | ||
- PATCH version when we make backwards compatible bug fixes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,40 @@ | ||
# torch_pca | ||
Principal Component Anlaysis (PCA) in PyTorch. | ||
# Pytorch CPA | ||
|
||
Principal Component Anlaysis (PCA) in PyTorch. The intention is to provide a | ||
simple and easy to use implementation of PCA in PyTorch, the most similar to | ||
the `sklearn`'s PCA as possible (in terms of API and, of course, output). | ||
|
||
![PythonVersion](https://img.shields.io/badge/python-3.8%20%7E%203.11-informational) | ||
![PytorchVersion](https://img.shields.io/badge/pytorch-1.8%20%7E%201.13%20%7C%202.0+-informational) | ||
|
||
[![GitHub User followers](https://img.shields.io/github/followers/valentingol?label=User%20followers&style=social)](https://github.com/valentingol) | ||
[![GitHub User's User stars](https://img.shields.io/github/stars/valentingol?label=User%20Stars&style=social)](https://github.com/valentingol) | ||
|
||
[![Ruff_logo](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff) | ||
[![Black_logo](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | ||
|
||
[![Ruff](https://github.com/valentingol/torch_pca/actions/workflows/ruff.yaml/badge.svg)](https://github.com/valentingol/Dinosor/actions/workflows/ruff.yaml) | ||
[![Flake8](https://github.com/valentingol/torch_pca/actions/workflows/flake.yaml/badge.svg)](https://github.com/valentingol/Dinosor/actions/workflows/flake.yaml) | ||
[![Pydocstyle](https://github.com/valentingol/torch_pca/actions/workflows/pydocstyle.yaml/badge.svg)](https://github.com/valentingol/Dinosor/actions/workflows/pydocstyle.yaml) | ||
[![MyPy](https://github.com/valentingol/torch_pca/actions/workflows/mypy.yaml/badge.svg)](https://github.com/valentingol/Dinosor/actions/workflows/mypy.yaml) | ||
|
||
## Installation | ||
|
||
```bash | ||
pip install torch-cpa | ||
``` | ||
|
||
## How to use | ||
|
||
```python | ||
from torch_cpa import PCA | ||
|
||
# Create like sklearn.decomposition.PCA | ||
pca_model = PCA(n_components=None, whiten=False) | ||
|
||
# Use like sklearn.decomposition.PCA | ||
>>> new_X1 = pca_model.fit_transform(X1) | ||
>>> new_X2 = pca_model.transform(X2) | ||
>>> print(pca.explained_variance_ratio_) | ||
[0.756, 0.142, 0.062, ...] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Style constants | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
WHITE='\033[0m' | ||
BOLD=$(tput bold) | ||
NORMAL=$(tput sgr0) | ||
|
||
# Check output function | ||
check_output() { | ||
if [ $? -ne 0 ]; then | ||
echo "${RED}$1 fail!\nExit${WHITE}" | ||
exit 1 | ||
else | ||
echo "${GREEN}$1 pass${WHITE}\n" | ||
fi | ||
} | ||
|
||
# Checks | ||
echo "**************** Typing ****************" | ||
mypy . | ||
check_output "Typing checks" | ||
|
||
echo "************* Import order *************" | ||
isort --check-only . | ||
check_output "Import order checks" | ||
|
||
echo "***************** PEP8 *****************" | ||
flake8 . | ||
check_output "PEP8 checks" | ||
|
||
echo "***************** Ruff *****************" | ||
ruff . | ||
check_output "Ruff checks" | ||
|
||
echo "*********** Style evaluation ***********" | ||
score=$(pylint . | sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p') | ||
|
||
echo "Pylint score: ${BOLD}$score/10.0${NORMAL} (details by running: pylint .)\nMinimum authorized score: 7.0\n" | ||
|
||
echo "************** Unit tests **************" | ||
pytest --cov-report term-missing --cov=./src tests/ | ||
check_output "Unit tests" | ||
|
||
printf "\n${GREEN}${BOLD}All checks pass${NORMAL}${WHITE}\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = ../docs | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
Oops, something went wrong.