Skip to content

Commit 45c7170

Browse files
committed
Query liwork
1 parent d7cf503 commit 45c7170

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

lax/src/least_squares.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,6 @@ pub trait LeastSquaresSvdDivideConquer_: Scalar {
2828
) -> Result<LeastSquaresOutput<Self>>;
2929
}
3030

31-
/// Eval iwork size
32-
///
33-
/// - NLVL = INT( LOG_2( MIN( M, N ) / ( SMLSIZ + 1 ) ) ) + 1
34-
/// - LIWORK = 3 * MIN( M, N ) * NLVL + 11 * MIN( M, N )
35-
///
36-
/// where SMLSIZ is returned by ILAENV and is equal to the maximum size of the subproblems
37-
/// at the bottom of the computation tree (usually about 25).
38-
///
39-
/// We put SMLSIZ=0 to estimate NLVL as large as possible
40-
/// because its size will usually very small.
41-
fn iwork_size(m: i32, n: i32) -> usize {
42-
let mn = m.min(n) as usize;
43-
let nlvl = (mn.to_f32().unwrap().log2() + 1.0)
44-
.max(0.0)
45-
.to_usize()
46-
.unwrap();
47-
(3 * mn * nlvl + 11 * mn).max(1)
48-
}
49-
5031
macro_rules! impl_least_squares_real {
5132
($scalar:ty, $gelsd:path) => {
5233
impl LeastSquaresSvdDivideConquer_ for $scalar {
@@ -65,11 +46,10 @@ macro_rules! impl_least_squares_real {
6546
let mut singular_values: Vec<Self::Real> = vec![Self::Real::zero(); k as usize];
6647
let mut rank: i32 = 0;
6748

68-
let mut iwork = vec![0; iwork_size(m, n)];
69-
7049
// eval work size
7150
let mut info = 0;
7251
let mut work_size = [Self::zero()];
52+
let mut iwork_size = [0];
7353
$gelsd(
7454
m,
7555
n,
@@ -83,14 +63,16 @@ macro_rules! impl_least_squares_real {
8363
&mut rank,
8464
&mut work_size,
8565
-1,
86-
&mut iwork,
66+
&mut iwork_size,
8767
&mut info,
8868
);
8969
info.as_lapack_result()?;
9070

9171
// calc
9272
let lwork = work_size[0].to_usize().unwrap();
9373
let mut work = vec![Self::zero(); lwork];
74+
let liwork = iwork_size[0].to_usize().unwrap();
75+
let mut iwork = vec![0; liwork];
9476
$gelsd(
9577
m,
9678
n,
@@ -135,11 +117,10 @@ macro_rules! impl_least_squares_real {
135117
let mut singular_values: Vec<Self::Real> = vec![Self::Real::zero(); k as usize];
136118
let mut rank: i32 = 0;
137119

138-
let mut iwork = vec![0; iwork_size(m, n)];
139-
140120
// eval work size
141121
let mut info = 0;
142122
let mut work_size = [Self::zero()];
123+
let mut iwork_size = [0];
143124
$gelsd(
144125
m,
145126
n,
@@ -153,14 +134,16 @@ macro_rules! impl_least_squares_real {
153134
&mut rank,
154135
&mut work_size,
155136
-1,
156-
&mut iwork,
137+
&mut iwork_size,
157138
&mut info,
158139
);
159140
info.as_lapack_result()?;
160141

161142
// calc
162143
let lwork = work_size[0].to_usize().unwrap();
163144
let mut work = vec![Self::zero(); lwork];
145+
let liwork = iwork_size[0].to_usize().unwrap();
146+
let mut iwork = vec![0; liwork];
164147
$gelsd(
165148
m,
166149
n,

0 commit comments

Comments
 (0)