Skip to content
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

Improve documentation #100

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve examples (vector)
  • Loading branch information
cpmech committed Apr 18, 2024
commit 553a76662309b9636d14869ed3202878120e8f62
21 changes: 21 additions & 0 deletions russell_lab/examples/vector_axpy_and_sum.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
use russell_lab::*;

fn main() -> Result<(), StrError> {
// axpy
let u = Vector::from(&[10.0, 20.0, 30.0]);
let mut v = Vector::from(&[10.0, 20.0, 30.0]);
vec_update(&mut v, 0.1, &u)?;
let correct = "┌ ┐\n\
│ 11 │\n\
│ 22 │\n\
│ 33 │\n\
└ ┘";
assert_eq!(format!("{}", v), correct);

// sum
let w = Vector::filled(3, 1.0);
let mut z = Vector::new(3);
vec_add(&mut z, 1.0, &v, 100.0, &w)?;
let correct = "┌ ┐\n\
│ 111 │\n\
│ 122 │\n\
│ 133 │\n\
└ ┘";
assert_eq!(format!("{}", z), correct);
Ok(())
}
14 changes: 14 additions & 0 deletions russell_lab/examples/vector_dot_scale_and_copy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
use russell_lab::*;

fn main() -> Result<(), StrError> {
// scale
let mut u = Vector::from(&[1.0, 2.0, 3.0]);
vec_scale(&mut u, 0.5);
let correct = "┌ ┐\n\
│ 0.5 │\n\
│ 1 │\n\
│ 1.5 │\n\
└ ┘";
assert_eq!(format!("{}", u), correct);

// copy
let mut v = Vector::from(&[-1.0, -2.0, -3.0]);
vec_copy(&mut v, &u)?;
assert_eq!(format!("{}", v), correct);
Ok(())
}
6 changes: 6 additions & 0 deletions russell_lab/examples/vector_norms.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use russell_lab::*;

fn main() -> Result<(), StrError> {
let u = Vector::from(&[2.0, -2.0, 2.0, -2.0, -3.0]);
assert_eq!(vec_norm(&u, Norm::One), 11.0);
assert_eq!(vec_norm(&u, Norm::Euc), 5.0);
assert_eq!(vec_norm(&u, Norm::Fro), 5.0); // same as Euc
assert_eq!(vec_norm(&u, Norm::Inf), 3.0);
assert_eq!(vec_norm(&u, Norm::Max), 3.0); // same as Inf
Ok(())
}