Merge branch 'main' into update_frame_init

This commit is contained in:
Palash Tyagi 2025-05-01 01:09:21 +01:00
commit 3c8b69d3ab
3 changed files with 34 additions and 26 deletions

View File

@ -86,6 +86,8 @@ jobs:
cp tarpaulin-report.json target/doc/rustframe/ cp tarpaulin-report.json target/doc/rustframe/
cp tarpaulin-badge.json target/doc/rustframe/ cp tarpaulin-badge.json target/doc/rustframe/
cp last-commit-date.json target/doc/rustframe/ cp last-commit-date.json target/doc/rustframe/
mkdir -p target/doc/rustframe/.github
cp .github/rustframe_logo.png target/doc/rustframe/.github/
echo "<meta http-equiv=\"refresh\" content=\"0; url=rustframe\">" > target/doc/index.html echo "<meta http-equiv=\"refresh\" content=\"0; url=rustframe\">" > target/doc/index.html
- name: Upload Pages artifact - name: Upload Pages artifact

View File

@ -7,6 +7,7 @@ on:
jobs: jobs:
run-unit-tests: run-unit-tests:
if: github.event.pull_request.draft == false
name: run-unit-tests name: run-unit-tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:

View File

@ -1,4 +1,7 @@
# rustframe
# <img align="center" alt="Rustframe" src=".github/rustframe_logo.png" height="50" /> rustframe
<!-- though the centre tag doesn't work as it would noramlly, it achieves the desired effect -->
📚 [Docs](https://magnus167.github.io/rustframe/) | 🐙 [GitHub](https://github.com/Magnus167/rustframe) | 🌐 [Gitea mirror](https://gitea.nulltech.uk/Magnus167/rustframe) | 🦀 [Crates.io](https://crates.io/crates/rustframe) | 🔖 [docs.rs](https://docs.rs/rustframe/latest/rustframe/) 📚 [Docs](https://magnus167.github.io/rustframe/) | 🐙 [GitHub](https://github.com/Magnus167/rustframe) | 🌐 [Gitea mirror](https://gitea.nulltech.uk/Magnus167/rustframe) | 🦀 [Crates.io](https://crates.io/crates/rustframe) | 🔖 [docs.rs](https://docs.rs/rustframe/latest/rustframe/)
@ -53,35 +56,37 @@ let dates: Vec<NaiveDate> =
.list() .list()
.unwrap(); .unwrap();
let col_names: Vec<String> = vec!["a".to_string(), "b".to_string()]; let col_names: Vec<String> = vec!["a".to_string(), "b".to_string()];
let ma: Matrix<f64> = Matrix::from_cols(vec![vec![1.0, 2.0, 3.0, 4.0], vec![5.0, 6.0, 7.0, 8.0]]); let ma: Matrix<f64> =
let mb: Matrix<f64> = Matrix::from_cols(vec![vec![4.0, 3.0, 2.0, 1.0], vec![8.0, 7.0, 6.0, 5.0]]); Matrix::from_cols(vec![vec![1.0, 2.0, 3.0, 4.0], vec![5.0, 6.0, 7.0, 8.0]]);
let mb: Matrix<f64> =
Matrix::from_cols(vec![vec![4.0, 3.0, 2.0, 1.0], vec![8.0, 7.0, 6.0, 5.0]]);
let fa: Frame<f64> = Frame::new( let fa: Frame<f64> = Frame::new(
ma.clone(), ma.clone(),
col_names.clone(), col_names.clone(),
Some(RowIndex::Date(dates.clone())), Some(RowIndex::Date(dates.clone())),
); );
let fb: Frame<f64> = Frame::new(mb, col_names, Some(RowIndex::Date(dates))); let fb: Frame<f64> = Frame::new(mb, col_names, Some(RowIndex::Date(dates)));
// Math that reads like math // Math that reads like math
let result: Frame<f64> = &fa * &fb; // elementwise multiply let result: Frame<f64> = &fa * &fb; // elementwise multiply
let total: f64 = result.sum_vertical().iter().sum::<f64>(); let total: f64 = result.sum_vertical().iter().sum::<f64>();
assert_eq!(total, 184.0); assert_eq!(total, 184.0);
// broadcast & reduce // broadcast & reduce
let result: Matrix<f64> = &ma + 1.0; // add scalar let result: Matrix<f64> = &ma + 1.0; // add scalar
let result: Matrix<f64> = &result - 1.0; // subtract scalar let result: Matrix<f64> = &result - 1.0; // subtract scalar
let result: Matrix<f64> = &result * 2.0; // multiply by scalar let result: Matrix<f64> = &result * 2.0; // multiply by scalar
let result: Matrix<f64> = &result / 2.0; // divide by scalar let result: Matrix<f64> = &result / 2.0; // divide by scalar
let check: bool = result.eq_elementwise(ma.clone()).all(); let check: bool = result.eq_elementwise(ma.clone()).all();
assert!(check); assert!(check);
// The above math can also be written as: // The above math can also be written as:
let check: bool = (&(&(&(&ma + 1.0) - 1.0) * 2.0) / 2.0) let check: bool = (&(&(&(&ma + 1.0) - 1.0) * 2.0) / 2.0)
.eq_elementwise(ma) .eq_elementwise(ma)
.all(); .all();
assert!(check); assert!(check);
``` ```