Skip to content

Commit 2e3b237

Browse files
committed
Apply suggestions from review
1 parent 22879c6 commit 2e3b237

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

src/integer/mat_z/arithmetic/sub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Sub<&MatQ> for &MatZ {
110110
type Output = MatQ;
111111

112112
/// Implements the [`Sub`] trait for two matrices.
113-
/// Furthermore, it is available for any combination of [`MatZ`] and [`MatQ`].
113+
/// [`Sub`] is implemented for any combination of owned and borrowed values.
114114
///
115115
/// Parameters:
116116
/// - `other`: specifies the value to subtract from `self`
@@ -136,7 +136,7 @@ impl Sub<&MatQ> for &MatZ {
136136
fn sub(self, other: &MatQ) -> Self::Output {
137137
let new_self = MatQ::from(self);
138138

139-
other.sub_safe(&new_self).unwrap()
139+
new_self.sub_safe(other).unwrap()
140140
}
141141
}
142142

src/rational/mat_q/arithmetic/add.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl Add for &MatQ {
8686
type Output = MatQ;
8787
/// Implements the [`Add`] trait for two [`MatQ`] values.
8888
/// [`Add`] is implemented for any combination of [`MatQ`] and borrowed [`MatQ`].
89-
/// Furthermore, any combination of [`MatQ`] and [`MatZ`] elements can be added.
9089
///
9190
/// Parameters:
9291
/// - `other`: specifies the value to add to `self`
@@ -95,19 +94,16 @@ impl Add for &MatQ {
9594
///
9695
/// # Examples
9796
/// ```
98-
/// use qfall_math::{rational::MatQ, integer::MatZ};
97+
/// use qfall_math::rational::MatQ;
9998
/// use std::str::FromStr;
10099
///
101100
/// let a = MatQ::from_str("[[1/2, 2/3, 3/4],[3/4, 4/5, 5/7]]").unwrap();
102101
/// let b = MatQ::from_str("[[1/4, 9/7, 3/7],[1, 0, 5]]").unwrap();
103-
/// let c = MatZ::identity(2, 3);
104102
///
105103
/// let d: MatQ = &a + &b;
106-
/// let e: MatQ = a + b;
107-
/// let f: MatQ = &d + e;
108-
/// let g: MatQ = d + &f;
109-
/// let h: MatQ = &f + &c;
110-
/// let i: MatQ = f + c;
104+
/// let e: MatQ = &a + b;
105+
/// let f: MatQ = d + &e;
106+
/// let g: MatQ = e + f;
111107
/// ```
112108
///
113109
/// # Panics ...
@@ -120,7 +116,30 @@ impl Add for &MatQ {
120116
impl Add<&MatZ> for &MatQ {
121117
type Output = MatQ;
122118

123-
/// Documentation at [`MatQ::add`].
119+
/// Implements the [`Add`] trait for two [`MatQ`] values.
120+
/// [`Add`] is implemented for any combination of [`MatQ`] and [`MatZ`].
121+
///
122+
/// Parameters:
123+
/// - `other`: specifies the value to add to `self`
124+
///
125+
/// Returns the sum of both numbers as a [`MatQ`].
126+
///
127+
/// # Examples
128+
/// ```
129+
/// use qfall_math::{rational::MatQ, integer::MatZ};
130+
/// use std::str::FromStr;
131+
///
132+
/// let a = MatQ::from_str("[[1/2, 2/3, 3/4],[3/4, 4/5, 5/7]]").unwrap();
133+
/// let b = MatZ::identity(2, 3);
134+
///
135+
/// let d: MatQ = &a + &b;
136+
/// let e: MatQ = a + &b;
137+
/// let f: MatQ = &b + d;
138+
/// let g: MatQ = b + f;
139+
/// ```
140+
///
141+
/// # Panics ...
142+
/// - if the dimensions of both matrices mismatch.
124143
fn add(self, other: &MatZ) -> Self::Output {
125144
let other = MatQ::from(other);
126145

src/rational/mat_q/arithmetic/sub.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ impl Sub for &MatQ {
2222
type Output = MatQ;
2323
/// Implements the [`Sub`] trait for two matrices.
2424
/// [`Sub`] is implemented for any combination of [`MatQ`] and borrowed [`MatQ`].
25-
/// Furthermore, it is available for any combination of [`MatZ`] and [`MatQ`].
2625
///
2726
/// Parameters:
2827
/// - `other`: specifies the value to subtract from `self`
@@ -31,19 +30,16 @@ impl Sub for &MatQ {
3130
///
3231
/// # Examples
3332
/// ```
34-
/// use qfall_math::{rational::MatQ, integer::MatZ};
33+
/// use qfall_math::rational::MatQ;
3534
/// use std::str::FromStr;
3635
///
3736
/// let a: MatQ = MatQ::from_str("[[1/2, 2/3, 3/4],[3/4, 4/5, 5/7]]").unwrap();
3837
/// let b: MatQ = MatQ::from_str("[[1/4, 9/7, 3/7],[1, 0, 5]]").unwrap();
39-
/// let c: MatZ = MatZ::identity(2, 3);
4038
///
4139
/// let d: MatQ = &a - &b;
4240
/// let e: MatQ = a - b;
4341
/// let f: MatQ = &d - e;
4442
/// let g: MatQ = d - &f;
45-
/// let h: MatQ = &f - &c;
46-
/// let i: MatQ = f - c;
4743
/// ```
4844
///
4945
/// # Panics ...
@@ -56,7 +52,30 @@ impl Sub for &MatQ {
5652
impl Sub<&MatZ> for &MatQ {
5753
type Output = MatQ;
5854

59-
/// Documentation at [`MatQ::sub`].
55+
/// Implements the [`Sub`] trait for two matrices.
56+
/// [`Sub`] is implemented for any combination of [`MatQ`] and [`MatZ`].
57+
///
58+
/// Parameters:
59+
/// - `other`: specifies the value to subtract from `self`
60+
///
61+
/// Returns the result of the subtraction as a [`MatQ`].
62+
///
63+
/// # Examples
64+
/// ```
65+
/// use qfall_math::{rational::MatQ, integer::MatZ};
66+
/// use std::str::FromStr;
67+
///
68+
/// let a: MatQ = MatQ::from_str("[[1/2, 2/3, 3/4],[3/4, 4/5, 5/7]]").unwrap();
69+
/// let b: MatZ = MatZ::identity(2, 3);
70+
///
71+
/// let d: MatQ = &a - &b;
72+
/// let e: MatQ = a - &b;
73+
/// let f: MatQ = &b - e;
74+
/// let g: MatQ = b - f;
75+
/// ```
76+
///
77+
/// # Panics ...
78+
/// - if the dimensions of both matrices mismatch.
6079
fn sub(self, other: &MatZ) -> Self::Output {
6180
let other = MatQ::from(other);
6281

0 commit comments

Comments
 (0)