forked from M-Labs/nalgebra
Fix nalgebra-lapack.
This commit is contained in:
parent
eedb860565
commit
38ac9a2f9a
@ -22,7 +22,7 @@ proptest-support = [ "nalgebra/proptest-support" ]
|
|||||||
arbitrary = [ "nalgebra/arbitrary" ]
|
arbitrary = [ "nalgebra/arbitrary" ]
|
||||||
|
|
||||||
# For BLAS/LAPACK
|
# For BLAS/LAPACK
|
||||||
default = ["netlib"]
|
default = ["intel-mkl"]
|
||||||
openblas = ["lapack-src/openblas"]
|
openblas = ["lapack-src/openblas"]
|
||||||
netlib = ["lapack-src/netlib"]
|
netlib = ["lapack-src/netlib"]
|
||||||
accelerate = ["lapack-src/accelerate"]
|
accelerate = ["lapack-src/accelerate"]
|
||||||
|
@ -77,9 +77,10 @@ where
|
|||||||
|
|
||||||
let lda = n as i32;
|
let lda = n as i32;
|
||||||
|
|
||||||
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
// TODO: avoid the initialization?
|
||||||
|
let mut wr = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
// TODO: Tap into the workspace.
|
// TODO: Tap into the workspace.
|
||||||
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
let mut wi = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
|
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
let mut placeholder1 = [T::zero()];
|
let mut placeholder1 = [T::zero()];
|
||||||
@ -102,14 +103,13 @@ where
|
|||||||
|
|
||||||
lapack_check!(info);
|
lapack_check!(info);
|
||||||
|
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
match (left_eigenvectors, eigenvectors) {
|
match (left_eigenvectors, eigenvectors) {
|
||||||
(true, true) => {
|
(true, true) => {
|
||||||
let mut vl =
|
// TODO: avoid the initializations?
|
||||||
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
|
let mut vl = Matrix::zeros_generic(nrows, ncols);
|
||||||
let mut vr =
|
let mut vr = Matrix::zeros_generic(nrows, ncols);
|
||||||
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
|
|
||||||
|
|
||||||
T::xgeev(
|
T::xgeev(
|
||||||
ljob,
|
ljob,
|
||||||
@ -138,8 +138,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
let mut vl =
|
// TODO: avoid the initialization?
|
||||||
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
|
let mut vl = Matrix::zeros_generic(nrows, ncols);
|
||||||
|
|
||||||
T::xgeev(
|
T::xgeev(
|
||||||
ljob,
|
ljob,
|
||||||
@ -168,8 +168,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(false, true) => {
|
(false, true) => {
|
||||||
let mut vr =
|
// TODO: avoid the initialization?
|
||||||
unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
|
let mut vr = Matrix::zeros_generic(nrows, ncols);
|
||||||
|
|
||||||
T::xgeev(
|
T::xgeev(
|
||||||
ljob,
|
ljob,
|
||||||
@ -246,8 +246,9 @@ where
|
|||||||
|
|
||||||
let lda = n as i32;
|
let lda = n as i32;
|
||||||
|
|
||||||
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
// TODO: avoid the initialization?
|
||||||
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
let mut wr = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
|
let mut wi = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
|
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
let mut placeholder1 = [T::zero()];
|
let mut placeholder1 = [T::zero()];
|
||||||
@ -270,7 +271,7 @@ where
|
|||||||
|
|
||||||
lapack_panic!(info);
|
lapack_panic!(info);
|
||||||
|
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
T::xgeev(
|
T::xgeev(
|
||||||
b'T',
|
b'T',
|
||||||
@ -290,7 +291,7 @@ where
|
|||||||
);
|
);
|
||||||
lapack_panic!(info);
|
lapack_panic!(info);
|
||||||
|
|
||||||
let mut res = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
let mut res = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
|
|
||||||
for i in 0..res.len() {
|
for i in 0..res.len() {
|
||||||
res[i] = Complex::new(wr[i], wi[i]);
|
res[i] = Complex::new(wr[i], wi[i]);
|
||||||
|
@ -59,14 +59,12 @@ where
|
|||||||
"Unable to compute the hessenberg decomposition of an empty matrix."
|
"Unable to compute the hessenberg decomposition of an empty matrix."
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut tau = unsafe {
|
let mut tau = Matrix::zeros_generic(nrows.sub(Const::<1>), Const::<1>);
|
||||||
Matrix::new_uninitialized_generic(nrows.sub(Const::<1>), Const::<1>).assume_init()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
let lwork =
|
let lwork =
|
||||||
T::xgehrd_work_size(n, 1, n, m.as_mut_slice(), n, tau.as_mut_slice(), &mut info);
|
T::xgehrd_work_size(n, 1, n, m.as_mut_slice(), n, tau.as_mut_slice(), &mut info);
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
lapack_panic!(info);
|
lapack_panic!(info);
|
||||||
|
|
||||||
|
@ -139,10 +139,3 @@ impl ComplexHelper for Complex<f64> {
|
|||||||
self.re
|
self.re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn uninitialized_vec<T: Copy>(n: usize) -> Vec<T> {
|
|
||||||
let mut res = Vec::new();
|
|
||||||
res.reserve_exact(n);
|
|
||||||
res.set_len(n);
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
@ -290,7 +290,7 @@ where
|
|||||||
);
|
);
|
||||||
lapack_check!(info);
|
lapack_check!(info);
|
||||||
|
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
T::xgetri(
|
T::xgetri(
|
||||||
dim,
|
dim,
|
||||||
|
@ -56,9 +56,7 @@ where
|
|||||||
let (nrows, ncols) = m.shape_generic();
|
let (nrows, ncols) = m.shape_generic();
|
||||||
|
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
let mut tau = unsafe {
|
let mut tau = Matrix::zeros_generic(nrows.min(ncols), Const::<1>);
|
||||||
Matrix::new_uninitialized_generic(nrows.min(ncols), Const::<1>).assume_init()
|
|
||||||
};
|
|
||||||
|
|
||||||
if nrows.value() == 0 || ncols.value() == 0 {
|
if nrows.value() == 0 || ncols.value() == 0 {
|
||||||
return Self { qr: m, tau };
|
return Self { qr: m, tau };
|
||||||
@ -73,7 +71,7 @@ where
|
|||||||
&mut info,
|
&mut info,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
T::xgeqrf(
|
T::xgeqrf(
|
||||||
nrows.value() as i32,
|
nrows.value() as i32,
|
||||||
|
@ -77,9 +77,9 @@ where
|
|||||||
|
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
|
|
||||||
let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
let mut wr = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
let mut wi = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
let mut q = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() };
|
let mut q = Matrix::zeros_generic(nrows, ncols);
|
||||||
// Placeholders:
|
// Placeholders:
|
||||||
let mut bwork = [0i32];
|
let mut bwork = [0i32];
|
||||||
let mut unused = 0;
|
let mut unused = 0;
|
||||||
@ -100,7 +100,7 @@ where
|
|||||||
);
|
);
|
||||||
lapack_check!(info);
|
lapack_check!(info);
|
||||||
|
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
T::xgees(
|
T::xgees(
|
||||||
b'V',
|
b'V',
|
||||||
@ -152,9 +152,7 @@ where
|
|||||||
where
|
where
|
||||||
DefaultAllocator: Allocator<Complex<T>, D>,
|
DefaultAllocator: Allocator<Complex<T>, D>,
|
||||||
{
|
{
|
||||||
let mut out = unsafe {
|
let mut out = Matrix::zeros_generic(self.t.shape_generic().0, Const::<1>);
|
||||||
OVector::new_uninitialized_generic(self.t.shape_generic().0, Const::<1>).assume_init()
|
|
||||||
};
|
|
||||||
|
|
||||||
for i in 0..out.len() {
|
for i in 0..out.len() {
|
||||||
out[i] = Complex::new(self.re[i], self.im[i])
|
out[i] = Complex::new(self.re[i], self.im[i])
|
||||||
|
@ -98,9 +98,9 @@ macro_rules! svd_impl(
|
|||||||
|
|
||||||
let lda = nrows.value() as i32;
|
let lda = nrows.value() as i32;
|
||||||
|
|
||||||
let mut u = unsafe { Matrix::new_uninitialized_generic(nrows, nrows).assume_init() };
|
let mut u = Matrix::zeros_generic(nrows, nrows);
|
||||||
let mut s = unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), Const::<1>).assume_init() };
|
let mut s = Matrix::zeros_generic(nrows.min(ncols), Const::<1>);
|
||||||
let mut vt = unsafe { Matrix::new_uninitialized_generic(ncols, ncols).assume_init() };
|
let mut vt = Matrix::zeros_generic(ncols, ncols);
|
||||||
|
|
||||||
let ldu = nrows.value();
|
let ldu = nrows.value();
|
||||||
let ldvt = ncols.value();
|
let ldvt = ncols.value();
|
||||||
@ -108,7 +108,7 @@ macro_rules! svd_impl(
|
|||||||
let mut work = [ 0.0 ];
|
let mut work = [ 0.0 ];
|
||||||
let mut lwork = -1 as i32;
|
let mut lwork = -1 as i32;
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
let mut iwork = unsafe { crate::uninitialized_vec(8 * cmp::min(nrows.value(), ncols.value())) };
|
let mut iwork = vec![0; 8 * cmp::min(nrows.value(), ncols.value())];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
$lapack_func(job, nrows.value() as i32, ncols.value() as i32, m.as_mut_slice(),
|
$lapack_func(job, nrows.value() as i32, ncols.value() as i32, m.as_mut_slice(),
|
||||||
@ -118,7 +118,7 @@ macro_rules! svd_impl(
|
|||||||
lapack_check!(info);
|
lapack_check!(info);
|
||||||
|
|
||||||
lwork = work[0] as i32;
|
lwork = work[0] as i32;
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![0.0; lwork as usize];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
$lapack_func(job, nrows.value() as i32, ncols.value() as i32, m.as_mut_slice(),
|
$lapack_func(job, nrows.value() as i32, ncols.value() as i32, m.as_mut_slice(),
|
||||||
@ -253,9 +253,9 @@ macro_rules! svd_complex_impl(
|
|||||||
let min_nrows_ncols = nrows.min(ncols);
|
let min_nrows_ncols = nrows.min(ncols);
|
||||||
|
|
||||||
|
|
||||||
let mut u = unsafe { Matrix::new_uninitialized_generic(nrows, nrows) };
|
let mut u = Matrix::zeros_generic(nrows, nrows);
|
||||||
let mut s = unsafe { Matrix::new_uninitialized_generic(min_nrows_ncols, U1) };
|
let mut s = Matrix::zeros_generic(min_nrows_ncols, U1);
|
||||||
let mut vt = unsafe { Matrix::new_uninitialized_generic(ncols, ncols) };
|
let mut vt = Matrix::zeros_generic(ncols, ncols);
|
||||||
|
|
||||||
let ldu = nrows.value();
|
let ldu = nrows.value();
|
||||||
let ldvt = ncols.value();
|
let ldvt = ncols.value();
|
||||||
|
@ -93,14 +93,13 @@ where
|
|||||||
|
|
||||||
let lda = n as i32;
|
let lda = n as i32;
|
||||||
|
|
||||||
let mut values =
|
let mut values = Matrix::zeros_generic(nrows, Const::<1>);
|
||||||
unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() };
|
|
||||||
let mut info = 0;
|
let mut info = 0;
|
||||||
|
|
||||||
let lwork = T::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info);
|
let lwork = T::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info);
|
||||||
lapack_check!(info);
|
lapack_check!(info);
|
||||||
|
|
||||||
let mut work = unsafe { crate::uninitialized_vec(lwork as usize) };
|
let mut work = vec![T::zero(); lwork as usize];
|
||||||
|
|
||||||
T::xsyev(
|
T::xsyev(
|
||||||
jobz,
|
jobz,
|
||||||
|
Loading…
Reference in New Issue
Block a user