Skip to content

Commit 3de2b33

Browse files
committed
Make solve_scaled_odgp_with_parity return iterator
I changed the name to this: solve_scaled_odgp_with_parity_k_ne_0 Because the zero branch returned the wrong type. But it is never called with k=0.
1 parent 1a5d43a commit 3de2b33

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/odgp.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ pub fn solve_odgp_with_parity(
133133
.map(move |alpha| (alpha * ZRootTwo::new(IBig::ZERO, IBig::ONE)) + &p)
134134
}
135135

136-
137136
pub fn solve_scaled_odgp(i: Interval, j: Interval, k: i64) -> impl Iterator<Item = DRootTwo> {
138137
let scale = pow_sqrt2(k);
139138
let neg_scale = -scale.clone();
@@ -142,22 +141,22 @@ pub fn solve_scaled_odgp(i: Interval, j: Interval, k: i64) -> impl Iterator<Item
142141
} else {
143142
j.scale(&neg_scale)
144143
};
145-
solve_odgp(i.scale(&scale), scaled_j)
146-
.map(move |alpha| DRootTwo::new(alpha, k))
144+
solve_odgp(i.scale(&scale), scaled_j).map(move |alpha| DRootTwo::new(alpha, k))
147145
}
148146

149-
pub fn solve_scaled_odgp_with_parity(
147+
pub fn solve_scaled_odgp_with_parity_k_ne_0(
150148
i: Interval,
151149
j: Interval,
152150
k: i64,
153151
beta: &DRootTwo,
154-
) -> Vec<DRootTwo> {
155-
if k == 0 {
156-
let base = beta.renew_denomexp(0);
157-
return solve_odgp_with_parity(i, j, &base)
158-
.map(DRootTwo::from_zroottwo)
159-
.collect();
160-
}
152+
) -> impl Iterator<Item = DRootTwo> {
153+
// Can't do this because the iterators are not of the same type.
154+
// But this function is only called with k == 1. So we don't need the k == 0 branch.
155+
// if k == 0 {
156+
// let base = beta.renew_denomexp(0);
157+
// return solve_odgp_with_parity(i, j, &base)
158+
// .map(DRootTwo::from_zroottwo);
159+
// }
161160

162161
let p = beta.renew_denomexp(k).parity();
163162
let offset = if p == IBig::ZERO {
@@ -169,7 +168,7 @@ pub fn solve_scaled_odgp_with_parity(
169168
let sub_i = i - offset.to_real();
170169
let sub_j = j - offset.conj_sq2().to_real();
171170
let sol = solve_scaled_odgp(sub_i, sub_j, k - 1);
172-
sol.into_iter().map(|a| a + offset.clone()).collect()
171+
sol.map(move |a| a + offset.clone())
173172
}
174173

175174
#[cfg(test)]

src/tdgp.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dashu_int::IBig;
77

88
use crate::common::{fb_with_prec, ib_to_bf_prec};
99
use crate::grid_op::GridOp;
10-
use crate::odgp::{solve_scaled_odgp, solve_scaled_odgp_with_parity};
10+
use crate::odgp::{solve_scaled_odgp, solve_scaled_odgp_with_parity_k_ne_0};
1111
use crate::region::{Ellipse, Interval, Rectangle};
1212
use crate::ring::{DOmega, DRootTwo};
1313

@@ -42,7 +42,7 @@ pub fn solve_tdgp(
4242

4343
let alpha0 = match sol_x.next() {
4444
Some(val) => val,
45-
None => return vec![]
45+
None => return vec![],
4646
};
4747

4848
let droot_zero = DRootTwo::from_int(IBig::ZERO);
@@ -99,10 +99,8 @@ pub fn solve_tdgp(
9999
int_a = int_a.fatten(&dt_a);
100100
int_b = int_b.fatten(&dt_b);
101101

102-
let sol_t = solve_scaled_odgp_with_parity(int_a, int_b, 1, &parity);
103-
let sol_x = sol_t
104-
.into_iter()
105-
.map(|alpha| alpha * dx.clone() + alpha0.clone());
102+
let sol_t = solve_scaled_odgp_with_parity_k_ne_0(int_a, int_b, 1, &parity);
103+
let sol_x = sol_t.map(|alpha| alpha * dx.clone() + alpha0.clone());
106104
for alpha in sol_x {
107105
sol_sufficient.push(DOmega::from_droottwo_vector(&alpha, &beta, k));
108106
}

0 commit comments

Comments
 (0)