From 1dbe5d0efe544b063ff2261788dd054c04970f6c Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 3 May 2025 01:19:01 +0100 Subject: [PATCH] Update matrix arithmetic operations --- README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3a990ae..931b463 100644 --- a/README.md +++ b/README.md @@ -76,17 +76,26 @@ let total: f64 = result.sum_vertical().iter().sum::(); assert_eq!(total, 184.0); // broadcast & reduce -let result: Matrix = &ma + 1.0; // add scalar -let result: Matrix = &result - 1.0; // subtract scalar -let result: Matrix = &result * 2.0; // multiply by scalar -let result: Matrix = &result / 2.0; // divide by scalar +let result: Matrix = ma.clone() + 1.0; // add scalar +let result: Matrix = result + &ma - &ma; // add matrix +let result: Matrix = result - 1.0; // subtract scalar +let result: Matrix = result * 2.0; // multiply by scalar +let result: Matrix = result / 2.0; // divide by scalar -let check: bool = result.eq_elementwise(ma.clone()).all(); +let check: bool = result.eq_elem(ma.clone()).all(); assert!(check); // The above math can also be written as: let check: bool = (&(&(&(&ma + 1.0) - 1.0) * 2.0) / 2.0) - .eq_elementwise(ma) + .eq_elem(ma.clone()) .all(); assert!(check); + +// The above math can also be written as: +let check: bool = ((((ma.clone() + 1.0) - 1.0) * 2.0) / 2.0) + .eq_elem(ma) + .all(); +assert!(check); + + ```