Skip to content

Commit c3753c7

Browse files
committed
fixed comments
0 parents  commit c3753c7

130 files changed

Lines changed: 33037 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# These owners will be the default owners for everything in
2+
# the repo. Unless a later match takes precedence,
3+
# Developers in this list will be requested for
4+
# review when someone opens a pull request.
5+
* @morenol
6+
* @Mec-iS

.github/CODE_OF_CONDUCT.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Code of Conduct
2+
3+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4+
5+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6+
7+
Examples of unacceptable behavior by participants include:
8+
9+
* The use of sexualized language or imagery
10+
* Personal attacks
11+
* Trolling or insulting/derogatory comments
12+
* Public or private harassment
13+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
14+
* Other unethical or unprofessional conduct.
15+
16+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17+
18+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19+
20+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21+
22+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)

.github/CONTRIBUTING.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# **Contributing**
2+
3+
When contributing to this repository, please first discuss the change you wish to make via issue,
4+
email, or any other method with the owners of this repository before making a change.
5+
6+
Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project.
7+
8+
## Background
9+
10+
We try to follow these principles:
11+
* follow as much as possible the sklearn API to give a frictionless user experience for practitioners already familiar with it
12+
* use only pure-Rust implementations for safety and future-proofing (with some low-level limited exceptions)
13+
* do not use macros in the library code to allow readability and transparent behavior
14+
* priority is not on "big data" dataset, try to be fast for small/average dataset with limited memory footprint.
15+
16+
## Pull Request Process
17+
18+
1. Open a PR following the template (erase the part of the template you don't need).
19+
2. Update the CHANGELOG.md with details of changes to the interface if they are breaking changes, this includes new environment variables, exposed ports useful file locations and container parameters.
20+
3. Pull Request can be merged in once you have the sign-off of one other developer, or if you do not have permission to do that you may request the reviewer to merge it for you.
21+
22+
### generic guidelines
23+
Take a look to the conventions established by existing code:
24+
* Every module should come with some reference to scientific literature that allows relating the code to research. Use the `//!` comments at the top of the module to tell readers about the basics of the procedure you are implementing.
25+
* Every module should provide a Rust doctest, a brief test embedded with the documentation that explains how to use the procedure implemented.
26+
* Every module should provide comprehensive tests at the end, in its `mod tests {}` sub-module. These tests can be flagged or not with configuration flags to allow WebAssembly target.
27+
* Run `cargo doc --no-deps --open` and read the generated documentation in the browser to be sure that your changes reflects in the documentation and new code is documented.
28+
29+
#### digging deeper
30+
* a nice overview of the codebase is given by [static analyzer](https://mozilla.github.io/rust-code-analysis/metrics.html):
31+
```
32+
$ cargo install rust-code-analysis-cli
33+
// print metrics for every module
34+
$ rust-code-analysis-cli -m -O json -o . -p src/ --pr
35+
// print full AST for a module
36+
$ rust-code-analysis-cli -p src/algorithm/neighbour/fastpair.rs --ls 22 --le 213 -d > ast.txt
37+
```
38+
* find more information about what happens in your binary with [`twiggy`](https://rustwasm.github.io/twiggy/install.html). This need a compiled binary so create a brief `main {}` function using `smartcore` and then point `twiggy` to that file.
39+
40+
* Please take a look to the output of a profiler to spot most evident performance problems, see [this guide about using a profiler](http://www.codeofview.com/fix-rs/2017/01/24/how-to-optimize-rust-programs-on-linux/).
41+
42+
## Issue Report Process
43+
44+
1. Go to the project's issues.
45+
2. Select the template that better fits your issue.
46+
3. Read carefully the instructions and write within the template guidelines.
47+
4. Submit it and wait for support.
48+
49+
## Reviewing process
50+
51+
1. After a PR is opened maintainers are notified
52+
2. Probably changes will be required to comply with the workflow, these commands are run automatically and all tests shall pass:
53+
* **Formatting**: run `rustfmt src/*.rs` to apply automatic formatting
54+
* **Linting**: `clippy` is used with command `cargo clippy --all-features -- -Drust-2018-idioms -Dwarnings`
55+
* **Coverage** (optional): `tarpaulin` is used with command `cargo tarpaulin --out Lcov --all-features -- --test-threads 1`
56+
* **Testing**: multiple test pipelines are run for different targets
57+
3. When everything is OK, code is merged.
58+
59+
60+
## Contribution Best Practices
61+
62+
* Read this [how-to about Github workflow here](https://guides.github.com/introduction/flow/) if you are not familiar with.
63+
64+
* Read all the texts related to [contributing for an OS community](https://github.com/HTTP-APIs/hydrus/tree/master/.github).
65+
66+
* Read this [how-to about writing a PR](https://github.com/blog/1943-how-to-write-the-perfect-pull-request) and this [other how-to about writing a issue](https://wiredcraft.com/blog/how-we-write-our-github-issues/)
67+
68+
* **read history**: search past open or closed issues for your problem before opening a new issue.
69+
70+
* **PRs on develop**: any change should be PRed first in `development`
71+
72+
* **testing**: everything should work and be tested as defined in the workflow. If any is failing for non-related reasons, annotate the test failure in the PR comment.

.github/DEVELOPERS.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# smartcore: Introduction to modules
2+
3+
Important source of information:
4+
* [Rust API guidelines](https://rust-lang.github.io/api-guidelines/about.html)
5+
6+
## Walkthrough: traits system and basic structures
7+
8+
#### numbers
9+
The library is founded on basic traits provided by `num-traits`. Basic traits are in `src/numbers`. These traits are used to define all the procedures in the library to make everything safer and provide constraints to what implementations can handle.
10+
11+
#### linalg
12+
`numbers` are made at use in linear algebra structures in the **`src/linalg/basic`** module. These sub-modules define the traits used all over the code base.
13+
14+
* *arrays*: In particular data structures like `Array`, `Array1` (1-dimensional), `Array2` (matrix, 2-D); plus their "views" traits. Views are used to provide no-footprint access to data, they have composed traits to allow writing (mutable traits: `MutArray`, `ArrayViewMut`, ...).
15+
* *matrix*: This provides the main entrypoint to matrices operations and currently the only structure provided in the shape of `struct DenseMatrix`. A matrix can be instantiated and automatically make available all the traits in "arrays" (sparse matrices implementation will be provided).
16+
* *vector*: Convenience traits are implemented for `std::Vec` to allow extensive reuse.
17+
18+
These are all traits and by definition they do not allow instantiation. For instantiable structures see implementation like `DenseMatrix` with relative constructor.
19+
20+
#### linalg/traits
21+
The traits in `src/linalg/traits` are closely linked to Linear Algebra's theoretical framework. These traits are used to specify characteristics and constraints for types accepted by various algorithms. For example these allow to define if a matrix is `QRDecomposable` and/or `SVDDecomposable`. See docstring for referencese to theoretical framework.
22+
23+
As above these are all traits and by definition they do not allow instantiation. They are mostly used to provide constraints for implementations. For example, the implementation for Linear Regression requires the input data `X` to be in `smartcore`'s trait system `Array2<FloatNumber> + QRDecomposable<TX> + SVDDecomposable<TX>`, a 2-D matrix that is both QR and SVD decomposable; that is what the provided strucure `linalg::arrays::matrix::DenseMatrix` happens to be: `impl<T: FloatNumber> QRDecomposable<T> for DenseMatrix<T> {};impl<T: FloatNumber> SVDDecomposable<T> for DenseMatrix<T> {}`.
24+
25+
#### metrics
26+
Implementations for metrics (classification, regression, cluster, ...) and distance measure (Euclidean, Hamming, Manhattan, ...). For example: `Accuracy`, `F1`, `AUC`, `Precision`, `R2`. As everything else in the code base, these implementations reuse `numbers` and `linalg` traits and structures.
27+
28+
These are collected in structures like `pub struct ClassificationMetrics<T> {}` that implements `metrics::Metrics`, these are groups of functions (classification, regression, cluster, ...) that provide instantiation for the structures. Each of those instantiation can be passed around using the relative function, like `pub fn accuracy<T: Number + RealNumber + FloatNumber, V: ArrayView1<T>>(y_true: &V, y_pred: &V) -> T`. This provides a mechanism for metrics to be passed to higher interfaces like the `cross_validate`:
29+
```rust
30+
let results =
31+
cross_validate(
32+
BiasedEstimator::new(), // custom estimator
33+
&x, &y, // input data
34+
NoParameters {}, // extra parameters
35+
cv, // type of cross validator
36+
&accuracy // **metrics function** <--------
37+
).unwrap();
38+
```
39+
40+
TODO: complete for all modules
41+
42+
## Notebooks
43+
Proceed to the [**notebooks**](https://github.com/smartcorelib/smartcore-jupyter/) to see these modules in action.

.github/ISSUE_TEMPLATE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### I'm submitting a
2+
- [ ] bug report.
3+
- [ ] improvement.
4+
- [ ] feature request.
5+
6+
### Current Behaviour:
7+
<!-- Describe about the bug -->
8+
9+
### Expected Behaviour:
10+
<!-- Describe what will happen if bug is removed -->
11+
12+
### Steps to reproduce:
13+
<!-- If you can then please provide the steps to reproduce the bug -->
14+
15+
### Snapshot:
16+
<!-- If you can then please provide the screenshot of the issue you are facing -->
17+
18+
### Environment:
19+
<!-- Please provide the following environment details if relevant -->
20+
* rustc version
21+
* cargo version
22+
* OS details
23+
24+
### Do you want to work on this issue?
25+
<!-- yes/no -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!-- Please create (if there is not one yet) a issue before sending a PR -->
2+
<!-- Add issue number (Eg: fixes #123) -->
3+
<!-- Always provide changes in existing tests or new tests -->
4+
5+
Fixes #
6+
7+
### Checklist
8+
- [ ] My branch is up-to-date with development branch.
9+
- [ ] Everything works and tested on latest stable Rust.
10+
- [ ] Coverage and Linting have been applied
11+
12+
### Current behaviour
13+
<!-- Describe the code you are going to change and its behaviour -->
14+
15+
### New expected behaviour
16+
<!-- Describe the new code and its expected behaviour -->
17+
18+
### Change logs
19+
20+
<!-- #### Added -->
21+
<!-- Edit these points below to describe the new features added with this PR -->
22+
<!-- - Feature 1 -->
23+
<!-- - Feature 2 -->
24+
25+
26+
<!-- #### Changed -->
27+
<!-- Edit these points below to describe the changes made in existing functionality with this PR -->
28+
<!-- - Change 1 -->
29+
<!-- - Change 1 -->

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
ignore:
9+
- dependency-name: rand_distr
10+
versions:
11+
- 0.4.0

.github/workflows/ci.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, development]
6+
pull_request:
7+
branches: [development]
8+
9+
jobs:
10+
tests:
11+
runs-on: "${{ matrix.platform.os }}-latest"
12+
strategy:
13+
matrix:
14+
platform:
15+
[
16+
{ os: "windows", target: "x86_64-pc-windows-msvc" },
17+
{ os: "windows", target: "i686-pc-windows-msvc" },
18+
{ os: "ubuntu", target: "x86_64-unknown-linux-gnu" },
19+
{ os: "ubuntu", target: "i686-unknown-linux-gnu" },
20+
{ os: "ubuntu", target: "wasm32-unknown-unknown" },
21+
{ os: "macos", target: "aarch64-apple-darwin" },
22+
]
23+
env:
24+
TZ: "/usr/share/zoneinfo/your/location"
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Cache .cargo and target
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.cargo
32+
./target
33+
key: ${{ runner.os }}-cargo-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo.toml') }}
34+
restore-keys: ${{ runner.os }}-cargo-${{ matrix.platform.target }}-${{ hashFiles('**/Cargo.toml') }}
35+
- name: Install Rust toolchain
36+
uses: actions-rs/toolchain@v1
37+
with:
38+
toolchain: stable
39+
target: ${{ matrix.platform.target }}
40+
profile: minimal
41+
default: true
42+
- name: Install test runner for wasm
43+
if: matrix.platform.target == 'wasm32-unknown-unknown'
44+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
45+
- name: Stable Build with all features
46+
uses: actions-rs/cargo@v1
47+
with:
48+
command: build
49+
args: --all-features --target ${{ matrix.platform.target }}
50+
- name: Stable Build without features
51+
uses: actions-rs/cargo@v1
52+
with:
53+
command: build
54+
args: --target ${{ matrix.platform.target }}
55+
- name: Tests
56+
if: matrix.platform.target == 'x86_64-unknown-linux-gnu' || matrix.platform.target == 'x86_64-pc-windows-msvc' || matrix.platform.target == 'aarch64-apple-darwin'
57+
uses: actions-rs/cargo@v1
58+
with:
59+
command: test
60+
args: --all-features
61+
- name: Tests in WASM
62+
if: matrix.platform.target == 'wasm32-unknown-unknown'
63+
run: wasm-pack test --node -- --all-features
64+
65+
check_features:
66+
runs-on: "${{ matrix.platform.os }}-latest"
67+
strategy:
68+
matrix:
69+
platform: [{ os: "ubuntu" }]
70+
features: ["--features serde", "--features datasets", ""]
71+
env:
72+
TZ: "/usr/share/zoneinfo/your/location"
73+
steps:
74+
- uses: actions/checkout@v4
75+
- name: Cache .cargo and target
76+
uses: actions/cache@v4
77+
with:
78+
path: |
79+
~/.cargo
80+
./target
81+
key: ${{ runner.os }}-cargo-features-${{ hashFiles('**/Cargo.toml') }}
82+
restore-keys: ${{ runner.os }}-cargo-features-${{ hashFiles('**/Cargo.toml') }}
83+
- name: Install Rust toolchain
84+
uses: actions-rs/toolchain@v1
85+
with:
86+
toolchain: stable
87+
target: ${{ matrix.platform.target }}
88+
profile: minimal
89+
default: true
90+
- name: Stable Build
91+
uses: actions-rs/cargo@v1
92+
with:
93+
command: build
94+
args: --no-default-features ${{ matrix.features }}

.github/workflows/coverage.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [ main, development ]
6+
pull_request:
7+
branches: [ development ]
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
env:
13+
TZ: "/usr/share/zoneinfo/your/location"
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Cache .cargo
17+
uses: actions/cache@v4
18+
with:
19+
path: |
20+
~/.cargo
21+
./target
22+
key: ${{ runner.os }}-coverage-cargo-${{ hashFiles('**/Cargo.toml') }}
23+
restore-keys: ${{ runner.os }}-coverage-cargo-${{ hashFiles('**/Cargo.toml') }}
24+
- name: Install Rust toolchain
25+
uses: actions-rs/toolchain@v1
26+
with:
27+
toolchain: nightly
28+
profile: minimal
29+
default: true
30+
- name: Install cargo-tarpaulin
31+
uses: actions-rs/install@v0.1
32+
with:
33+
crate: cargo-tarpaulin
34+
version: latest
35+
use-tool-cache: true
36+
- name: Run cargo-tarpaulin
37+
uses: actions-rs/cargo@v1
38+
with:
39+
command: tarpaulin
40+
args: --out Lcov --all-features -- --test-threads 1
41+
- name: Upload to codecov.io
42+
uses: codecov/codecov-action@v2
43+
with:
44+
fail_ci_if_error: false

.github/workflows/lint.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Lint checks
2+
3+
on:
4+
push:
5+
branches: [ main, development ]
6+
pull_request:
7+
branches: [ development ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
env:
13+
TZ: "/usr/share/zoneinfo/your/location"
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Cache .cargo and target
17+
uses: actions/cache@v4
18+
with:
19+
path: |
20+
~/.cargo
21+
./target
22+
key: ${{ runner.os }}-lint-cargo-${{ hashFiles('**/Cargo.toml') }}
23+
restore-keys: ${{ runner.os }}-lint-cargo-${{ hashFiles('**/Cargo.toml') }}
24+
- name: Install Rust toolchain
25+
uses: actions-rs/toolchain@v1
26+
with:
27+
toolchain: stable
28+
profile: minimal
29+
default: true
30+
- run: rustup component add rustfmt
31+
- name: Check formt
32+
uses: actions-rs/cargo@v1
33+
with:
34+
command: fmt
35+
args: --all -- --check
36+
- run: rustup component add clippy
37+
- name: Run clippy
38+
uses: actions-rs/cargo@v1
39+
with:
40+
command: clippy
41+
args: --all-features -- -Drust-2018-idioms -Dwarnings

0 commit comments

Comments
 (0)